Skip to content

Repository files navigation

Bedrock

English | 简体中文

Swift SPM Platform License

Bedrock is a small collection of common Swift data structures and lightweight data models. It is written as project-level foundation code: simple enough to read, copy, adapt, and test.

The package is available through SwiftPM, but importing the whole package is not the main point. If one type is useful, feel free to copy that single source file into your project and adjust it for your own needs. If Bedrock saves you time, a star is appreciated.

Some implementations are shaped by benchmark experiments in Benchmarks/. Those benchmarks are design notes and sanity checks, not a performance framework.

Supported Types

Collections

Type Source Summary
OrderedDictionary OrderedDictionary.swift A hash-backed dictionary that keeps key/value pairs in insertion order.
OrderedSet OrderedSet.swift A hash-backed set that keeps members in insertion order.
Stack Stack.swift A small last-in, first-out collection.
Queue Queue.swift A first-in, first-out collection backed by two arrays.
Deque Deque.swift A double-ended queue backed by circular storage.
RingBuffer RingBuffer.swift A fixed-capacity FIFO buffer that overwrites old values when full.

Caches

Type Source Summary
LRUCache LRUCache.swift A fixed-capacity least-recently-used cache.

Examples

var dictionary: OrderedDictionary<String, Int> = [
    "one": 1,
    "two": 2
]

dictionary.updateValue(3, forKey: "three")
dictionary[key: "two"] = 20

print(dictionary.keys)      // ["one", "two", "three"]
print(dictionary[0].key)    // "one"
var cache = LRUCache<String, Int>(capacity: 2)
cache.updateValue(1, forKey: "a")
cache.updateValue(2, forKey: "b")
cache.value(forKey: "a")
cache.updateValue(3, forKey: "c")

print(cache.keys)           // ["a", "c"]

Notes

Benchmarks

License

Bedrock is available under the license in LICENSE.

About

Bedrock is a collection of foundational building blocks for Swift, including data structures, caching primitives, concurrency utilities, and infrastructure components.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages