[PersistentCollections] Rename to SharableHashedCollections

`PersistentSet` → `ShareableSet`
`PersistentDictionary` → `ShareableDictionary`
`PersistentCollections` → `ShareableHashedCollections`
This commit is contained in:
Karoy Lorentey committed 2022-11-07 18:10:16 -08:00
1 parent 1098c52654
commit e8fc3ee4cd
120 files changed
+1065 -1064

No files matched your search

@@ -1,42 +1,42 @@
{
"kind": "group",
"title": "PersistentDictionary Benchmarks",
"title": "ShareableDictionary Benchmarks",
"directory": "Results",
"contents": [
{
"kind": "group",
"title": "PersistentDictionary Operations",
"title": "ShareableDictionary Operations",
"contents": [
{
"kind": "chart",
"title": "all",
"tasks": [
"PersistentDictionary<Int, Int> init(uniqueKeysWithValues:)",
"PersistentDictionary<Int, Int> sequential iteration",
"PersistentDictionary<Int, Int> sequential iteration, indices",
"PersistentDictionary<Int, Int>.Keys sequential iteration",
"PersistentDictionary<Int, Int>.Values sequential iteration",
"PersistentDictionary<Int, Int> indexing subscript",
"PersistentDictionary<Int, Int> subscript, successful lookups",
"PersistentDictionary<Int, Int> subscript, unsuccessful lookups",
"PersistentDictionary<Int, Int> subscript, noop setter",
"PersistentDictionary<Int, Int> subscript, set existing",
"PersistentDictionary<Int, Int> subscript, _modify",
"PersistentDictionary<Int, Int> subscript, insert, unique",
"PersistentDictionary<Int, Int> subscript, insert, shared",
"PersistentDictionary<Int, Int> subscript, remove existing, unique",
"PersistentDictionary<Int, Int> subscript, remove existing, shared",
"PersistentDictionary<Int, Int> subscript, remove missing",
"PersistentDictionary<Int, Int> defaulted subscript, successful lookups",
"PersistentDictionary<Int, Int> defaulted subscript, unsuccessful lookups",
"PersistentDictionary<Int, Int> defaulted subscript, _modify existing",
"PersistentDictionary<Int, Int> defaulted subscript, _modify missing",
"PersistentDictionary<Int, Int> successful index(forKey:)",
"PersistentDictionary<Int, Int> unsuccessful index(forKey:)",
"PersistentDictionary<Int, Int> updateValue(_:forKey:), existing",
"PersistentDictionary<Int, Int> updateValue(_:forKey:), insert",
"PersistentDictionary<Int, Int> random removals (existing keys)",
"PersistentDictionary<Int, Int> random removals (missing keys)",
"ShareableDictionary<Int, Int> init(uniqueKeysWithValues:)",
"ShareableDictionary<Int, Int> sequential iteration",
"ShareableDictionary<Int, Int> sequential iteration, indices",
"ShareableDictionary<Int, Int>.Keys sequential iteration",
"ShareableDictionary<Int, Int>.Values sequential iteration",
"ShareableDictionary<Int, Int> indexing subscript",
"ShareableDictionary<Int, Int> subscript, successful lookups",
"ShareableDictionary<Int, Int> subscript, unsuccessful lookups",
"ShareableDictionary<Int, Int> subscript, noop setter",
"ShareableDictionary<Int, Int> subscript, set existing",
"ShareableDictionary<Int, Int> subscript, _modify",
"ShareableDictionary<Int, Int> subscript, insert, unique",
"ShareableDictionary<Int, Int> subscript, insert, shared",
"ShareableDictionary<Int, Int> subscript, remove existing, unique",
"ShareableDictionary<Int, Int> subscript, remove existing, shared",
"ShareableDictionary<Int, Int> subscript, remove missing",
"ShareableDictionary<Int, Int> defaulted subscript, successful lookups",
"ShareableDictionary<Int, Int> defaulted subscript, unsuccessful lookups",
"ShareableDictionary<Int, Int> defaulted subscript, _modify existing",
"ShareableDictionary<Int, Int> defaulted subscript, _modify missing",
"ShareableDictionary<Int, Int> successful index(forKey:)",
"ShareableDictionary<Int, Int> unsuccessful index(forKey:)",
"ShareableDictionary<Int, Int> updateValue(_:forKey:), existing",
"ShareableDictionary<Int, Int> updateValue(_:forKey:), insert",
"ShareableDictionary<Int, Int> random removals (existing keys)",
"ShareableDictionary<Int, Int> random removals (missing keys)",
]
}
]
@@ -50,7 +50,7 @@
"kind": "chart",
"title": "init(uniqueKeysWithValues:)",
"tasks": [
"PersistentDictionary<Int, Int> init(uniqueKeysWithValues:)",
"ShareableDictionary<Int, Int> init(uniqueKeysWithValues:)",
"Dictionary<Int, Int> init(uniqueKeysWithValues:)",
"OrderedDictionary<Int, Int> init(uniqueKeysWithValues:)",
]
@@ -59,7 +59,7 @@
"kind": "chart",
"title": "sequential iteration",
"tasks": [
"PersistentDictionary<Int, Int> sequential iteration",
"ShareableDictionary<Int, Int> sequential iteration",
"Dictionary<Int, Int> sequential iteration",
"OrderedDictionary<Int, Int> sequential iteration",
]
@@ -68,7 +68,7 @@
"kind": "chart",
"title": "sequential iteration [Keys]",
"tasks": [
"PersistentDictionary<Int, Int>.Keys sequential iteration",
"ShareableDictionary<Int, Int>.Keys sequential iteration",
"Dictionary<Int, Int>.Keys sequential iteration",
"OrderedDictionary<Int, Int>.Keys sequential iteration",
]
@@ -77,7 +77,7 @@
"kind": "chart",
"title": "sequential iteration [Values]",
"tasks": [
"PersistentDictionary<Int, Int>.Values sequential iteration",
"ShareableDictionary<Int, Int>.Values sequential iteration",
"Dictionary<Int, Int>.Values sequential iteration",
"OrderedDictionary<Int, Int>.Values sequential iteration",
]
@@ -86,7 +86,7 @@
"kind": "chart",
"title": "sequential iteration using indices",
"tasks": [
"PersistentDictionary<Int, Int> sequential iteration, indices",
"ShareableDictionary<Int, Int> sequential iteration, indices",
"Dictionary<Int, Int> sequential iteration, indices",
"OrderedDictionary<Int, Int> sequential iteration, indices",
]
@@ -95,7 +95,7 @@
"kind": "chart",
"title": "indexing subscript",
"tasks": [
"PersistentDictionary<Int, Int> indexing subscript",
"ShareableDictionary<Int, Int> indexing subscript",
"Dictionary<Int, Int> indexing subscript",
"OrderedDictionary<Int, Int> indexing subscript",
]
@@ -104,7 +104,7 @@
"kind": "chart",
"title": "subscript, successful lookups",
"tasks": [
"PersistentDictionary<Int, Int> subscript, successful lookups",
"ShareableDictionary<Int, Int> subscript, successful lookups",
"Dictionary<Int, Int> subscript, successful lookups",
"OrderedDictionary<Int, Int> subscript, successful lookups",
]
@@ -113,7 +113,7 @@
"kind": "chart",
"title": "subscript, unsuccessful lookups",
"tasks": [
"PersistentDictionary<Int, Int> subscript, unsuccessful lookups",
"ShareableDictionary<Int, Int> subscript, unsuccessful lookups",
"Dictionary<Int, Int> subscript, unsuccessful lookups",
"OrderedDictionary<Int, Int> subscript, unsuccessful lookups",
]
@@ -122,7 +122,7 @@
"kind": "chart",
"title": "subscript, insert into unique collection",
"tasks": [
"PersistentDictionary<Int, Int> subscript, insert, unique",
"ShareableDictionary<Int, Int> subscript, insert, unique",
"Dictionary<Int, Int> subscript, insert, unique",
"Dictionary<Int, Int> subscript, insert, reserving capacity",
"OrderedDictionary<Int, Int> subscript, append, unique",
@@ -133,7 +133,7 @@
"kind": "chart",
"title": "subscript, insert into shared collection",
"tasks": [
"PersistentDictionary<Int, Int> subscript, insert, shared",
"ShareableDictionary<Int, Int> subscript, insert, shared",
"Dictionary<Int, Int> subscript, insert, shared",
"OrderedDictionary<Int, Int> subscript, append, shared",
]
@@ -142,7 +142,7 @@
"kind": "chart",
"title": "subscript, remove existing from unique collection",
"tasks": [
"PersistentDictionary<Int, Int> subscript, remove existing, unique",
"ShareableDictionary<Int, Int> subscript, remove existing, unique",
"Dictionary<Int, Int> subscript, remove existing, unique",
"OrderedDictionary<Int, Int> subscript, remove existing, unique",
]
@@ -151,7 +151,7 @@
"kind": "chart",
"title": "subscript, remove existing from shared collection",
"tasks": [
"PersistentDictionary<Int, Int> subscript, remove existing, shared",
"ShareableDictionary<Int, Int> subscript, remove existing, shared",
"Dictionary<Int, Int> subscript, remove existing, shared",
"OrderedDictionary<Int, Int> subscript, remove existing, shared",
]
@@ -160,8 +160,8 @@
"kind": "chart",
"title": "subscript, _modify existing",
"tasks": [
"PersistentDictionary<Int, Int> subscript, _modify",
"PersistentDictionary<Int, Int> defaulted subscript, _modify existing",
"ShareableDictionary<Int, Int> subscript, _modify",
"ShareableDictionary<Int, Int> defaulted subscript, _modify existing",
"Dictionary<Int, Int> subscript, _modify",
"Dictionary<Int, Int> defaulted subscript, _modify existing",
"OrderedDictionary<Int, Int> subscript, _modify",
@@ -173,7 +173,7 @@
"kind": "chart",
"title": "index(forKey:), successful index(forKey:)",
"tasks": [
"PersistentDictionary<Int, Int> successful index(forKey:)",
"ShareableDictionary<Int, Int> successful index(forKey:)",
"Dictionary<Int, Int> successful index(forKey:)",
"OrderedDictionary<Int, Int> successful index(forKey:)",
]
@@ -182,7 +182,7 @@
"kind": "chart",
"title": "index(forKey:), unsuccessful index(forKey:)",
"tasks": [
"PersistentDictionary<Int, Int> unsuccessful index(forKey:)",
"ShareableDictionary<Int, Int> unsuccessful index(forKey:)",
"Dictionary<Int, Int> unsuccessful index(forKey:)",
"OrderedDictionary<Int, Int> unsuccessful index(forKey:)",
]
@@ -191,7 +191,7 @@
"kind": "chart",
"title": "updateValue(_:forKey:), existing",
"tasks": [
"PersistentDictionary<Int, Int> updateValue(_:forKey:), existing",
"ShareableDictionary<Int, Int> updateValue(_:forKey:), existing",
"Dictionary<Int, Int> updateValue(_:forKey:), existing",
"OrderedDictionary<Int, Int> updateValue(_:forKey:), existing"
]
@@ -200,7 +200,7 @@
"kind": "chart",
"title": "updateValue(_:forKey:), insert",
"tasks": [
"PersistentDictionary<Int, Int> updateValue(_:forKey:), insert",
"ShareableDictionary<Int, Int> updateValue(_:forKey:), insert",
"Dictionary<Int, Int> updateValue(_:forKey:), insert",
"OrderedDictionary<Int, Int> updateValue(_:forKey:), append"
]
@@ -1,27 +1,27 @@
{
"kind": "group",
"title": "PersistentSet Benchmarks",
"title": "ShareableSet Benchmarks",
"directory": "Results",
"contents": [
{
"kind": "chart",
"title": "operations",
"tasks": [
"PersistentSet<Int> init from range",
"PersistentSet<Int> init from unsafe buffer",
"PersistentSet<Int> sequential iteration",
"PersistentSet<Int> successful contains",
"PersistentSet<Int> unsuccessful contains",
"PersistentSet<Int> insert",
"PersistentSet<Int> remove"
"ShareableSet<Int> init from range",
"ShareableSet<Int> init from unsafe buffer",
"ShareableSet<Int> sequential iteration",
"ShareableSet<Int> successful contains",
"ShareableSet<Int> unsuccessful contains",
"ShareableSet<Int> insert",
"ShareableSet<Int> remove"
]
},
{
"kind": "chart",
"title": "initializers",
"tasks": [
"PersistentSet<Int> init from range",
"PersistentSet<Int> init from unsafe buffer",
"ShareableSet<Int> init from range",
"ShareableSet<Int> init from unsafe buffer",
]
},
{
@@ -31,44 +31,44 @@
"kind": "chart",
"title": "union with Self",
"tasks": [
"PersistentSet<Int> union with Self (0% overlap)",
"PersistentSet<Int> union with Self (25% overlap)",
"PersistentSet<Int> union with Self (50% overlap)",
"PersistentSet<Int> union with Self (75% overlap)",
"PersistentSet<Int> union with Self (100% overlap)",
"ShareableSet<Int> union with Self (0% overlap)",
"ShareableSet<Int> union with Self (25% overlap)",
"ShareableSet<Int> union with Self (50% overlap)",
"ShareableSet<Int> union with Self (75% overlap)",
"ShareableSet<Int> union with Self (100% overlap)",
]
},
{
"kind": "chart",
"title": "union with Array",
"tasks": [
"PersistentSet<Int> union with Array (0% overlap)",
"PersistentSet<Int> union with Array (25% overlap)",
"PersistentSet<Int> union with Array (50% overlap)",
"PersistentSet<Int> union with Array (75% overlap)",
"PersistentSet<Int> union with Array (100% overlap)",
"ShareableSet<Int> union with Array (0% overlap)",
"ShareableSet<Int> union with Array (25% overlap)",
"ShareableSet<Int> union with Array (50% overlap)",
"ShareableSet<Int> union with Array (75% overlap)",
"ShareableSet<Int> union with Array (100% overlap)",
]
},
{
"kind": "chart",
"title": "formUnion with Self",
"tasks": [
"PersistentSet<Int> formUnion with Self (0% overlap)",
"PersistentSet<Int> formUnion with Self (25% overlap)",
"PersistentSet<Int> formUnion with Self (50% overlap)",
"PersistentSet<Int> formUnion with Self (75% overlap)",
"PersistentSet<Int> formUnion with Self (100% overlap)",
"ShareableSet<Int> formUnion with Self (0% overlap)",
"ShareableSet<Int> formUnion with Self (25% overlap)",
"ShareableSet<Int> formUnion with Self (50% overlap)",
"ShareableSet<Int> formUnion with Self (75% overlap)",
"ShareableSet<Int> formUnion with Self (100% overlap)",
]
},
{
"kind": "chart",
"title": "formUnion with Array",
"tasks": [
"PersistentSet<Int> formUnion with Array (0% overlap)",
"PersistentSet<Int> formUnion with Array (25% overlap)",
"PersistentSet<Int> formUnion with Array (50% overlap)",
"PersistentSet<Int> formUnion with Array (75% overlap)",
"PersistentSet<Int> formUnion with Array (100% overlap)",
"ShareableSet<Int> formUnion with Array (0% overlap)",
"ShareableSet<Int> formUnion with Array (25% overlap)",
"ShareableSet<Int> formUnion with Array (50% overlap)",
"ShareableSet<Int> formUnion with Array (75% overlap)",
"ShareableSet<Int> formUnion with Array (100% overlap)",
]
},
]
@@ -80,44 +80,44 @@
"kind": "chart",
"title": "intersection with Self",
"tasks": [
"PersistentSet<Int> intersection with Self (0% overlap)",
"PersistentSet<Int> intersection with Self (25% overlap)",
"PersistentSet<Int> intersection with Self (50% overlap)",
"PersistentSet<Int> intersection with Self (75% overlap)",
"PersistentSet<Int> intersection with Self (100% overlap)",
"ShareableSet<Int> intersection with Self (0% overlap)",
"ShareableSet<Int> intersection with Self (25% overlap)",
"ShareableSet<Int> intersection with Self (50% overlap)",
"ShareableSet<Int> intersection with Self (75% overlap)",
"ShareableSet<Int> intersection with Self (100% overlap)",
]
},
{
"kind": "chart",
"title": "intersection with Array",
"tasks": [
"PersistentSet<Int> intersection with Array (0% overlap)",
"PersistentSet<Int> intersection with Array (25% overlap)",
"PersistentSet<Int> intersection with Array (50% overlap)",
"PersistentSet<Int> intersection with Array (75% overlap)",
"PersistentSet<Int> intersection with Array (100% overlap)",
"ShareableSet<Int> intersection with Array (0% overlap)",
"ShareableSet<Int> intersection with Array (25% overlap)",
"ShareableSet<Int> intersection with Array (50% overlap)",
"ShareableSet<Int> intersection with Array (75% overlap)",
"ShareableSet<Int> intersection with Array (100% overlap)",
]
},
{
"kind": "chart",
"title": "formIntersection with Self",
"tasks": [
"PersistentSet<Int> formIntersection with Self (0% overlap)",
"PersistentSet<Int> formIntersection with Self (25% overlap)",
"PersistentSet<Int> formIntersection with Self (50% overlap)",
"PersistentSet<Int> formIntersection with Self (75% overlap)",
"PersistentSet<Int> formIntersection with Self (100% overlap)",
"ShareableSet<Int> formIntersection with Self (0% overlap)",
"ShareableSet<Int> formIntersection with Self (25% overlap)",
"ShareableSet<Int> formIntersection with Self (50% overlap)",
"ShareableSet<Int> formIntersection with Self (75% overlap)",
"ShareableSet<Int> formIntersection with Self (100% overlap)",
]
},
{
"kind": "chart",
"title": "formIntersection with Array",
"tasks": [
"PersistentSet<Int> formIntersection with Array (0% overlap)",
"PersistentSet<Int> formIntersection with Array (25% overlap)",
"PersistentSet<Int> formIntersection with Array (50% overlap)",
"PersistentSet<Int> formIntersection with Array (75% overlap)",
"PersistentSet<Int> formIntersection with Array (100% overlap)",
"ShareableSet<Int> formIntersection with Array (0% overlap)",
"ShareableSet<Int> formIntersection with Array (25% overlap)",
"ShareableSet<Int> formIntersection with Array (50% overlap)",
"ShareableSet<Int> formIntersection with Array (75% overlap)",
"ShareableSet<Int> formIntersection with Array (100% overlap)",
]
},
]
@@ -129,44 +129,44 @@
"kind": "chart",
"title": "symmetricDifference with Self",
"tasks": [
"PersistentSet<Int> symmetricDifference with Self (0% overlap)",
"PersistentSet<Int> symmetricDifference with Self (25% overlap)",
"PersistentSet<Int> symmetricDifference with Self (50% overlap)",
"PersistentSet<Int> symmetricDifference with Self (75% overlap)",
"PersistentSet<Int> symmetricDifference with Self (100% overlap)",
"ShareableSet<Int> symmetricDifference with Self (0% overlap)",
"ShareableSet<Int> symmetricDifference with Self (25% overlap)",
"ShareableSet<Int> symmetricDifference with Self (50% overlap)",
"ShareableSet<Int> symmetricDifference with Self (75% overlap)",
"ShareableSet<Int> symmetricDifference with Self (100% overlap)",
]
},
{
"kind": "chart",
"title": "symmetricDifference with Array",
"tasks": [
"PersistentSet<Int> symmetricDifference with Array (0% overlap)",
"PersistentSet<Int> symmetricDifference with Array (25% overlap)",
"PersistentSet<Int> symmetricDifference with Array (50% overlap)",
"PersistentSet<Int> symmetricDifference with Array (75% overlap)",
"PersistentSet<Int> symmetricDifference with Array (100% overlap)",
"ShareableSet<Int> symmetricDifference with Array (0% overlap)",
"ShareableSet<Int> symmetricDifference with Array (25% overlap)",
"ShareableSet<Int> symmetricDifference with Array (50% overlap)",
"ShareableSet<Int> symmetricDifference with Array (75% overlap)",
"ShareableSet<Int> symmetricDifference with Array (100% overlap)",
]
},
{
"kind": "chart",
"title": "formSymmetricDifference with Self",
"tasks": [
"PersistentSet<Int> formSymmetricDifference with Self (0% overlap)",
"PersistentSet<Int> formSymmetricDifference with Self (25% overlap)",
"PersistentSet<Int> formSymmetricDifference with Self (50% overlap)",
"PersistentSet<Int> formSymmetricDifference with Self (75% overlap)",
"PersistentSet<Int> formSymmetricDifference with Self (100% overlap)",
"ShareableSet<Int> formSymmetricDifference with Self (0% overlap)",
"ShareableSet<Int> formSymmetricDifference with Self (25% overlap)",
"ShareableSet<Int> formSymmetricDifference with Self (50% overlap)",
"ShareableSet<Int> formSymmetricDifference with Self (75% overlap)",
"ShareableSet<Int> formSymmetricDifference with Self (100% overlap)",
]
},
{
"kind": "chart",
"title": "formSymmetricDifference with Array",
"tasks": [
"PersistentSet<Int> formSymmetricDifference with Array (0% overlap)",
"PersistentSet<Int> formSymmetricDifference with Array (25% overlap)",
"PersistentSet<Int> formSymmetricDifference with Array (50% overlap)",
"PersistentSet<Int> formSymmetricDifference with Array (75% overlap)",
"PersistentSet<Int> formSymmetricDifference with Array (100% overlap)",
"ShareableSet<Int> formSymmetricDifference with Array (0% overlap)",
"ShareableSet<Int> formSymmetricDifference with Array (25% overlap)",
"ShareableSet<Int> formSymmetricDifference with Array (50% overlap)",
"ShareableSet<Int> formSymmetricDifference with Array (75% overlap)",
"ShareableSet<Int> formSymmetricDifference with Array (100% overlap)",
]
},
]
@@ -178,44 +178,44 @@
"kind": "chart",
"title": "subtracting Self",
"tasks": [
"PersistentSet<Int> subtracting Self (0% overlap)",
"PersistentSet<Int> subtracting Self (25% overlap)",
"PersistentSet<Int> subtracting Self (50% overlap)",
"PersistentSet<Int> subtracting Self (75% overlap)",
"PersistentSet<Int> subtracting Self (100% overlap)",
"ShareableSet<Int> subtracting Self (0% overlap)",
"ShareableSet<Int> subtracting Self (25% overlap)",
"ShareableSet<Int> subtracting Self (50% overlap)",
"ShareableSet<Int> subtracting Self (75% overlap)",
"ShareableSet<Int> subtracting Self (100% overlap)",
]
},
{
"kind": "chart",
"title": "subtracting Array",
"tasks": [
"PersistentSet<Int> subtracting Array (0% overlap)",
"PersistentSet<Int> subtracting Array (25% overlap)",
"PersistentSet<Int> subtracting Array (50% overlap)",
"PersistentSet<Int> subtracting Array (75% overlap)",
"PersistentSet<Int> subtracting Array (100% overlap)",
"ShareableSet<Int> subtracting Array (0% overlap)",
"ShareableSet<Int> subtracting Array (25% overlap)",
"ShareableSet<Int> subtracting Array (50% overlap)",
"ShareableSet<Int> subtracting Array (75% overlap)",
"ShareableSet<Int> subtracting Array (100% overlap)",
]
},
{
"kind": "chart",
"title": "subtract Self",
"tasks": [
"PersistentSet<Int> subtract Self (0% overlap)",
"PersistentSet<Int> subtract Self (25% overlap)",
"PersistentSet<Int> subtract Self (50% overlap)",
"PersistentSet<Int> subtract Self (75% overlap)",
"PersistentSet<Int> subtract Self (100% overlap)",
"ShareableSet<Int> subtract Self (0% overlap)",
"ShareableSet<Int> subtract Self (25% overlap)",
"ShareableSet<Int> subtract Self (50% overlap)",
"ShareableSet<Int> subtract Self (75% overlap)",
"ShareableSet<Int> subtract Self (100% overlap)",
]
},
{
"kind": "chart",
"title": "subtract with Array",
"tasks": [
"PersistentSet<Int> subtract Array (0% overlap)",
"PersistentSet<Int> subtract Array (25% overlap)",
"PersistentSet<Int> subtract Array (50% overlap)",
"PersistentSet<Int> subtract Array (75% overlap)",
"PersistentSet<Int> subtract Array (100% overlap)",
"ShareableSet<Int> subtract Array (0% overlap)",
"ShareableSet<Int> subtract Array (25% overlap)",
"ShareableSet<Int> subtract Array (50% overlap)",
"ShareableSet<Int> subtract Array (75% overlap)",
"ShareableSet<Int> subtract Array (100% overlap)",
]
},
]
@@ -229,7 +229,7 @@
"kind": "chart",
"title": "init from buffer of integers",
"tasks": [
"PersistentSet<Int> init from unsafe buffer",
"ShareableSet<Int> init from unsafe buffer",
"Set<Int> init from unsafe buffer",
]
},
@@ -237,7 +237,7 @@
"kind": "chart",
"title": "init from range of integers",
"tasks": [
"PersistentSet<Int> init from range",
"ShareableSet<Int> init from range",
"Set<Int> init from range",
]
},
@@ -245,7 +245,7 @@
"kind": "chart",
"title": "sequential iteration",
"tasks": [
"PersistentSet<Int> sequential iteration",
"ShareableSet<Int> sequential iteration",
"Set<Int> sequential iteration",
]
},
@@ -253,7 +253,7 @@
"kind": "chart",
"title": "sequential iteration using indices",
"tasks": [
"PersistentSet<Int> sequential iteration, indices",
"ShareableSet<Int> sequential iteration, indices",
"Set<Int> sequential iteration, indices",
]
},
@@ -261,7 +261,7 @@
"kind": "chart",
"title": "successful random lookups",
"tasks": [
"PersistentSet<Int> successful contains",
"ShareableSet<Int> successful contains",
"Set<Int> successful contains",
]
},
@@ -269,7 +269,7 @@
"kind": "chart",
"title": "unsuccessful random lookups",
"tasks": [
"PersistentSet<Int> unsuccessful contains",
"ShareableSet<Int> unsuccessful contains",
"Set<Int> unsuccessful contains",
]
},
@@ -277,7 +277,7 @@
"kind": "chart",
"title": "insert",
"tasks": [
"PersistentSet<Int> insert",
"ShareableSet<Int> insert",
"Set<Int> insert",
"Set<Int> insert, reserving capacity",
]
@@ -286,7 +286,7 @@
"kind": "chart",
"title": "insert-shared",
"tasks": [
"PersistentSet<Int> insert, shared",
"ShareableSet<Int> insert, shared",
"Set<Int> insert, shared",
]
},
@@ -294,7 +294,7 @@
"kind": "chart",
"title": "diffing",
"tasks": [
"PersistentSet<Int> insert one + subtract, shared",
"ShareableSet<Int> insert one + subtract, shared",
"Set<Int> insert one + subtract, shared",
]
},
@@ -302,7 +302,7 @@
"kind": "chart",
"title": "diffing2",
"tasks": [
"PersistentSet<Int> model diffing",
"ShareableSet<Int> model diffing",
"Set<Int> model diffing",
]
},
@@ -310,8 +310,8 @@
"kind": "chart",
"title": "remove",
"tasks": [
"PersistentSet<Int> remove",
"PersistentSet<Int> remove, shared",
"ShareableSet<Int> remove",
"ShareableSet<Int> remove, shared",
"Set<Int> remove",
"Set<Int> remove, shared",
]
@@ -10,25 +10,25 @@
//===----------------------------------------------------------------------===//
import CollectionsBenchmark
import PersistentCollections
import ShareableHashedCollections
extension Benchmark {
public mutating func addPersistentDictionaryBenchmarks() {
public mutating func addShareableDictionaryBenchmarks() {
self.add(
title: "PersistentDictionary<Int, Int> init(uniqueKeysWithValues:)",
title: "ShareableDictionary<Int, Int> init(uniqueKeysWithValues:)",
input: [Int].self
) { input in
let keysAndValues = input.map { ($0, 2 * $0) }
return { timer in
blackHole(PersistentDictionary(uniqueKeysWithValues: keysAndValues))
blackHole(ShareableDictionary(uniqueKeysWithValues: keysAndValues))
}
}
self.add(
title: "PersistentDictionary<Int, Int> sequential iteration",
title: "ShareableDictionary<Int, Int> sequential iteration",
input: [Int].self
) { input in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
return { timer in
for item in d {
blackHole(item)
@@ -37,10 +37,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int>.Keys sequential iteration",
title: "ShareableDictionary<Int, Int>.Keys sequential iteration",
input: [Int].self
) { input in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
return { timer in
for item in d.keys {
blackHole(item)
@@ -49,10 +49,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int>.Values sequential iteration",
title: "ShareableDictionary<Int, Int>.Values sequential iteration",
input: [Int].self
) { input in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
return { timer in
for item in d.values {
blackHole(item)
@@ -61,10 +61,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> sequential iteration, indices",
title: "ShareableDictionary<Int, Int> sequential iteration, indices",
input: [Int].self
) { input in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
return { timer in
for i in d.indices {
blackHole(d[i])
@@ -73,10 +73,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> striding, 10 steps",
title: "ShareableDictionary<Int, Int> striding, 10 steps",
input: [Int].self
) { input in
let d = PersistentDictionary(
let d = ShareableDictionary(
uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let steps = stride(from: 0, through: 10 * d.count, by: d.count)
.map { $0 / 10 }
@@ -92,10 +92,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> indexing subscript",
title: "ShareableDictionary<Int, Int> indexing subscript",
input: ([Int], [Int]).self
) { input, lookups in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let indices = lookups.map { d.index(forKey: $0)! }
return { timer in
for i in indices {
@@ -105,10 +105,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> subscript, successful lookups",
title: "ShareableDictionary<Int, Int> subscript, successful lookups",
input: ([Int], [Int]).self
) { input, lookups in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
return { timer in
for i in lookups {
precondition(d[i] == 2 * i)
@@ -117,10 +117,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> subscript, unsuccessful lookups",
title: "ShareableDictionary<Int, Int> subscript, unsuccessful lookups",
input: ([Int], [Int]).self
) { input, lookups in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let c = input.count
return { timer in
for i in lookups {
@@ -130,11 +130,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> subscript, noop setter",
title: "ShareableDictionary<Int, Int> subscript, noop setter",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let c = input.count
timer.measure {
for i in lookups {
@@ -147,11 +147,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> subscript, set existing",
title: "ShareableDictionary<Int, Int> subscript, set existing",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
timer.measure {
for i in lookups {
d[i] = 0
@@ -163,11 +163,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> subscript, _modify",
title: "ShareableDictionary<Int, Int> subscript, _modify",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
timer.measure {
for i in lookups {
d[i]! *= 2
@@ -179,10 +179,10 @@ extension Benchmark {
}
self.addSimple(
title: "PersistentDictionary<Int, Int> subscript, insert, unique",
title: "ShareableDictionary<Int, Int> subscript, insert, unique",
input: [Int].self
) { input in
var d: PersistentDictionary<Int, Int> = [:]
var d: ShareableDictionary<Int, Int> = [:]
for i in input {
d[i] = 2 * i
}
@@ -191,10 +191,10 @@ extension Benchmark {
}
self.addSimple(
title: "PersistentDictionary<Int, Int> subscript, insert, shared",
title: "ShareableDictionary<Int, Int> subscript, insert, shared",
input: [Int].self
) { input in
var d: PersistentDictionary<Int, Int> = [:]
var d: ShareableDictionary<Int, Int> = [:]
for i in input {
let copy = d
d[i] = 2 * i
@@ -205,11 +205,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> subscript, remove existing, unique",
title: "ShareableDictionary<Int, Int> subscript, remove existing, unique",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
timer.measure {
for i in lookups {
d[i] = nil
@@ -221,11 +221,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> subscript, remove existing, shared",
title: "ShareableDictionary<Int, Int> subscript, remove existing, shared",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
timer.measure {
for i in lookups {
let copy = d
@@ -239,11 +239,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> subscript, remove missing",
title: "ShareableDictionary<Int, Int> subscript, remove missing",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let c = input.count
timer.measure {
for i in lookups {
@@ -256,10 +256,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> defaulted subscript, successful lookups",
title: "ShareableDictionary<Int, Int> defaulted subscript, successful lookups",
input: ([Int], [Int]).self
) { input, lookups in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
return { timer in
for i in lookups {
precondition(d[i, default: -1] != -1)
@@ -268,10 +268,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> defaulted subscript, unsuccessful lookups",
title: "ShareableDictionary<Int, Int> defaulted subscript, unsuccessful lookups",
input: ([Int], [Int]).self
) { input, lookups in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
return { timer in
let c = d.count
for i in lookups {
@@ -281,11 +281,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> defaulted subscript, _modify existing",
title: "ShareableDictionary<Int, Int> defaulted subscript, _modify existing",
input: [Int].self
) { input in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
timer.measure {
for i in input {
d[i, default: -1] *= 2
@@ -297,11 +297,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> defaulted subscript, _modify missing",
title: "ShareableDictionary<Int, Int> defaulted subscript, _modify missing",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let c = input.count
timer.measure {
for i in lookups {
@@ -314,10 +314,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> successful index(forKey:)",
title: "ShareableDictionary<Int, Int> successful index(forKey:)",
input: ([Int], [Int]).self
) { input, lookups in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
return { timer in
for i in lookups {
precondition(d.index(forKey: i) != nil)
@@ -326,10 +326,10 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> unsuccessful index(forKey:)",
title: "ShareableDictionary<Int, Int> unsuccessful index(forKey:)",
input: ([Int], [Int]).self
) { input, lookups in
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
return { timer in
for i in lookups {
precondition(d.index(forKey: lookups.count + i) == nil)
@@ -338,11 +338,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> updateValue(_:forKey:), existing",
title: "ShareableDictionary<Int, Int> updateValue(_:forKey:), existing",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
timer.measure {
for i in lookups {
d.updateValue(0, forKey: i)
@@ -354,11 +354,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> updateValue(_:forKey:), insert",
title: "ShareableDictionary<Int, Int> updateValue(_:forKey:), insert",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
timer.measure {
for i in lookups {
d.updateValue(0, forKey: input.count + i)
@@ -370,11 +370,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> random removals (existing keys)",
title: "ShareableDictionary<Int, Int> random removals (existing keys)",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
timer.measure {
for i in lookups {
precondition(d.removeValue(forKey: i) != nil)
@@ -386,12 +386,12 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Int, Int> random removals (missing keys)",
title: "ShareableDictionary<Int, Int> random removals (missing keys)",
input: ([Int], [Int]).self
) { input, lookups in
return { timer in
let c = input.count
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { (c + $0, 2 * $0) })
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { (c + $0, 2 * $0) })
timer.measure {
for i in lookups {
precondition(d.removeValue(forKey: i) == nil)
@@ -403,11 +403,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Large, Large> subscript, insert, unique",
title: "ShareableDictionary<Large, Large> subscript, insert, unique",
input: [Large].self
) { input in
return { timer in
var d: PersistentDictionary<Large, Large> = [:]
var d: ShareableDictionary<Large, Large> = [:]
timer.measure {
for value in input {
d[value] = value
@@ -419,11 +419,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Large, Large> subscript, insert, shared",
title: "ShareableDictionary<Large, Large> subscript, insert, shared",
input: [Large].self
) { input in
return { timer in
var d: PersistentDictionary<Large, Large> = [:]
var d: ShareableDictionary<Large, Large> = [:]
timer.measure {
for value in input {
let copy = d
@@ -437,11 +437,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Large, Large> subscript, remove existing, unique",
title: "ShareableDictionary<Large, Large> subscript, remove existing, unique",
input: ([Large], [Large]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(
var d = ShareableDictionary(
uniqueKeysWithValues: input.lazy.map { ($0, $0) })
timer.measure {
for key in lookups {
@@ -454,11 +454,11 @@ extension Benchmark {
}
self.add(
title: "PersistentDictionary<Large, Large> subscript, remove existing, shared",
title: "ShareableDictionary<Large, Large> subscript, remove existing, shared",
input: ([Large], [Large]).self
) { input, lookups in
return { timer in
var d = PersistentDictionary(
var d = ShareableDictionary(
uniqueKeysWithValues: input.lazy.map { ($0, $0) })
timer.measure {
for key in lookups {
@@ -10,31 +10,31 @@
//===----------------------------------------------------------------------===//
import CollectionsBenchmark
import PersistentCollections
import ShareableHashedCollections
extension Benchmark {
public mutating func addPersistentSetBenchmarks() {
public mutating func addShareableSetBenchmarks() {
self.addSimple(
title: "PersistentSet<Int> init from range",
title: "ShareableSet<Int> init from range",
input: Int.self
) { size in
blackHole(PersistentSet(0 ..< size))
blackHole(ShareableSet(0 ..< size))
}
self.addSimple(
title: "PersistentSet<Int> init from unsafe buffer",
title: "ShareableSet<Int> init from unsafe buffer",
input: [Int].self
) { input in
input.withUnsafeBufferPointer { buffer in
blackHole(PersistentSet(buffer))
blackHole(ShareableSet(buffer))
}
}
self.add(
title: "PersistentSet<Int> sequential iteration",
title: "ShareableSet<Int> sequential iteration",
input: Int.self
) { size in
let set = PersistentSet(0 ..< size)
let set = ShareableSet(0 ..< size)
return { timer in
for i in set {
blackHole(i)
@@ -43,10 +43,10 @@ extension Benchmark {
}
self.add(
title: "PersistentSet<Int> sequential iteration, indices",
title: "ShareableSet<Int> sequential iteration, indices",
input: Int.self
) { size in
let set = PersistentSet(0 ..< size)
let set = ShareableSet(0 ..< size)
return { timer in
for i in set.indices {
blackHole(set[i])
@@ -55,10 +55,10 @@ extension Benchmark {
}
self.add(
title: "PersistentSet<Int> successful contains",
title: "ShareableSet<Int> successful contains",
input: ([Int], [Int]).self
) { input, lookups in
let set = PersistentSet(input)
let set = ShareableSet(input)
return { timer in
for i in lookups {
precondition(set.contains(i))
@@ -67,10 +67,10 @@ extension Benchmark {
}
self.add(
title: "PersistentSet<Int> unsuccessful contains",
title: "ShareableSet<Int> unsuccessful contains",
input: ([Int], [Int]).self
) { input, lookups in
let set = PersistentSet(input)
let set = ShareableSet(input)
let lookups = lookups.map { $0 + input.count }
return { timer in
for i in lookups {
@@ -80,10 +80,10 @@ extension Benchmark {
}
self.addSimple(
title: "PersistentSet<Int> insert",
title: "ShareableSet<Int> insert",
input: [Int].self
) { input in
var set: PersistentSet<Int> = []
var set: ShareableSet<Int> = []
for i in input {
set.insert(i)
}
@@ -92,10 +92,10 @@ extension Benchmark {
}
self.addSimple(
title: "PersistentSet<Int> insert, shared",
title: "ShareableSet<Int> insert, shared",
input: [Int].self
) { input in
var set: PersistentSet<Int> = []
var set: ShareableSet<Int> = []
for i in input {
let copy = set
set.insert(i)
@@ -106,10 +106,10 @@ extension Benchmark {
}
self.add(
title: "PersistentSet<Int> insert one + subtract, shared",
title: "ShareableSet<Int> insert one + subtract, shared",
input: [Int].self
) { input in
let original = PersistentSet(input)
let original = ShareableSet(input)
let newMember = input.count
return { timer in
var copy = original
@@ -121,10 +121,10 @@ extension Benchmark {
}
self.addSimple(
title: "PersistentSet<Int> model diffing",
title: "ShareableSet<Int> model diffing",
input: Int.self
) { input in
typealias Model = PersistentSet<Int>
typealias Model = ShareableSet<Int>
var _state: Model = [] // Private
func updateState(
@@ -145,11 +145,11 @@ extension Benchmark {
}
self.add(
title: "PersistentSet<Int> remove",
title: "ShareableSet<Int> remove",
input: ([Int], [Int]).self
) { input, removals in
return { timer in
var set = PersistentSet(input)
var set = ShareableSet(input)
for i in removals {
set.remove(i)
}
@@ -159,11 +159,11 @@ extension Benchmark {
}
self.add(
title: "PersistentSet<Int> remove, shared",
title: "ShareableSet<Int> remove, shared",
input: ([Int], [Int]).self
) { input, removals in
return { timer in
var set = PersistentSet(input)
var set = ShareableSet(input)
for i in removals {
let copy = set
set.remove(i)
@@ -186,12 +186,12 @@ extension Benchmark {
do {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> union with Self (\(percentage) overlap)",
title: "ShareableSet<Int> union with Self (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let a = PersistentSet(input)
let b = PersistentSet(start ..< start + input.count)
let a = ShareableSet(input)
let b = ShareableSet(start ..< start + input.count)
return { timer in
blackHole(a.union(identity(b)))
}
@@ -200,12 +200,12 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> intersection with Self (\(percentage) overlap)",
title: "ShareableSet<Int> intersection with Self (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let a = PersistentSet(input)
let b = PersistentSet(start ..< start + input.count)
let a = ShareableSet(input)
let b = ShareableSet(start ..< start + input.count)
return { timer in
blackHole(a.intersection(identity(b)))
}
@@ -214,12 +214,12 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> symmetricDifference with Self (\(percentage) overlap)",
title: "ShareableSet<Int> symmetricDifference with Self (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let a = PersistentSet(input)
let b = PersistentSet(start ..< start + input.count)
let a = ShareableSet(input)
let b = ShareableSet(start ..< start + input.count)
return { timer in
blackHole(a.symmetricDifference(identity(b)))
}
@@ -228,12 +228,12 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> subtracting Self (\(percentage) overlap)",
title: "ShareableSet<Int> subtracting Self (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let a = PersistentSet(input)
let b = PersistentSet(start ..< start + input.count)
let a = ShareableSet(input)
let b = ShareableSet(start ..< start + input.count)
return { timer in
blackHole(a.subtracting(identity(b)))
}
@@ -245,11 +245,11 @@ extension Benchmark {
do {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> union with Array (\(percentage) overlap)",
title: "ShareableSet<Int> union with Array (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let a = PersistentSet(input)
let a = ShareableSet(input)
let b = Array(start ..< start + input.count)
return { timer in
blackHole(a.union(identity(b)))
@@ -259,11 +259,11 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> intersection with Array (\(percentage) overlap)",
title: "ShareableSet<Int> intersection with Array (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let a = PersistentSet(input)
let a = ShareableSet(input)
let b = Array(start ..< start + input.count)
return { timer in
blackHole(a.intersection(identity(b)))
@@ -273,11 +273,11 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> symmetricDifference with Array (\(percentage) overlap)",
title: "ShareableSet<Int> symmetricDifference with Array (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let a = PersistentSet(input)
let a = ShareableSet(input)
let b = Array(start ..< start + input.count)
return { timer in
blackHole(a.symmetricDifference(identity(b)))
@@ -287,11 +287,11 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> subtracting Array (\(percentage) overlap)",
title: "ShareableSet<Int> subtracting Array (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let a = PersistentSet(input)
let a = ShareableSet(input)
let b = Array(start ..< start + input.count)
return { timer in
blackHole(a.subtracting(identity(b)))
@@ -304,13 +304,13 @@ extension Benchmark {
do {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> formUnion with Self (\(percentage) overlap)",
title: "ShareableSet<Int> formUnion with Self (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let b = PersistentSet(start ..< start + input.count)
let b = ShareableSet(start ..< start + input.count)
return { timer in
var a = PersistentSet(input)
var a = ShareableSet(input)
timer.measure {
a.formUnion(identity(b))
}
@@ -321,13 +321,13 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> formIntersection with Self (\(percentage) overlap)",
title: "ShareableSet<Int> formIntersection with Self (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let b = PersistentSet(start ..< start + input.count)
let b = ShareableSet(start ..< start + input.count)
return { timer in
var a = PersistentSet(input)
var a = ShareableSet(input)
timer.measure {
a.formIntersection(identity(b))
}
@@ -338,13 +338,13 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> formSymmetricDifference with Self (\(percentage) overlap)",
title: "ShareableSet<Int> formSymmetricDifference with Self (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let b = PersistentSet(start ..< start + input.count)
let b = ShareableSet(start ..< start + input.count)
return { timer in
var a = PersistentSet(input)
var a = ShareableSet(input)
timer.measure {
a.formSymmetricDifference(identity(b))
}
@@ -355,13 +355,13 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> subtract Self (\(percentage) overlap)",
title: "ShareableSet<Int> subtract Self (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let b = PersistentSet(start ..< start + input.count)
let b = ShareableSet(start ..< start + input.count)
return { timer in
var a = PersistentSet(input)
var a = ShareableSet(input)
timer.measure {
a.subtract(identity(b))
}
@@ -375,13 +375,13 @@ extension Benchmark {
do {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> formUnion with Array (\(percentage) overlap)",
title: "ShareableSet<Int> formUnion with Array (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let b = Array(start ..< start + input.count)
return { timer in
var a = PersistentSet(input)
var a = ShareableSet(input)
timer.measure {
a.formUnion(identity(b))
}
@@ -392,13 +392,13 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> formIntersection with Array (\(percentage) overlap)",
title: "ShareableSet<Int> formIntersection with Array (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let b = Array(start ..< start + input.count)
return { timer in
var a = PersistentSet(input)
var a = ShareableSet(input)
timer.measure {
a.formIntersection(identity(b))
}
@@ -409,13 +409,13 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> formSymmetricDifference with Array (\(percentage) overlap)",
title: "ShareableSet<Int> formSymmetricDifference with Array (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let b = Array(start ..< start + input.count)
return { timer in
var a = PersistentSet(input)
var a = ShareableSet(input)
timer.measure {
a.formSymmetricDifference(identity(b))
}
@@ -426,13 +426,13 @@ extension Benchmark {
for (percentage, start) in overlaps {
self.add(
title: "PersistentSet<Int> subtract Array (\(percentage) overlap)",
title: "ShareableSet<Int> subtract Array (\(percentage) overlap)",
input: [Int].self
) { input in
let start = start(input.count)
let b = Array(start ..< start + input.count)
return { timer in
var a = PersistentSet(input)
var a = ShareableSet(input)
timer.measure {
a.subtract(identity(b))
}
+2 -2
View File
@@ -29,13 +29,13 @@ benchmark.registerCustomGenerators()
benchmark.addArrayBenchmarks()
benchmark.addSetBenchmarks()
benchmark.addDictionaryBenchmarks()
benchmark.addPersistentDictionaryBenchmarks()
benchmark.addShareableDictionaryBenchmarks()
benchmark.addDequeBenchmarks()
benchmark.addOrderedSetBenchmarks()
benchmark.addOrderedDictionaryBenchmarks()
benchmark.addHeapBenchmarks()
benchmark.addBitSetBenchmarks()
benchmark.addPersistentSetBenchmarks()
benchmark.addShareableSetBenchmarks()
benchmark.addCppBenchmarks()
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
benchmark.addFoundationBenchmarks()
@@ -30,11 +30,11 @@ struct MemoryBenchmarks: ParsableCommand {
var i = 0
var d: Dictionary<String, String> = [:]
var pd: PersistentDictionary<String, String> = [:]
var pd: ShareableDictionary<String, String> = [:]
print("""
Size,"Dictionary<String, String>",\
"PersistentDictionary<String, String>",\
"ShareableDictionary<String, String>",\
"average node size",\
"average item depth"
""")
@@ -67,9 +67,9 @@ struct MemoryBenchmarks: ParsableCommand {
complain("""
Averages:
Dictionary: \(sumd / Double(sizes.count))
PersistentDictionary: \(sump / Double(sizes.count))
ShareableDictionary: \(sump / Double(sizes.count))
PersistentDictionary at 1M items:
ShareableDictionary at 1M items:
average node size: \(pstats.averageNodeSize)
average item depth: \(pstats.averageItemDepth)
average lookup chain length: \(pstats.averageLookupChainLength)
+6 -6
View File
@@ -52,7 +52,7 @@ let package = Package(
.library(name: "DequeModule", targets: ["DequeModule"]),
.library(name: "HeapModule", targets: ["HeapModule"]),
.library(name: "OrderedCollections", targets: ["OrderedCollections"]),
.library(name: "PersistentCollections", targets: ["PersistentCollections"]),
.library(name: "ShareableHashedCollections", targets: ["ShareableHashedCollections"]),
],
targets: [
.target(
@@ -62,7 +62,7 @@ let package = Package(
"DequeModule",
"HeapModule",
"OrderedCollections",
"PersistentCollections",
"ShareableHashedCollections",
],
exclude: ["CMakeLists.txt"],
swiftSettings: settings),
@@ -134,15 +134,15 @@ let package = Package(
dependencies: ["OrderedCollections", "_CollectionsTestSupport"],
swiftSettings: settings),
// PersistentSet<Element>, PersistentDictionary<Key, Value>
// ShareableSet<Element>, ShareableDictionary<Key, Value>
.target(
name: "PersistentCollections",
name: "ShareableHashedCollections",
dependencies: ["_CollectionsUtilities"],
exclude: ["CMakeLists.txt"],
swiftSettings: settings),
.testTarget(
name: "PersistentCollectionsTests",
dependencies: ["PersistentCollections", "_CollectionsTestSupport"],
name: "ShareableHashedCollectionsTests",
dependencies: ["ShareableHashedCollections", "_CollectionsTestSupport"],
swiftSettings: settings),
]
)
+4 -4
View File
@@ -20,7 +20,7 @@ The package currently provides the following implementations:
- [`OrderedDictionary<Key, Value>`][OrderedDictionary], an ordered variant of the standard `Dictionary`, providing similar benefits.
- [`PersistentSet`][PersistentSet] and [`PersistentDictionary`][PersistentDictionary], persistent hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). These work similar to the standard `Set` and `Dictionary`, but they excel at use cases that mutate shared copies, offering dramatic memory savings and radical time improvements.
- [`ShareableSet`][ShareableSet] and [`ShareableDictionary`][ShareableDictionary], persistent hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). These work similar to the standard `Set` and `Dictionary`, but they excel at use cases that mutate shared copies, offering dramatic memory savings and radical time improvements.
[BitSet]: Documentation/BitSet.md
[BitArray]: Documentation/BitArray.md
@@ -28,8 +28,8 @@ The package currently provides the following implementations:
[Heap]: Documentation/Heap.md
[OrderedSet]: Documentation/OrderedSet.md
[OrderedDictionary]: Documentation/OrderedDictionary.md
[PersistentSet]: Documentation/PersistentSet.md
[PersistentDictionary]: Documentation/PersistentDictionary.md
[ShareableSet]: Documentation/ShareableSet.md
[ShareableDictionary]: Documentation/ShareableDictionary.md
The following data structures are currently being worked on but they aren't ready for inclusion in a tagged release:
@@ -55,7 +55,7 @@ The Swift Collections package is source stable. The version numbers follow [Sema
[semver]: https://semver.org
The public API of version 1.1 of the `swift-collections` package consists of non-underscored declarations that are marked `public` in the `Collections`, `BitCollections`, `DequeModule`, `HeapModule`, `OrderedCollections` and `PersistentCollections` modules.
The public API of version 1.1 of the `swift-collections` package consists of non-underscored declarations that are marked `public` in the `Collections`, `BitCollections`, `DequeModule`, `HeapModule`, `OrderedCollections` and `ShareableHashedCollections` modules.
Interfaces that aren't part of the public API may continue to change in any release, including patch releases.
If you have a use case that requires using underscored APIs, please [submit a Feature Request][enhancement] describing it! We'd like the public interface to be as useful as possible -- although preferably without compromising safety or limiting future evolution.
+1 -1
View File
@@ -12,5 +12,5 @@ add_subdirectory(Collections)
add_subdirectory(DequeModule)
add_subdirectory(HeapModule)
add_subdirectory(OrderedCollections)
add_subdirectory(PersistentCollections)
add_subdirectory(ShareableHashedCollections)
add_subdirectory(_CollectionsUtilities)
+1 -1
View File
@@ -14,7 +14,7 @@ target_link_libraries(Collections PRIVATE
DequeModule
HeapModule
OrderedCollections
PersistentCollections
ShareableHashedCollections
)
set_target_properties(Collections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
@@ -34,5 +34,5 @@
### Persistent Collections
- ``PersistentSet``
- ``PersistentDictionary``
- ``ShareableSet``
- ``ShareableDictionary``
@@ -1,4 +1,4 @@
# ``Collections/PersistentDictionary``
# ``Collections/ShareableDictionary``
<!-- DO NOT EDIT THIS FILE; IT'S AUTOMATICALLY GENERATED -->
@@ -11,13 +11,13 @@
### Collection Views
`PersistentDictionary` provides the customary dictionary views, `keys` and
`ShareableDictionary` provides the customary dictionary views, `keys` and
`values`. These are collection types that are projections of the dictionary
itself, with elements that match only the keys or values of the dictionary,
respectively. The `Keys` view is notable in that it provides operations for
subtracting and intersecting the keys of two dictionaries, allowing for easy
detection of inserted and removed items between two snapshots of the same
dictionary. Because `PersistentDictionary` needs to invalidate indices on every
dictionary. Because `ShareableDictionary` needs to invalidate indices on every
mutation, its `Values` view is not a `MutableCollection`.
- ``Keys-swift.struct``
@@ -52,11 +52,11 @@ mutation, its `Values` view is not a `MutableCollection`.
### Adding or Updating Keys and Values
Beyond the standard `updateValue(_:forKey:)` method, `PersistentDictionary` also
Beyond the standard `updateValue(_:forKey:)` method, `ShareableDictionary` also
provides additional `updateValue` variants that take closure arguments. These
provide a more straightforward way to perform in-place mutations on dictionary
values (compared to mutating values through the corresponding subscript
operation.) `PersistentDictionary` also provides the standard `merge` and
operation.) `ShareableDictionary` also provides the standard `merge` and
`merging` operations for combining dictionary values.
- ``updateValue(_:forKey:)``
@@ -1,11 +1,11 @@
# ``Collections/PersistentSet``
# ``Collections/ShareableSet``
<!-- DO NOT EDIT THIS FILE; IT'S AUTOMATICALLY GENERATED -->
### Implementation Details
`PersistentSet` and `PersistentDictionary` are based on a Swift adaptation
`ShareableSet` and `ShareableDictionary` are based on a Swift adaptation
of the *Compressed Hash-Array Mapped Prefix Tree* (CHAMP) data structure.
- Michael J Steindorfer and Jurgen J Vinju. Optimizing Hash-Array Mapped
@@ -18,7 +18,7 @@ In this setup, the members of such a collection are organized into a tree
data structure based on their hash values. For example, assuming 16 bit hash
values sliced into 4-bit chunks, each node in the prefix tree would have
sixteen slots (one for each digit), each of which may contain a member, a
child node reference, or it may be empty. A `PersistentSet` containing the
child node reference, or it may be empty. A `ShareableSet` containing the
three items `Maximo`, `Julia` and `Don Pablo` (with hash values of `0x2B65`,
`0xA69F` and `0xADA1`, respectively) may be organized into a prefix tree of
two nodes:
@@ -65,7 +65,7 @@ share the same hash. Looking up a member in one of these nodes requires a
linear search, so it is crucial that such collisions do not happen often.
As long as `Element` properly implements `Hashable`, lookup operations in a
`PersistentSet` are expected to be able to decide whether the set contains a
`ShareableSet` are expected to be able to decide whether the set contains a
particular item by looking at no more than a constant number of items on
average -- typically they will need to compare against just one member.
@@ -98,7 +98,7 @@ average -- typically they will need to compare against just one member.
### Non-mutating Set Operations
To acknowledge the efficiency of `PersistentSet` at inserting and removing items
To acknowledge the efficiency of `ShareableSet` at inserting and removing items
from copies of a set, we provide a family of non-mutating primitives that
perform these operations. Instead of directly modifying the set they're given,
they return a brand new set with the desired result.
@@ -112,7 +112,7 @@ they return a brand new set with the desired result.
All the standard combining operations (intersection, union, subtraction and
symmetric difference) are supported, in both non-mutating and mutating forms.
`SetAlgebra` only requires the ability to combine one set instance with another,
but `PersistentSet` follows the tradition established by `Set` in providing
but `ShareableSet` follows the tradition established by `Set` in providing
additional overloads to each operation that allow combining a set with
additional types, including arbitrary sequences.
@@ -150,12 +150,13 @@ additional types, including arbitrary sequences.
### Comparing Sets
`PersistentSet` supports all standard set comparisons (subset tests, superset
`ShareableSet` supports all standard set comparisons (subset tests, superset
tests, disjunctness test), including the customary overloads established by
`Set`. As an additional extension, the `isEqualSet` family of member functions
generalize the standard `==` operation to support checking whether a
`PersistentSet` consists of exactly the same members as an arbitrary sequence,
ignoring element ordering and duplicates (if any).
`ShareableSet` consists of exactly the same members as an arbitrary sequence.
Like `==`, the `isEqualSet` functions ignore element ordering and duplicates (if
any).
- ``==(_:_:)``
- ``isEqualSet(to:)-7egih``
+1 -1
View File
@@ -13,4 +13,4 @@
@_exported import DequeModule
@_exported import HeapModule
@_exported import OrderedCollections
@_exported import PersistentCollections
@_exported import ShareableHashedCollections
@@ -1,105 +0,0 @@
#[[
This source file is part of the Swift Collections Open Source Project
Copyright (c) 2022 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]
add_library(PersistentCollections
"Node/_AncestorSlots.swift"
"Node/_Bitmap.swift"
"Node/_Bucket.swift"
"Node/_Hash.swift"
"Node/_HashTreeIterator.swift"
"Node/_HashTreeStatistics.swift"
"Node/_Level.swift"
"Node/_Node+Builder.swift"
"Node/_Node+Debugging.swift"
"Node/_Node+Initializers.swift"
"Node/_Node+Invariants.swift"
"Node/_Node+Lookups.swift"
"Node/_Node+Primitive Insertions.swift"
"Node/_Node+Primitive Removals.swift"
"Node/_Node+Primitive Replacement.swift"
"Node/_Node+Storage.swift"
"Node/_Node+Structural compactMapValues.swift"
"Node/_Node+Structural filter.swift"
"Node/_Node+Structural intersection.swift"
"Node/_Node+Structural isDisjoint.swift"
"Node/_Node+Structural isEqualSet.swift"
"Node/_Node+Structural isSubset.swift"
"Node/_Node+Structural mapValues.swift"
"Node/_Node+Structural merge.swift"
"Node/_Node+Structural subtracting.swift"
"Node/_Node+Structural symmetricDifference.swift"
"Node/_Node+Structural union.swift"
"Node/_Node+Subtree Insertions.swift"
"Node/_Node+Subtree Modify.swift"
"Node/_Node+Subtree Removals.swift"
"Node/_Node+UnsafeHandle.swift"
"Node/_Node.swift"
"Node/_RawNode+UnsafeHandle.swift"
"Node/_RawNode.swift"
"Node/_Slot.swift"
"Node/_Stack.swift"
"Node/_StorageHeader.swift"
"Node/_UnmanagedNode.swift"
"Node/_UnsafePath.swift"
"PersistentDictionary/PersistentDictionary+Codable.swift"
"PersistentDictionary/PersistentDictionary+Collection.swift"
"PersistentDictionary/PersistentDictionary+CustomReflectable.swift"
"PersistentDictionary/PersistentDictionary+Debugging.swift"
"PersistentDictionary/PersistentDictionary+Descriptions.swift"
"PersistentDictionary/PersistentDictionary+Equatable.swift"
"PersistentDictionary/PersistentDictionary+ExpressibleByDictionaryLiteral.swift"
"PersistentDictionary/PersistentDictionary+Filter.swift"
"PersistentDictionary/PersistentDictionary+Fluent Operations.swift"
"PersistentDictionary/PersistentDictionary+Hashable.swift"
"PersistentDictionary/PersistentDictionary+Initializers.swift"
"PersistentDictionary/PersistentDictionary+Keys.swift"
"PersistentDictionary/PersistentDictionary+MapValues.swift"
"PersistentDictionary/PersistentDictionary+Merge.swift"
"PersistentDictionary/PersistentDictionary+Sendable.swift"
"PersistentDictionary/PersistentDictionary+Sequence.swift"
"PersistentDictionary/PersistentDictionary+Values.swift"
"PersistentDictionary/PersistentDictionary.swift"
"PersistentSet/PersistentSet+Codable.swift"
"PersistentSet/PersistentSet+Collection.swift"
"PersistentSet/PersistentSet+CustomReflectable.swift"
"PersistentSet/PersistentSet+Debugging.swift"
"PersistentSet/PersistentSet+Descriptions.swift"
"PersistentSet/PersistentSet+Equatable.swift"
"PersistentSet/PersistentSet+ExpressibleByArrayLiteral.swift"
"PersistentSet/PersistentSet+Extras.swift"
"PersistentSet/PersistentSet+Filter.swift"
"PersistentSet/PersistentSet+Hashable.swift"
"PersistentSet/PersistentSet+Sendable.swift"
"PersistentSet/PersistentSet+Sequence.swift"
"PersistentSet/PersistentSet+SetAlgebra Initializers.swift"
"PersistentSet/PersistentSet+SetAlgebra basics.swift"
"PersistentSet/PersistentSet+SetAlgebra fluent basics.swift"
"PersistentSet/PersistentSet+SetAlgebra formIntersection.swift"
"PersistentSet/PersistentSet+SetAlgebra formSymmetricDifference.swift"
"PersistentSet/PersistentSet+SetAlgebra formUnion.swift"
"PersistentSet/PersistentSet+SetAlgebra intersection.swift"
"PersistentSet/PersistentSet+SetAlgebra isDisjoint.swift"
"PersistentSet/PersistentSet+SetAlgebra isEqualSet.swift"
"PersistentSet/PersistentSet+SetAlgebra isStrictSubset.swift"
"PersistentSet/PersistentSet+SetAlgebra isStrictSuperset.swift"
"PersistentSet/PersistentSet+SetAlgebra isSubset.swift"
"PersistentSet/PersistentSet+SetAlgebra isSuperset.swift"
"PersistentSet/PersistentSet+SetAlgebra subtract.swift"
"PersistentSet/PersistentSet+SetAlgebra subtracting.swift"
"PersistentSet/PersistentSet+SetAlgebra symmetricDifference.swift"
"PersistentSet/PersistentSet+SetAlgebra union.swift"
"PersistentSet/PersistentSet.swift"
)
target_link_libraries(PersistentCollections PRIVATE
_CollectionsUtilities)
set_target_properties(PersistentCollections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
_install_target(PersistentCollections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS PersistentCollections)
@@ -0,0 +1,105 @@
#[[
This source file is part of the Swift Collections Open Source Project
Copyright (c) 2022 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]
add_library(ShareableHashedCollections
"Node/_AncestorSlots.swift"
"Node/_Bitmap.swift"
"Node/_Bucket.swift"
"Node/_Hash.swift"
"Node/_HashTreeIterator.swift"
"Node/_HashTreeStatistics.swift"
"Node/_Level.swift"
"Node/_Node+Builder.swift"
"Node/_Node+Debugging.swift"
"Node/_Node+Initializers.swift"
"Node/_Node+Invariants.swift"
"Node/_Node+Lookups.swift"
"Node/_Node+Primitive Insertions.swift"
"Node/_Node+Primitive Removals.swift"
"Node/_Node+Primitive Replacement.swift"
"Node/_Node+Storage.swift"
"Node/_Node+Structural compactMapValues.swift"
"Node/_Node+Structural filter.swift"
"Node/_Node+Structural intersection.swift"
"Node/_Node+Structural isDisjoint.swift"
"Node/_Node+Structural isEqualSet.swift"
"Node/_Node+Structural isSubset.swift"
"Node/_Node+Structural mapValues.swift"
"Node/_Node+Structural merge.swift"
"Node/_Node+Structural subtracting.swift"
"Node/_Node+Structural symmetricDifference.swift"
"Node/_Node+Structural union.swift"
"Node/_Node+Subtree Insertions.swift"
"Node/_Node+Subtree Modify.swift"
"Node/_Node+Subtree Removals.swift"
"Node/_Node+UnsafeHandle.swift"
"Node/_Node.swift"
"Node/_RawNode+UnsafeHandle.swift"
"Node/_RawNode.swift"
"Node/_Slot.swift"
"Node/_Stack.swift"
"Node/_StorageHeader.swift"
"Node/_UnmanagedNode.swift"
"Node/_UnsafePath.swift"
"ShareableDictionary/ShareableDictionary+Codable.swift"
"ShareableDictionary/ShareableDictionary+Collection.swift"
"ShareableDictionary/ShareableDictionary+CustomReflectable.swift"
"ShareableDictionary/ShareableDictionary+Debugging.swift"
"ShareableDictionary/ShareableDictionary+Descriptions.swift"
"ShareableDictionary/ShareableDictionary+Equatable.swift"
"ShareableDictionary/ShareableDictionary+ExpressibleByDictionaryLiteral.swift"
"ShareableDictionary/ShareableDictionary+Filter.swift"
"ShareableDictionary/ShareableDictionary+Fluent Operations.swift"
"ShareableDictionary/ShareableDictionary+Hashable.swift"
"ShareableDictionary/ShareableDictionary+Initializers.swift"
"ShareableDictionary/ShareableDictionary+Keys.swift"
"ShareableDictionary/ShareableDictionary+MapValues.swift"
"ShareableDictionary/ShareableDictionary+Merge.swift"
"ShareableDictionary/ShareableDictionary+Sendable.swift"
"ShareableDictionary/ShareableDictionary+Sequence.swift"
"ShareableDictionary/ShareableDictionary+Values.swift"
"ShareableDictionary/ShareableDictionary.swift"
"ShareableSet/ShareableSet+Codable.swift"
"ShareableSet/ShareableSet+Collection.swift"
"ShareableSet/ShareableSet+CustomReflectable.swift"
"ShareableSet/ShareableSet+Debugging.swift"
"ShareableSet/ShareableSet+Descriptions.swift"
"ShareableSet/ShareableSet+Equatable.swift"
"ShareableSet/ShareableSet+ExpressibleByArrayLiteral.swift"
"ShareableSet/ShareableSet+Extras.swift"
"ShareableSet/ShareableSet+Filter.swift"
"ShareableSet/ShareableSet+Hashable.swift"
"ShareableSet/ShareableSet+Sendable.swift"
"ShareableSet/ShareableSet+Sequence.swift"
"ShareableSet/ShareableSet+SetAlgebra Initializers.swift"
"ShareableSet/ShareableSet+SetAlgebra basics.swift"
"ShareableSet/ShareableSet+SetAlgebra fluent basics.swift"
"ShareableSet/ShareableSet+SetAlgebra formIntersection.swift"
"ShareableSet/ShareableSet+SetAlgebra formSymmetricDifference.swift"
"ShareableSet/ShareableSet+SetAlgebra formUnion.swift"
"ShareableSet/ShareableSet+SetAlgebra intersection.swift"
"ShareableSet/ShareableSet+SetAlgebra isDisjoint.swift"
"ShareableSet/ShareableSet+SetAlgebra isEqualSet.swift"
"ShareableSet/ShareableSet+SetAlgebra isStrictSubset.swift"
"ShareableSet/ShareableSet+SetAlgebra isStrictSuperset.swift"
"ShareableSet/ShareableSet+SetAlgebra isSubset.swift"
"ShareableSet/ShareableSet+SetAlgebra isSuperset.swift"
"ShareableSet/ShareableSet+SetAlgebra subtract.swift"
"ShareableSet/ShareableSet+SetAlgebra subtracting.swift"
"ShareableSet/ShareableSet+SetAlgebra symmetricDifference.swift"
"ShareableSet/ShareableSet+SetAlgebra union.swift"
"ShareableSet/ShareableSet.swift"
)
target_link_libraries(ShareableHashedCollections PRIVATE
_CollectionsUtilities)
set_target_properties(ShareableHashedCollections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
_install_target(ShareableHashedCollections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS ShareableHashedCollections)
@@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//
/// A fixed-size array of just enough size to hold an ancestor path in a
/// `PersistentDictionary`.
/// `ShareableDictionary`.
@usableFromInline
@frozen
internal struct _Stack<Element> {
@@ -11,7 +11,7 @@
// Code in this file is a slightly adapted variant of `Dictionary`'s `Codable`
// implementation in the Standard Library as of Swift 5.7.
// `PersistentDictionary` therefore encodes/decodes itself exactly the same as
// `ShareableDictionary` therefore encodes/decodes itself exactly the same as
// `Dictionary`, and the two types can each decode data encoded by the other.
/// A wrapper for dictionary keys which are Strings or Ints.
@@ -35,7 +35,7 @@ internal struct _DictionaryCodingKey: CodingKey {
}
}
extension PersistentDictionary: Encodable
extension ShareableDictionary: Encodable
where Key: Encodable, Value: Encodable
{
/// Encodes the elements of this dictionary into the given encoder.
@@ -85,7 +85,7 @@ where Key: Encodable, Value: Encodable
}
}
extension PersistentDictionary: Decodable
extension ShareableDictionary: Decodable
where Key: Decodable, Value: Decodable
{
/// Creates a new dictionary by decoding from the given decoder.
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary {
extension ShareableDictionary {
/// The position of an element in a persistent dictionary.
///
/// An index in a persistent dictionary is a compact encoding of a path in
@@ -39,11 +39,11 @@ extension PersistentDictionary {
}
#if swift(>=5.5)
extension PersistentDictionary.Index: @unchecked Sendable
extension ShareableDictionary.Index: @unchecked Sendable
where Key: Sendable, Value: Sendable {}
#endif
extension PersistentDictionary.Index: Equatable {
extension ShareableDictionary.Index: Equatable {
/// Returns a Boolean value indicating whether two index values are equal.
///
/// Note that comparing two indices that do not belong to the same tree
@@ -59,7 +59,7 @@ extension PersistentDictionary.Index: Equatable {
}
}
extension PersistentDictionary.Index: Comparable {
extension ShareableDictionary.Index: Comparable {
/// Returns a Boolean value indicating whether the value of the first argument
/// is less than the second argument.
///
@@ -75,7 +75,7 @@ extension PersistentDictionary.Index: Comparable {
}
}
extension PersistentDictionary.Index: Hashable {
extension ShareableDictionary.Index: Hashable {
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
@@ -86,21 +86,21 @@ extension PersistentDictionary.Index: Hashable {
}
}
extension PersistentDictionary.Index: CustomStringConvertible {
extension ShareableDictionary.Index: CustomStringConvertible {
// A textual representation of this instance.
public var description: String {
_path.description
}
}
extension PersistentDictionary.Index: CustomDebugStringConvertible {
extension ShareableDictionary.Index: CustomDebugStringConvertible {
/// A textual representation of this instance, suitable for debugging.
public var debugDescription: String {
_path.description
}
}
extension PersistentDictionary: Collection {
extension ShareableDictionary: Collection {
/// A Boolean value indicating whether the collection is empty.
///
/// - Complexity: O(1)
@@ -198,7 +198,7 @@ extension PersistentDictionary: Collection {
/// - Parameter start: A valid index of the collection.
/// - Parameter end: Another valid index of the collection.
/// - Returns: The distance between `start` and `end`.
/// (The result can be negative, even though `PersistentDictionary` is not
/// (The result can be negative, even though `ShareableDictionary` is not
/// a bidirectional collection.)
/// - Complexity: O(log(`count`))
@inlinable
@@ -216,7 +216,7 @@ extension PersistentDictionary: Collection {
/// - i: A valid index of the collection.
/// - distance: The distance to offset `i`. As a special exception,
/// `distance` is allowed to be negative even though
/// `PersistentDictionary` isn't a bidirectional collection.
/// `ShareableDictionary` isn't a bidirectional collection.
/// - Returns: An index offset by `distance` from the index `i`. If
/// `distance` is positive, this is the same value as the result of
/// `distance` calls to `index(after:)`. If distance is negative, then
@@ -244,7 +244,7 @@ extension PersistentDictionary: Collection {
/// - i: A valid index of the collection.
/// - distance: The distance to offset `i`. As a special exception,
/// `distance` is allowed to be negative even though
/// `PersistentDictionary` isn't a bidirectional collection.
/// `ShareableDictionary` isn't a bidirectional collection.
/// - limit: A valid index of the collection to use as a limit. If
/// `distance > 0`, a limit that is less than `i` has no effect.
/// Likewise, if `distance < 0`, a limit that is greater than `i` has no
@@ -273,8 +273,8 @@ extension PersistentDictionary: Collection {
#if false
// Note: Let's not do this. `BidirectionalCollection` would imply that
// the ordering of elements would be meaningful, which isn't true for
// `PersistentDictionary`.
extension PersistentDictionary: BidirectionalCollection {
// `ShareableDictionary`.
extension ShareableDictionary: BidirectionalCollection {
/// Replaces the given index with its predecessor.
///
/// - Parameter i: A valid index of the collection.
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary: CustomReflectable {
extension ShareableDictionary: CustomReflectable {
/// The custom mirror for this instance.
public var customMirror: Mirror {
Mirror(self, unlabeledChildren: self, displayStyle: .dictionary)
@@ -11,7 +11,7 @@
import _CollectionsUtilities
extension PersistentDictionary {
extension ShareableDictionary {
/// True if consistency checking is enabled in the implementation of this
/// type, false otherwise.
///
@@ -11,14 +11,14 @@
import _CollectionsUtilities
extension PersistentDictionary: CustomStringConvertible {
extension ShareableDictionary: CustomStringConvertible {
// A textual representation of this instance.
public var description: String {
_dictionaryDescription(for: self)
}
}
extension PersistentDictionary: CustomDebugStringConvertible {
extension ShareableDictionary: CustomDebugStringConvertible {
/// A textual representation of this instance, suitable for debugging.
public var debugDescription: String {
_dictionaryDescription(
@@ -26,6 +26,6 @@ extension PersistentDictionary: CustomDebugStringConvertible {
}
internal static func _debugTypeName() -> String {
"PersistentDictionary<\(Key.self), \(Value.self)>"
"ShareableDictionary<\(Key.self), \(Value.self)>"
}
}
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary: Equatable where Value: Equatable {
extension ShareableDictionary: Equatable where Value: Equatable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Two persistent dictionaries are considered equal if they contain the same
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary: ExpressibleByDictionaryLiteral {
extension ShareableDictionary: ExpressibleByDictionaryLiteral {
/// Creates a new dictionary from the contents of a dictionary literal.
///
/// The literal must not contain duplicate elements.
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary {
extension ShareableDictionary {
/// Returns a new persistent dictionary containing the key-value pairs of this
/// dictionary that satisfy the given predicate.
///
@@ -26,6 +26,6 @@ extension PersistentDictionary {
) rethrows -> Self {
let result = try _root.filter(.top, isIncluded)
guard let result = result else { return self }
return PersistentDictionary(_new: result.finalize(.top))
return ShareableDictionary(_new: result.finalize(.top))
}
}
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary {
extension ShareableDictionary {
/// Return a new dictionary that has the specified key-value pair in addition
/// to all existing elements in this dictionary.
///
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary: Hashable where Value: Hashable {
extension ShareableDictionary: Hashable where Value: Hashable {
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary {
extension ShareableDictionary {
/// Creates an empty dictionary.
///
/// This initializer is equivalent to initializing with an empty dictionary
@@ -25,7 +25,7 @@ extension PersistentDictionary {
///
/// - Complexity: O(1)
@inlinable
public init(_ other: PersistentDictionary<Key, Value>) {
public init(_ other: ShareableDictionary<Key, Value>) {
self = other
}
@@ -45,7 +45,7 @@ extension PersistentDictionary {
/// - Complexity: O(`other.count`)
@inlinable
public init(
keys: PersistentSet<Key>,
keys: ShareableSet<Key>,
valueGenerator valueTransform: (Key) throws -> Value
) rethrows {
// FIXME: This is a non-standard addition
@@ -144,12 +144,12 @@ extension PersistentDictionary {
///
/// let pairsWithDuplicateKeys = [("a", 1), ("b", 2), ("a", 3), ("b", 4)]
///
/// let firstValues = PersistentDictionary(
/// let firstValues = ShareableDictionary(
/// pairsWithDuplicateKeys,
/// uniquingKeysWith: { (first, _) in first })
/// // ["a": 1, "b": 2]
///
/// let lastValues = PersistentDictionary(
/// let lastValues = ShareableDictionary(
/// pairsWithDuplicateKeys,
/// uniquingKeysWith: { (_, last) in last })
/// // ["a": 3, "b": 4]
@@ -183,12 +183,12 @@ extension PersistentDictionary {
///
/// let pairsWithDuplicateKeys = [("a", 1), ("b", 2), ("a", 3), ("b", 4)]
///
/// let firstValues = PersistentDictionary(
/// let firstValues = ShareableDictionary(
/// pairsWithDuplicateKeys,
/// uniquingKeysWith: { (first, _) in first })
/// // ["a": 1, "b": 2]
///
/// let lastValues = PersistentDictionary(
/// let lastValues = ShareableDictionary(
/// pairsWithDuplicateKeys,
/// uniquingKeysWith: { (_, last) in last })
/// // ["a": 3, "b": 4]
@@ -212,7 +212,7 @@ extension PersistentDictionary {
}
}
extension PersistentDictionary {
extension ShareableDictionary {
/// Creates a new dictionary whose keys are the groupings returned by the
/// given closure and whose values are arrays of the elements that returned
/// each key.
@@ -225,7 +225,7 @@ extension PersistentDictionary {
/// dictionary from that array by grouping the names by first letter:
///
/// let students = ["Kofi", "Abena", "Efua", "Kweku", "Akosua"]
/// let studentsByLetter = PersistentDictionary(grouping: students, by: { $0.first! })
/// let studentsByLetter = ShareableDictionary(grouping: students, by: { $0.first! })
/// // ["K": ["Kofi", "Kweku"], "A": ["Abena", "Akosua"], "E": ["Efua"]]
///
/// The new `studentsByLetter` dictionary has three entries, with students'
@@ -260,7 +260,7 @@ extension PersistentDictionary {
/// dictionary from that array by grouping the names by first letter:
///
/// let students = ["Kofi", "Abena", "Efua", "Kweku", "Akosua"]
/// let studentsByLetter = PersistentDictionary(grouping: students, by: { $0.first! })
/// let studentsByLetter = ShareableDictionary(grouping: students, by: { $0.first! })
/// // ["K": ["Kofi", "Kweku"], "A": ["Abena", "Akosua"], "E": ["Efua"]]
///
/// The new `studentsByLetter` dictionary has three entries, with students'
@@ -11,18 +11,18 @@
import _CollectionsUtilities
extension PersistentDictionary {
extension ShareableDictionary {
/// A view of a persistent dictionary’s keys, as a standalone collection.
@frozen
public struct Keys {
@usableFromInline
internal typealias _Node = PersistentCollections._Node<Key, Value>
internal typealias _Node = ShareableHashedCollections._Node<Key, Value>
@usableFromInline
internal var _base: PersistentDictionary
internal var _base: ShareableDictionary
@inlinable
internal init(_base: PersistentDictionary) {
internal init(_base: ShareableDictionary) {
self._base = _base
}
}
@@ -37,30 +37,30 @@ extension PersistentDictionary {
}
#if swift(>=5.5)
extension PersistentDictionary.Keys: Sendable
extension ShareableDictionary.Keys: Sendable
where Key: Sendable, Value: Sendable {}
#endif
extension PersistentDictionary.Keys: _UniqueCollection {}
extension ShareableDictionary.Keys: _UniqueCollection {}
extension PersistentDictionary.Keys: CustomStringConvertible {
extension ShareableDictionary.Keys: CustomStringConvertible {
// A textual representation of this instance.
public var description: String {
_arrayDescription(for: self)
}
}
extension PersistentDictionary.Keys: CustomDebugStringConvertible {
extension ShareableDictionary.Keys: CustomDebugStringConvertible {
/// A textual representation of this instance, suitable for debugging.
public var debugDescription: String {
_arrayDescription(
for: self,
debug: true,
typeName: "\(PersistentDictionary._debugTypeName()).Keys")
typeName: "\(ShareableDictionary._debugTypeName()).Keys")
}
}
extension PersistentDictionary.Keys: Sequence {
extension ShareableDictionary.Keys: Sequence {
/// The element type of the collection.
public typealias Element = Key
@@ -71,10 +71,10 @@ extension PersistentDictionary.Keys: Sequence {
public typealias Element = Key
@usableFromInline
internal var _base: PersistentDictionary.Iterator
internal var _base: ShareableDictionary.Iterator
@inlinable
internal init(_base: PersistentDictionary.Iterator) {
internal init(_base: ShareableDictionary.Iterator) {
self._base = _base
}
@@ -113,12 +113,12 @@ extension PersistentDictionary.Keys: Sequence {
}
#if swift(>=5.5)
extension PersistentDictionary.Keys.Iterator: Sendable
extension ShareableDictionary.Keys.Iterator: Sendable
where Key: Sendable, Value: Sendable {}
#endif
extension PersistentDictionary.Keys: Collection {
public typealias Index = PersistentDictionary.Index
extension ShareableDictionary.Keys: Collection {
public typealias Index = ShareableDictionary.Index
@inlinable
public var isEmpty: Bool { _base.isEmpty }
@@ -166,10 +166,10 @@ extension PersistentDictionary.Keys: Collection {
}
#if false
extension PersistentDictionary.Keys: BidirectionalCollection {
extension ShareableDictionary.Keys: BidirectionalCollection {
// Note: Let's not do this. `BidirectionalCollection` would imply that
// the ordering of elements would be meaningful, which isn't true for
// `PersistentDictionary.Keys`.
// `ShareableDictionary.Keys`.
@inlinable
public func formIndex(before i: inout Index) {
_base.formIndex(before: &i)
@@ -182,12 +182,12 @@ extension PersistentDictionary.Keys: BidirectionalCollection {
}
#endif
extension PersistentDictionary.Keys {
extension ShareableDictionary.Keys {
/// Returns a new keys view with the elements that are common to both this
/// view and the provided other one.
///
/// var a: PersistentDictionary = ["a": 1, "b": 2, "c": 3]
/// let b: PersistentDictionary = ["b": 4, "d": 5, "e": 6]
/// var a: ShareableDictionary = ["a": 1, "b": 2, "c": 3]
/// let b: ShareableDictionary = ["b": 4, "d": 5, "e": 6]
/// let c = a.keys.intersection(b.keys)
/// // `c` is `["b"]`
///
@@ -204,19 +204,19 @@ extension PersistentDictionary.Keys {
/// hash tree structure to minimize work when possible, e.g. by linking
/// parts of the input trees directly into the result.
public func intersection<Value2>(
_ other: PersistentDictionary<Key, Value2>.Keys
_ other: ShareableDictionary<Key, Value2>.Keys
) -> Self {
guard let r = _base._root.intersection(.top, other._base._root) else {
return self
}
return PersistentDictionary(_new: r).keys
return ShareableDictionary(_new: r).keys
}
/// Returns a new keys view with the elements that are common to both this
/// view and the provided persistent set.
///
/// var a: PersistentDictionary = ["a": 1, "b": 2, "c": 3]
/// let b: PersistentSet = ["b", "d", "e"]
/// var a: ShareableDictionary = ["a": 1, "b": 2, "c": 3]
/// let b: ShareableSet = ["b", "d", "e"]
/// let c = a.keys.intersection(b)
/// // `c` is `["b"]`
///
@@ -231,18 +231,18 @@ extension PersistentDictionary.Keys {
/// However, the implementation is careful to make the best use of
/// hash tree structure to minimize work when possible, e.g. by linking
/// parts of the input trees directly into the result.
public func intersection(_ other: PersistentSet<Key>) -> Self {
public func intersection(_ other: ShareableSet<Key>) -> Self {
guard let r = _base._root.intersection(.top, other._root) else {
return self
}
return PersistentDictionary(_new: r).keys
return ShareableDictionary(_new: r).keys
}
/// Returns a new keys view containing the elements of `self` that do not
/// occur in the provided other one.
///
/// var a: PersistentDictionary = ["a": 1, "b": 2, "c": 3]
/// let b: PersistentDictionary = ["b": 4, "d": 5, "e": 6]
/// var a: ShareableDictionary = ["a": 1, "b": 2, "c": 3]
/// let b: ShareableDictionary = ["b": 4, "d": 5, "e": 6]
/// let c = a.keys.subtracting(b.keys)
/// // `c` is some permutation of `["a", "c"]`
///
@@ -255,19 +255,19 @@ extension PersistentDictionary.Keys {
/// hash tree structure to minimize work when possible, e.g. by linking
/// parts of the input trees directly into the result.
public func subtracting<Value2>(
_ other: PersistentDictionary<Key, Value2>.Keys
_ other: ShareableDictionary<Key, Value2>.Keys
) -> Self {
guard let r = _base._root.subtracting(.top, other._base._root) else {
return self
}
return PersistentDictionary(_new: r).keys
return ShareableDictionary(_new: r).keys
}
/// Returns a new keys view containing the elements of `self` that do not
/// occur in the provided persistent set.
///
/// var a: PersistentDictionary = ["a": 1, "b": 2, "c": 3]
/// let b: PersistentSet = ["b", "d", "e"]
/// var a: ShareableDictionary = ["a": 1, "b": 2, "c": 3]
/// let b: ShareableSet = ["b", "d", "e"]
/// let c = a.keys.subtracting(b)
/// // `c` is some permutation of `["a", "c"]`
///
@@ -278,10 +278,10 @@ extension PersistentDictionary.Keys {
/// However, the implementation is careful to make the best use of
/// hash tree structure to minimize work when possible, e.g. by linking
/// parts of the input trees directly into the result.
public func subtracting(_ other: PersistentSet<Key>) -> Self {
public func subtracting(_ other: ShareableSet<Key>) -> Self {
guard let r = _base._root.subtracting(.top, other._root) else {
return self
}
return PersistentDictionary(_new: r).keys
return ShareableDictionary(_new: r).keys
}
}
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary {
extension ShareableDictionary {
/// Returns a new dictionary containing the keys of this dictionary with the
/// values transformed by the given closure.
///
@@ -23,9 +23,9 @@ extension PersistentDictionary {
@inlinable
public func mapValues<T>(
_ transform: (Value) throws -> T
) rethrows -> PersistentDictionary<Key, T> {
) rethrows -> ShareableDictionary<Key, T> {
let transformed = try _root.mapValues { try transform($0.value) }
return PersistentDictionary<Key, T>(_new: transformed)
return ShareableDictionary<Key, T>(_new: transformed)
}
/// Returns a new dictionary containing only the key-value pairs that have
@@ -38,7 +38,7 @@ extension PersistentDictionary {
/// and `compactMapValues` with a transformation that returns an optional
/// `Int` value.
///
/// let data: PersistentDictionary = ["a": "1", "b": "three", "c": "///4///"]
/// let data: ShareableDictionary = ["a": "1", "b": "three", "c": "///4///"]
///
/// let m: [String: Int?] = data.mapValues { str in Int(str) }
/// // ["a": Optional(1), "b": nil, "c": nil]
@@ -57,8 +57,8 @@ extension PersistentDictionary {
@inlinable
public func compactMapValues<T>(
_ transform: (Value) throws -> T?
) rethrows -> PersistentDictionary<Key, T> {
) rethrows -> ShareableDictionary<Key, T> {
let result = try _root.compactMapValues(.top, transform)
return PersistentDictionary<Key, T>(_new: result.finalize(.top))
return ShareableDictionary<Key, T>(_new: result.finalize(.top))
}
}
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary {
extension ShareableDictionary {
/// Merges the key-value pairs in the given sequence into the dictionary,
/// using a combining closure to determine the value for any duplicate keys.
///
@@ -22,7 +22,7 @@ extension PersistentDictionary {
/// This example shows how to choose the current or new values for any
/// duplicate keys:
///
/// var dictionary: PersistentDictionary = ["a": 1, "b": 2]
/// var dictionary: ShareableDictionary = ["a": 1, "b": 2]
///
/// // Keeping existing value for key "a":
/// dictionary.merge(zip(["a", "c"], [3, 4])) { (current, _) in current }
@@ -58,7 +58,7 @@ extension PersistentDictionary {
/// This example shows how to choose the current or new values for any
/// duplicate keys:
///
/// var dictionary: PersistentDictionary = ["a": 1, "b": 2]
/// var dictionary: ShareableDictionary = ["a": 1, "b": 2]
///
/// // Keeping existing value for key "a":
/// dictionary.merge(zip(["a", "c"], [3, 4])) { (current, _) in current }
@@ -101,7 +101,7 @@ extension PersistentDictionary {
/// This example shows how to choose the current or new values for any
/// duplicate keys:
///
/// var dictionary: PersistentDictionary = ["a": 1, "b": 2]
/// var dictionary: ShareableDictionary = ["a": 1, "b": 2]
///
/// // Keeping existing value for key "a":
/// dictionary.merge(zip(["a", "c"], [3, 4])) { (current, _) in current }
@@ -10,6 +10,6 @@
//===----------------------------------------------------------------------===//
#if swift(>=5.5)
extension PersistentDictionary: @unchecked Sendable
extension ShareableDictionary: @unchecked Sendable
where Key: Sendable, Value: Sendable {}
#endif
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentDictionary: Sequence {
extension ShareableDictionary: Sequence {
/// The element type of a dictionary: a tuple containing an individual
/// key-value pair.
public typealias Element = (key: Key, value: Value)
@@ -52,11 +52,11 @@ extension PersistentDictionary: Sequence {
}
#if swift(>=5.5)
extension PersistentDictionary.Iterator: @unchecked Sendable
extension ShareableDictionary.Iterator: @unchecked Sendable
where Key: Sendable, Value: Sendable {}
#endif
extension PersistentDictionary.Iterator: IteratorProtocol {
extension ShareableDictionary.Iterator: IteratorProtocol {
/// The element type of a dictionary: a tuple containing an individual
/// key-value pair.
public typealias Element = (key: Key, value: Value)
@@ -11,21 +11,21 @@
import _CollectionsUtilities
extension PersistentDictionary {
extension ShareableDictionary {
/// A view of a dictionary’s values.
@frozen
public struct Values {
@usableFromInline
internal typealias _Node = PersistentCollections._Node<Key, Value>
internal typealias _Node = ShareableHashedCollections._Node<Key, Value>
@usableFromInline
internal typealias _UnsafeHandle = _Node.UnsafeHandle
@usableFromInline
internal var _base: PersistentDictionary
internal var _base: ShareableDictionary
@inlinable
internal init(_base: PersistentDictionary) {
internal init(_base: ShareableDictionary) {
self._base = _base
}
}
@@ -42,28 +42,28 @@ extension PersistentDictionary {
}
#if swift(>=5.5)
extension PersistentDictionary.Values: Sendable
extension ShareableDictionary.Values: Sendable
where Key: Sendable, Value: Sendable {}
#endif
extension PersistentDictionary.Values: CustomStringConvertible {
extension ShareableDictionary.Values: CustomStringConvertible {
// A textual representation of this instance.
public var description: String {
_arrayDescription(for: self)
}
}
extension PersistentDictionary.Values: CustomDebugStringConvertible {
extension ShareableDictionary.Values: CustomDebugStringConvertible {
/// A textual representation of this instance, suitable for debugging.
public var debugDescription: String {
_arrayDescription(
for: self,
debug: true,
typeName: "\(PersistentDictionary._debugTypeName()).Values")
typeName: "\(ShareableDictionary._debugTypeName()).Values")
}
}
extension PersistentDictionary.Values: Sequence {
extension ShareableDictionary.Values: Sequence {
public typealias Element = Value
@frozen
@@ -71,10 +71,10 @@ extension PersistentDictionary.Values: Sequence {
public typealias Element = Value
@usableFromInline
internal var _base: PersistentDictionary.Iterator
internal var _base: ShareableDictionary.Iterator
@inlinable
internal init(_base: PersistentDictionary.Iterator) {
internal init(_base: ShareableDictionary.Iterator) {
self._base = _base
}
@@ -91,14 +91,14 @@ extension PersistentDictionary.Values: Sequence {
}
#if swift(>=5.5)
extension PersistentDictionary.Values.Iterator: Sendable
extension ShareableDictionary.Values.Iterator: Sendable
where Key: Sendable, Value: Sendable {}
#endif
// Note: This cannot be a MutableCollection because its subscript setter
// needs to invalidate indices.
extension PersistentDictionary.Values: Collection {
public typealias Index = PersistentDictionary.Index
extension ShareableDictionary.Values: Collection {
public typealias Index = ShareableDictionary.Index
@inlinable
public var isEmpty: Bool { _base.isEmpty }
@@ -152,10 +152,10 @@ extension PersistentDictionary.Values: Collection {
}
#if false
extension PersistentDictionary.Values: BidirectionalCollection {
extension ShareableDictionary.Values: BidirectionalCollection {
// Note: Let's not do this. `BidirectionalCollection` would imply that
// the ordering of elements would be meaningful, which isn't true for
// `PersistentDictionary.Values`.
// `ShareableDictionary.Values`.
@inlinable
public func formIndex(before i: inout Index) {
_base.formIndex(before: &i)
@@ -13,13 +13,13 @@
/// mutating shared copies and comparing different snapshots of the same
/// collection.
///
/// `PersistentDictionary` has the same functionality as a standard
/// `ShareableDictionary` has the same functionality as a standard
/// `Dictionary`, and it largely implements the same APIs: both are hashed
/// collection types with convenient and efficient ways to look up the value
/// associated with a particular key, and both types are unordered, meaning that
/// neither type provides any guarantees about the ordering of their items.
///
/// However, `PersistentDictionary` is optimizing specifically for use cases
/// However, `ShareableDictionary` is optimizing specifically for use cases
/// that need to mutate shared copies or to compare a dictionary value to one of
/// its older snapshots.
///
@@ -27,10 +27,10 @@
/// and it implements value semantics with all-or-nothing copy-on-write
/// behavior: every time a shared copy of a dictionary is mutated, the mutation
/// needs to make a full copy of the dictionary's storage.
/// `PersistentDictionary` takes a different approach: it organizes its members
/// `ShareableDictionary` takes a different approach: it organizes its members
/// into a tree structure, the nodes of which can be freely shared across
/// collection values. When mutating a shared copy of a dictionary value,
/// `PersistentDictionary` is able to simply link the unchanged parts of the
/// `ShareableDictionary` is able to simply link the unchanged parts of the
/// tree directly into the result, saving both time and memory.
///
/// This structural sharing also makes it more efficient to compare mutated
@@ -39,7 +39,7 @@
/// typically be handled in constant time, leading to a dramatic performance
/// boost when the two inputs are still largely unchanged:
///
/// var d = PersistentDictionary(
/// var d = ShareableDictionary(
/// uniqueKeysWithValues: (0 ..< 10_000).map { ($0, 2 * $0) })
/// let copy = d
/// d[20_000] = 42 // Expected to be an O(log(n)) operation
@@ -47,7 +47,7 @@
/// // `diff` now holds the single item 20_000.
///
/// The tree structure also eliminates the need to reserve capacity in advance:
/// `PersistentDictionary` creates, destroys and resizes individual nodes as
/// `ShareableDictionary` creates, destroys and resizes individual nodes as
/// needed, always consuming just enough memory to store its contents. As of
/// Swift 5.7, the standard collection types never shrink their storage, so
/// temporary storage spikes can linger as unused but still allocated memory
@@ -55,16 +55,16 @@
///
/// Of course, switching to a tree structure comes with some trade offs. In
/// particular, inserting new items, removing existing ones, and iterating over
/// a `PersistentDictionary` is expected to be a constant factor slower than a
/// a `ShareableDictionary` is expected to be a constant factor slower than a
/// standard `Dictionary` -- allocating/deallocating nodes isn't free, and
/// navigating the tree structure requires more pointer dereferences than
/// accessing a flat hash table. However the algorithmic improvements above
/// usually more than make up for this, as long as the use case can make use of
/// them.
@frozen // Not really -- this package is not at all ABI stable
public struct PersistentDictionary<Key: Hashable, Value> {
public struct ShareableDictionary<Key: Hashable, Value> {
@usableFromInline
internal typealias _Node = PersistentCollections._Node<Key, Value>
internal typealias _Node = ShareableHashedCollections._Node<Key, Value>
@usableFromInline
internal typealias _UnsafeHandle = _Node.UnsafeHandle
@@ -90,7 +90,7 @@ public struct PersistentDictionary<Key: Hashable, Value> {
}
}
extension PersistentDictionary {
extension ShareableDictionary {
/// Accesses the value associated with the given key for reading and writing.
///
/// This *key-based* subscript returns the value for the given key if the key
@@ -100,7 +100,7 @@ extension PersistentDictionary {
/// key found in the dictionary (`"Coral"`) and a key not found in the
/// dictionary (`"Cerise"`).
///
/// var hues: PersistentDictionary = ["Heliotrope": 296, "Coral": 16, "Aquamarine": 156]
/// var hues: ShareableDictionary = ["Heliotrope": 296, "Coral": 16, "Aquamarine": 156]
/// print(hues["Coral"])
/// // Prints "Optional(16)"
/// print(hues["Cerise"])
@@ -186,7 +186,7 @@ extension PersistentDictionary {
/// example uses the subscript with a message to use in case an HTTP response
/// code isn't recognized:
///
/// var responseMessages: PersistentDictionary = [
/// var responseMessages: ShareableDictionary = [
/// 200: "OK",
/// 403: "Access forbidden",
/// 404: "File not found",
@@ -207,7 +207,7 @@ extension PersistentDictionary {
/// of each letter in a string:
///
/// let message = "Hello, Elle!"
/// var letterCounts: PersistentDictionary<Character, Int> = [:]
/// var letterCounts: ShareableDictionary<Character, Int> = [:]
/// for letter in message {
/// letterCounts[letter, default: 0] += 1
/// }
@@ -298,7 +298,7 @@ extension PersistentDictionary {
/// value of an existing key is updated, `updateValue(_:forKey:)` returns
/// the original value.
///
/// var hues: PersistentDictionary = [
/// var hues: ShareableDictionary = [
/// "Heliotrope": 296,
/// "Coral": 16,
/// "Aquamarine": 156]
@@ -383,7 +383,7 @@ extension PersistentDictionary {
/// in a string:
///
/// let message = "Hello, Elle!"
/// var letterCounts: PersistentDictionary<Character, Int> = [:]
/// var letterCounts: ShareableDictionary<Character, Int> = [:]
/// for letter in message {
/// letterCounts.updateValue(forKey: letter) { count in
/// if count == nil {
@@ -434,7 +434,7 @@ extension PersistentDictionary {
/// in a string:
///
/// let message = "Hello, Elle!"
/// var letterCounts: PersistentDictionary<Character, Int> = [:]
/// var letterCounts: ShareableDictionary<Character, Int> = [:]
/// for letter in message {
/// letterCounts.updateValue(forKey: letter, default: 0) { count in
/// count += 1
@@ -483,7 +483,7 @@ extension PersistentDictionary {
/// If the key is found in the dictionary, this method returns the key's
/// associated value, and invalidates all previously returned indices.
///
/// var hues: PersistentDictionary = [
/// var hues: ShareableDictionary = [
/// "Heliotrope": 296,
/// "Coral": 16,
/// "Aquamarine": 156]
@@ -1,4 +1,4 @@
# ``PersistentCollections/PersistentDictionary``
# ``ShareableHashedCollections/ShareableDictionary``
<!-- Summary -->
@@ -8,13 +8,13 @@
### Collection Views
`PersistentDictionary` provides the customary dictionary views, `keys` and
`ShareableDictionary` provides the customary dictionary views, `keys` and
`values`. These are collection types that are projections of the dictionary
itself, with elements that match only the keys or values of the dictionary,
respectively. The `Keys` view is notable in that it provides operations for
subtracting and intersecting the keys of two dictionaries, allowing for easy
detection of inserted and removed items between two snapshots of the same
dictionary. Because `PersistentDictionary` needs to invalidate indices on every
dictionary. Because `ShareableDictionary` needs to invalidate indices on every
mutation, its `Values` view is not a `MutableCollection`.
- ``Keys-swift.struct``
@@ -49,11 +49,11 @@ mutation, its `Values` view is not a `MutableCollection`.
### Adding or Updating Keys and Values
Beyond the standard `updateValue(_:forKey:)` method, `PersistentDictionary` also
Beyond the standard `updateValue(_:forKey:)` method, `ShareableDictionary` also
provides additional `updateValue` variants that take closure arguments. These
provide a more straightforward way to perform in-place mutations on dictionary
values (compared to mutating values through the corresponding subscript
operation.) `PersistentDictionary` also provides the standard `merge` and
operation.) `ShareableDictionary` also provides the standard `merge` and
`merging` operations for combining dictionary values.
- ``updateValue(_:forKey:)``
@@ -1,8 +1,8 @@
# ``PersistentCollections/PersistentSet``
# ``ShareableHashedCollections/ShareableSet``
### Implementation Details
`PersistentSet` and `PersistentDictionary` are based on a Swift adaptation
`ShareableSet` and `ShareableDictionary` are based on a Swift adaptation
of the *Compressed Hash-Array Mapped Prefix Tree* (CHAMP) data structure.
- Michael J Steindorfer and Jurgen J Vinju. Optimizing Hash-Array Mapped
@@ -15,7 +15,7 @@ In this setup, the members of such a collection are organized into a tree
data structure based on their hash values. For example, assuming 16 bit hash
values sliced into 4-bit chunks, each node in the prefix tree would have
sixteen slots (one for each digit), each of which may contain a member, a
child node reference, or it may be empty. A `PersistentSet` containing the
child node reference, or it may be empty. A `ShareableSet` containing the
three items `Maximo`, `Julia` and `Don Pablo` (with hash values of `0x2B65`,
`0xA69F` and `0xADA1`, respectively) may be organized into a prefix tree of
two nodes:
@@ -62,7 +62,7 @@ share the same hash. Looking up a member in one of these nodes requires a
linear search, so it is crucial that such collisions do not happen often.
As long as `Element` properly implements `Hashable`, lookup operations in a
`PersistentSet` are expected to be able to decide whether the set contains a
`ShareableSet` are expected to be able to decide whether the set contains a
particular item by looking at no more than a constant number of items on
average -- typically they will need to compare against just one member.
@@ -95,7 +95,7 @@ average -- typically they will need to compare against just one member.
### Non-mutating Set Operations
To acknowledge the efficiency of `PersistentSet` at inserting and removing items
To acknowledge the efficiency of `ShareableSet` at inserting and removing items
from copies of a set, we provide a family of non-mutating primitives that
perform these operations. Instead of directly modifying the set they're given,
they return a brand new set with the desired result.
@@ -109,7 +109,7 @@ they return a brand new set with the desired result.
All the standard combining operations (intersection, union, subtraction and
symmetric difference) are supported, in both non-mutating and mutating forms.
`SetAlgebra` only requires the ability to combine one set instance with another,
but `PersistentSet` follows the tradition established by `Set` in providing
but `ShareableSet` follows the tradition established by `Set` in providing
additional overloads to each operation that allow combining a set with
additional types, including arbitrary sequences.
@@ -147,11 +147,11 @@ additional types, including arbitrary sequences.
### Comparing Sets
`PersistentSet` supports all standard set comparisons (subset tests, superset
`ShareableSet` supports all standard set comparisons (subset tests, superset
tests, disjunctness test), including the customary overloads established by
`Set`. As an additional extension, the `isEqualSet` family of member functions
generalize the standard `==` operation to support checking whether a
`PersistentSet` consists of exactly the same members as an arbitrary sequence.
`ShareableSet` consists of exactly the same members as an arbitrary sequence.
Like `==`, the `isEqualSet` functions ignore element ordering and duplicates (if
any).
@@ -1,4 +1,4 @@
# ``PersistentCollections``
# ``ShareableHashedCollections``
**Swift Collections** is an open-source package of data structure implementations for the Swift programming language.
@@ -16,5 +16,5 @@
### Persistent Collections
- ``PersistentSet``
- ``PersistentDictionary``
- ``ShareableSet``
- ``ShareableDictionary``
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet: Encodable where Element: Encodable {
extension ShareableSet: Encodable where Element: Encodable {
/// Encodes the elements of this set into the given encoder.
///
/// - Parameter encoder: The encoder to write data to.
@@ -20,7 +20,7 @@ extension PersistentSet: Encodable where Element: Encodable {
}
}
extension PersistentSet: Decodable where Element: Decodable {
extension ShareableSet: Decodable where Element: Decodable {
/// Creates a new set by decoding from the given decoder.
///
/// This initializer throws an error if reading from the decoder fails, or
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet {
extension ShareableSet {
/// The position of an element in a persistent set.
///
/// An index in a persistent set is a compact encoding of a path in the
@@ -39,11 +39,11 @@ extension PersistentSet {
}
#if swift(>=5.5)
extension PersistentSet.Index: @unchecked Sendable
extension ShareableSet.Index: @unchecked Sendable
where Element: Sendable {}
#endif
extension PersistentSet.Index: Equatable {
extension ShareableSet.Index: Equatable {
/// Returns a Boolean value indicating whether two index values are equal.
///
/// Note that comparing two indices that do not belong to the same tree
@@ -59,7 +59,7 @@ extension PersistentSet.Index: Equatable {
}
}
extension PersistentSet.Index: Comparable {
extension ShareableSet.Index: Comparable {
/// Returns a Boolean value indicating whether the value of the first argument
/// is less than the second argument.
///
@@ -76,7 +76,7 @@ extension PersistentSet.Index: Comparable {
}
}
extension PersistentSet.Index: Hashable {
extension ShareableSet.Index: Hashable {
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
@@ -87,21 +87,21 @@ extension PersistentSet.Index: Hashable {
}
}
extension PersistentSet.Index: CustomStringConvertible {
extension ShareableSet.Index: CustomStringConvertible {
// A textual representation of this instance.
public var description: String {
_path.description
}
}
extension PersistentSet.Index: CustomDebugStringConvertible {
extension ShareableSet.Index: CustomDebugStringConvertible {
/// A textual representation of this instance, suitable for debugging.
public var debugDescription: String {
description
}
}
extension PersistentSet: Collection {
extension ShareableSet: Collection {
/// A Boolean value indicating whether the collection is empty.
///
/// - Complexity: O(1)
@@ -198,7 +198,7 @@ extension PersistentSet: Collection {
/// - Parameter start: A valid index of the collection.
/// - Parameter end: Another valid index of the collection.
/// - Returns: The distance between `start` and `end`.
/// (The result can be negative, even though `PersistentSet` is not a
/// (The result can be negative, even though `ShareableSet` is not a
/// bidirectional collection.)
/// - Complexity: O(log(`count`))
@inlinable
@@ -215,7 +215,7 @@ extension PersistentSet: Collection {
/// - Parameters:
/// - i: A valid index of the collection.
/// - distance: The distance to offset `i`. As a special exception,
/// `distance` is allowed to be negative even though `PersistentSet`
/// `distance` is allowed to be negative even though `ShareableSet`
/// isn't a bidirectional collection.
/// - Returns: An index offset by `distance` from the index `i`. If
/// `distance` is positive, this is the same value as the result of
@@ -243,7 +243,7 @@ extension PersistentSet: Collection {
/// - Parameters:
/// - i: A valid index of the collection.
/// - distance: The distance to offset `i`. As a special exception,
/// `distance` is allowed to be negative even though `PersistentSet`
/// `distance` is allowed to be negative even though `ShareableSet`
/// isn't a bidirectional collection.
/// - limit: A valid index of the collection to use as a limit. If
/// `distance > 0`, a limit that is less than `i` has no effect.
@@ -340,8 +340,8 @@ extension PersistentSet: Collection {
#if false
// Note: Let's not do this. `BidirectionalCollection` would imply that
// the ordering of elements would be meaningful, which isn't true for
// `PersistentSet`.
extension PersistentSet: BidirectionalCollection {
// `ShareableSet`.
extension ShareableSet: BidirectionalCollection {
/// Replaces the given index with its predecessor.
///
/// - Parameter i: A valid index of the collection.
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet: CustomReflectable {
extension ShareableSet: CustomReflectable {
/// The custom mirror for this instance.
public var customMirror: Mirror {
Mirror(self, unlabeledChildren: self, displayStyle: .set)
@@ -11,7 +11,7 @@
import _CollectionsUtilities
extension PersistentSet {
extension ShareableSet {
/// True if consistency checking is enabled in the implementation of this
/// type, false otherwise.
///
@@ -11,14 +11,14 @@
import _CollectionsUtilities
extension PersistentSet: CustomStringConvertible {
extension ShareableSet: CustomStringConvertible {
/// A textual representation of this instance.
public var description: String {
_arrayDescription(for: self)
}
}
extension PersistentSet: CustomDebugStringConvertible {
extension ShareableSet: CustomDebugStringConvertible {
/// A textual representation of this instance, suitable for debugging.
public var debugDescription: String {
_arrayDescription(
@@ -26,6 +26,6 @@ extension PersistentSet: CustomDebugStringConvertible {
}
internal func _debugTypeName() -> String {
"PersistentSet<\(Element.self)>"
"ShareableSet<\(Element.self)>"
}
}
@@ -11,7 +11,7 @@
import _CollectionsUtilities
extension PersistentSet: Equatable {
extension ShareableSet: Equatable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Two persistent sets are considered equal if they contain the same
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet: ExpressibleByArrayLiteral {
extension ShareableSet: ExpressibleByArrayLiteral {
/// Creates a new set from the contents of an array literal.
///
/// Duplicate elements in the literal are allowed, but the resulting
@@ -11,9 +11,9 @@
import _CollectionsUtilities
extension PersistentSet: _UniqueCollection {}
extension ShareableSet: _UniqueCollection {}
extension PersistentSet {
extension ShareableSet {
/// Removes the element at the given valid index.
///
/// Calling this method invalidates all existing indices of the collection.
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet {
extension ShareableSet {
/// Returns a new persistent set containing all the members of this persistent
/// set that satisfy the given predicate.
///
@@ -26,7 +26,7 @@ extension PersistentSet {
) rethrows -> Self {
let result = try _root.filter(.top) { try isIncluded($0.key) }
guard let result = result else { return self }
return PersistentSet(_new: result.finalize(.top))
return ShareableSet(_new: result.finalize(.top))
}
/// Removes all the elements that satisfy the given predicate.
@@ -36,7 +36,7 @@ extension PersistentSet {
/// This example removes all the odd values from an
/// set of numbers:
///
/// var numbers: PersistentSet = [5, 6, 7, 8, 9, 10, 11]
/// var numbers: ShareableSet = [5, 6, 7, 8, 9, 10, 11]
/// numbers.removeAll(where: { $0 % 2 != 0 })
/// // numbers == [6, 8, 10], in some order
///
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet: Hashable {
extension ShareableSet: Hashable {
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
@@ -10,5 +10,5 @@
//===----------------------------------------------------------------------===//
#if swift(>=5.5)
extension PersistentSet: @unchecked Sendable where Element: Sendable {}
extension ShareableSet: @unchecked Sendable where Element: Sendable {}
#endif
@@ -9,8 +9,8 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet: Sequence {
/// An iterator over the members of a `PersistentSet`.
extension ShareableSet: Sequence {
/// An iterator over the members of a `ShareableSet`.
@frozen
public struct Iterator: IteratorProtocol {
@usableFromInline
@@ -50,6 +50,6 @@ extension PersistentSet: Sequence {
}
#if swift(>=5.5)
extension PersistentSet.Iterator: @unchecked Sendable
extension ShareableSet.Iterator: @unchecked Sendable
where Element: Sendable {}
#endif
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet {
extension ShareableSet {
/// Creates an empty set.
///
/// This initializer is equivalent to initializing with an empty array
@@ -62,7 +62,7 @@ extension PersistentSet {
/// - Complexity: O(*items.count*)
@inlinable
public init<Value>(
_ item: __owned PersistentDictionary<Element, Value>.Keys
_ item: __owned ShareableDictionary<Element, Value>.Keys
) {
self.init(_new: item._base._root.mapValues { _ in () })
}
@@ -11,7 +11,7 @@
import _CollectionsUtilities
extension PersistentSet: SetAlgebra {
extension ShareableSet: SetAlgebra {
/// Returns a Boolean value that indicates whether the given element exists
/// in the set.
///
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet {
extension ShareableSet {
/// Return a new set that contains `newMember` in addition to all existing
/// elements in this set.
///
@@ -28,7 +28,7 @@ extension PersistentSet {
public func inserting(_ newMember: __owned Element) -> Self {
let hash = _Hash(newMember)
let r = _root.inserting(.top, (newMember, ()), hash)
return PersistentSet(_new: r.node)
return ShareableSet(_new: r.node)
}
/// Return a new set that contains all members of this set except `member`.
@@ -49,7 +49,7 @@ extension PersistentSet {
let r = _root.removing(.top, member, hash)
guard let r = r else { return self }
let root = r.replacement.finalize(.top)
return PersistentSet(_new: root)
return ShareableSet(_new: root)
}
/// Return a new set that contains `newMember` in addition to all members of
@@ -9,11 +9,11 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet {
extension ShareableSet {
/// Removes the elements of this set that aren't also in the given one.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [0, 2, 4, 6]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [0, 2, 4, 6]
/// a.formIntersection(b)
/// // `a` is now some permutation of `[2, 4]`
///
@@ -50,7 +50,7 @@ extension PersistentSet {
/// parts of the input trees directly into the result.
@inlinable
public mutating func formIntersection<Value>(
_ other: PersistentDictionary<Element, Value>.Keys
_ other: ShareableDictionary<Element, Value>.Keys
) {
// FIXME: Implement in-place reductions
self = intersection(other)
@@ -58,7 +58,7 @@ extension PersistentSet {
/// Removes the elements of this set that aren't also in the given sequence.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b = [0, 2, 4, 6]
/// a.formIntersection(b)
/// // `a` is now some permutation of `[2, 4]`
@@ -9,12 +9,12 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet {
extension ShareableSet {
/// Replace this set with the elements contained in this set or the given
/// set, but not both.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [0, 2, 4, 6]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [0, 2, 4, 6]
/// a.formSymmetricDifference(b)
/// // `a` is now some permutation of `[0, 1, 3, 6]`
///
@@ -33,8 +33,8 @@ extension PersistentSet {
/// Replace this set with the elements contained in this set or the given
/// keys view of a persistent dictionary, but not both.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
/// a.formSymmetricDifference(b.keys)
/// // `a` is now some permutation of `[0, 1, 3, 6]`
///
@@ -47,7 +47,7 @@ extension PersistentSet {
/// parts of the input trees directly into the result.
@inlinable
public mutating func formSymmetricDifference<Value>(
_ other: __owned PersistentDictionary<Element, Value>.Keys
_ other: __owned ShareableDictionary<Element, Value>.Keys
) {
self = symmetricDifference(other)
}
@@ -55,7 +55,7 @@ extension PersistentSet {
/// Replace this set with the elements contained in this set or the given
/// sequence, but not both.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b = [0, 2, 4, 6, 2, 4, 6]
/// a.formSymmetricDifference(b)
/// // `a` is now some permutation of `[0, 1, 3, 6]`
@@ -9,11 +9,11 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet {
extension ShareableSet {
/// Adds the elements of the given set to this set.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [0, 2, 4, 6]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [0, 2, 4, 6]
/// a.formUnion(b)
/// // `a` is now some permutation of `[0, 1, 2, 3, 4, 6]`
///
@@ -37,8 +37,8 @@ extension PersistentSet {
/// Adds the elements of the given keys view of a persistent dictionary
/// to this set.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
/// a.formUnion(b.keys)
/// // `a` is now some permutation of `[0, 1, 2, 3, 4, 6]`
///
@@ -56,14 +56,14 @@ extension PersistentSet {
/// parts of the input trees directly into the result.
@inlinable
public mutating func formUnion<Value>(
_ other: __owned PersistentDictionary<Element, Value>.Keys
_ other: __owned ShareableDictionary<Element, Value>.Keys
) {
self = union(other)
}
/// Adds the elements of the given sequence to this set.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b = [0, 2, 4, 6, 0, 2]
/// a.formUnion(b)
/// // `a` is now some permutation of `[0, 1, 2, 3, 4, 6]`
@@ -9,12 +9,12 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet {
extension ShareableSet {
/// Returns a new set with the elements that are common to both this set and
/// the provided other one.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [0, 2, 4, 6]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [0, 2, 4, 6]
/// let c = a.intersection(b)
/// // `c` is some permutation of `[2, 4]`
///
@@ -37,8 +37,8 @@ extension PersistentSet {
/// Returns a new set with the elements that are common to both this set and
/// the provided keys view of a persistent dictionary.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
/// let c = a.intersection(b.keys)
/// // `c` is some permutation of `[2, 4]`
///
@@ -55,14 +55,14 @@ extension PersistentSet {
/// parts of the input trees directly into the result.
@inlinable @inline(__always)
public func intersection<Value>(
_ other: PersistentDictionary<Element, Value>.Keys
_ other: ShareableDictionary<Element, Value>.Keys
) -> Self {
_intersection(other._base._root)
}
@inlinable
internal func _intersection<V>(
_ other: PersistentCollections._Node<Element, V>
_ other: ShareableHashedCollections._Node<Element, V>
) -> Self {
guard let r = _root.intersection(.top, other) else { return self }
return Self(_new: r)
@@ -71,7 +71,7 @@ extension PersistentSet {
/// Returns a new set with the elements that are common to both this set and
/// the provided sequence.
///
/// var a: PersistentSet = [1, 2, 3, 4]
/// var a: ShareableSet = [1, 2, 3, 4]
/// let b = [0, 2, 4, 6]
/// let c = a.intersection(b)
/// // `c` is some permutation of `[2, 4]`
@@ -9,12 +9,12 @@
//
//===----------------------------------------------------------------------===//
extension PersistentSet {
extension ShareableSet {
/// Returns a Boolean value that indicates whether the set has no members in
/// common with the given set.
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [5, 6]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [5, 6]
/// a.isDisjoint(with: b) // true
///
/// - Parameter other: Another set.
@@ -32,8 +32,8 @@ extension PersistentSet {
/// Returns a Boolean value that indicates whether the set has no members in
/// common with the given set.
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [5, 6]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [5, 6]
/// a.isDisjoint(with: b) // true
///
/// - Parameter other: The keys view of a persistent dictionary.
@@ -45,7 +45,7 @@ extension PersistentSet {
/// average, if `Element` implements high-quality hashing.
@inlinable
public func isDisjoint<Value>(
with other: PersistentDictionary<Element, Value>.Keys
with other: ShareableDictionary<Element, Value>.Keys
) -> Bool {
self._root.isDisjoint(.top, with: other._base._root)
}
@@ -53,8 +53,8 @@ extension PersistentSet {
/// Returns a Boolean value that indicates whether the set has no members in
/// common with the given set.
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [5, 6]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [5, 6]
/// a.isDisjoint(with: b) // true
///
/// - Parameter other: A finite sequence of elements, some of which may
@@ -12,7 +12,7 @@
import _CollectionsUtilities
// FIXME: These are non-standard extensions generalizing ==.
extension PersistentSet {
extension ShareableSet {
/// Returns a Boolean value indicating whether persistent sets are equal. Two
/// persistent sets are considered equal if they contain the same elements,
/// but not necessarily in the same order.
@@ -46,7 +46,7 @@ extension PersistentSet {
/// comparing elements in shared subtrees.
@inlinable
public func isEqualSet<Value>(
to other: PersistentDictionary<Element, Value>.Keys
to other: ShareableDictionary<Element, Value>.Keys
) -> Bool {
_root.isEqualSet(to: other._base._root, by: { _, _ in true })
}
@@ -58,7 +58,7 @@ extension PersistentSet {
/// Duplicate items in `other` do not prevent it from comparing equal to
/// `self`.
///
/// let this: PersistentSet = [0, 1, 5, 6]
/// let this: ShareableSet = [0, 1, 5, 6]
/// let that = [5, 5, 0, 1, 1, 6, 5, 0, 1, 6, 6, 5]
///
/// this.isEqualSet(to: that) // true
@@ -11,7 +11,7 @@
import _CollectionsUtilities
extension PersistentSet {
extension ShareableSet {
/// Returns a Boolean value that indicates whether the set is a strict subset
/// of the given set.
///
@@ -19,8 +19,8 @@ extension PersistentSet {
/// also a member of *B* and *B* contains at least one element that is not a
/// member of *A*. (Ignoring the order the elements appear in the sets.)
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [4, 2, 1]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [4, 2, 1]
/// b.isStrictSubset(of: a) // true
///
/// - Parameter other: Another set.
@@ -45,8 +45,8 @@ extension PersistentSet {
/// also a member of *B* and *B* contains at least one element that is not a
/// member of *A*. (Ignoring the order the elements appear in the sets.)
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [4, 2, 1]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [4, 2, 1]
/// b.isStrictSubset(of: a) // true
///
/// - Parameter other: The keys view of a persistent dictionary.
@@ -60,7 +60,7 @@ extension PersistentSet {
/// e.g. by skipping over parts of the input trees.
@inlinable
public func isStrictSubset<Value>(
of other: PersistentDictionary<Element, Value>.Keys
of other: ShareableDictionary<Element, Value>.Keys
) -> Bool {
guard self.count < other.count else { return false }
return isSubset(of: other)
@@ -73,8 +73,8 @@ extension PersistentSet {
/// also a member of *B* and *B* contains at least one element that is not a
/// member of *A*. (Ignoring the order the elements appear in the sets.)
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [4, 2, 1]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [4, 2, 1]
/// b.isStrictSubset(of: a) // true
///
/// - Parameter other: A sequence of elements, some of whose elements may
@@ -11,7 +11,7 @@
import _CollectionsUtilities
extension PersistentSet {
extension ShareableSet {
/// Returns a Boolean value that indicates whether the set is a strict
/// superset of the given set.
///
@@ -19,8 +19,8 @@ extension PersistentSet {
/// also a member of *A* and *A* contains at least one element that is *not*
/// a member of *B*. (Ignoring the order the elements appear in the sets.)
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [4, 2, 1]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [4, 2, 1]
/// a.isStrictSuperset(of: b.unordered) // true
///
/// - Parameter other: Another set.
@@ -45,8 +45,8 @@ extension PersistentSet {
/// also a member of *B* and *B* contains at least one element that is not a
/// member of *A*. (Ignoring the order the elements appear in the sets.)
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [4, 2, 1]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [4, 2, 1]
/// a.isStrictSuperset(of: b.unordered) // true
///
/// - Parameter other: The keys view of a persistent dictionary.
@@ -60,7 +60,7 @@ extension PersistentSet {
/// e.g. by skipping over parts of the input trees.
@inlinable
public func isStrictSuperset<Value>(
of other: PersistentDictionary<Element, Value>.Keys
of other: ShareableDictionary<Element, Value>.Keys
) -> Bool {
guard self.count > other.count else { return false }
return other._base._root.isSubset(.top, of: self._root)
@@ -73,8 +73,8 @@ extension PersistentSet {
/// also a member of *B* and *B* contains at least one element that is not a
/// member of *A*. (Ignoring the order the elements appear in the sets.)
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [4, 2, 1]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [4, 2, 1]
/// a.isStrictSuperset(of: b.unordered) // true
///
/// - Parameter other: A sequence of elements, some of whose elements may
@@ -11,15 +11,15 @@
import _CollectionsUtilities
extension PersistentSet {
extension ShareableSet {
/// Returns a Boolean value that indicates whether this set is a subset of
/// the given set.
///
/// Set *A* is a subset of another set *B* if every member of *A* is also a
/// member of *B*, ignoring the order they appear in the two sets.
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [4, 2, 1]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [4, 2, 1]
/// b.isSubset(of: a) // true
///
/// - Parameter other: Another set.
@@ -41,8 +41,8 @@ extension PersistentSet {
/// Set *A* is a subset of another set *B* if every member of *A* is also a
/// member of *B*, ignoring the order they appear in the two sets.
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [4, 2, 1]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [4, 2, 1]
/// b.isSubset(of: a) // true
///
/// - Parameter other: The keys view of a persistent dictionary.
@@ -55,7 +55,7 @@ extension PersistentSet {
/// e.g. by skipping over parts of the input trees.
@inlinable
public func isSubset<Value>(
of other: PersistentDictionary<Element, Value>.Keys
of other: ShareableDictionary<Element, Value>.Keys
) -> Bool {
self._root.isSubset(.top, of: other._base._root)
}
@@ -66,8 +66,8 @@ extension PersistentSet {
/// Set *A* is a subset of another set *B* if every member of *A* is also a
/// member of *B*, ignoring the order they appear in the two sets.
///
/// let a: PersistentSet = [1, 2, 3, 4]
/// let b: PersistentSet = [4, 2, 1]
/// let a: ShareableSet = [1, 2, 3, 4]
/// let b: ShareableSet = [4, 2, 1]
/// b.isSubset(of: a) // true
///
/// - Parameter other: A sequence of elements, some of whose elements may
Loaded 100 of 120 files, more files were not shown because too many files have changed in this diff. Show more