English | 简体中文
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.
| 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. |
| Type | Source | Summary |
|---|---|---|
LRUCache |
LRUCache.swift | A fixed-capacity least-recently-used cache. |
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"]Bedrock is available under the license in LICENSE.