diff --git a/Benchmarks/Libraries/PersistentSet.json b/Benchmarks/Libraries/PersistentSet.json deleted file mode 100644 index 7adf2aab..00000000 --- a/Benchmarks/Libraries/PersistentSet.json +++ /dev/null @@ -1,754 +0,0 @@ -{ - "kind": "group", - "title": "PersistentSet Benchmarks", - "directory": "Results", - "contents": [ - { - "kind": "chart", - "title": "operations", - "tasks": [ - "PersistentSet init from range", - "PersistentSet init from unsafe buffer", - "PersistentSet sequential iteration", - "PersistentSet successful contains", - "PersistentSet unsuccessful contains", - "PersistentSet insert", - "PersistentSet remove" - ] - }, - { - "kind": "chart", - "title": "initializers", - "tasks": [ - "PersistentSet init from range", - "PersistentSet init from unsafe buffer", - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "union with Self", - "tasks": [ - "PersistentSet union with Self (0% overlap)", - "PersistentSet union with Self (25% overlap)", - "PersistentSet union with Self (50% overlap)", - "PersistentSet union with Self (75% overlap)", - "PersistentSet union with Self (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "union with Array", - "tasks": [ - "PersistentSet union with Array (0% overlap)", - "PersistentSet union with Array (25% overlap)", - "PersistentSet union with Array (50% overlap)", - "PersistentSet union with Array (75% overlap)", - "PersistentSet union with Array (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "formUnion with Self", - "tasks": [ - "PersistentSet formUnion with Self (0% overlap)", - "PersistentSet formUnion with Self (25% overlap)", - "PersistentSet formUnion with Self (50% overlap)", - "PersistentSet formUnion with Self (75% overlap)", - "PersistentSet formUnion with Self (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "formUnion with Array", - "tasks": [ - "PersistentSet formUnion with Array (0% overlap)", - "PersistentSet formUnion with Array (25% overlap)", - "PersistentSet formUnion with Array (50% overlap)", - "PersistentSet formUnion with Array (75% overlap)", - "PersistentSet formUnion with Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "intersection with Self", - "tasks": [ - "PersistentSet intersection with Self (0% overlap)", - "PersistentSet intersection with Self (25% overlap)", - "PersistentSet intersection with Self (50% overlap)", - "PersistentSet intersection with Self (75% overlap)", - "PersistentSet intersection with Self (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "intersection with Array", - "tasks": [ - "PersistentSet intersection with Array (0% overlap)", - "PersistentSet intersection with Array (25% overlap)", - "PersistentSet intersection with Array (50% overlap)", - "PersistentSet intersection with Array (75% overlap)", - "PersistentSet intersection with Array (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "formIntersection with Self", - "tasks": [ - "PersistentSet formIntersection with Self (0% overlap)", - "PersistentSet formIntersection with Self (25% overlap)", - "PersistentSet formIntersection with Self (50% overlap)", - "PersistentSet formIntersection with Self (75% overlap)", - "PersistentSet formIntersection with Self (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "formIntersection with Array", - "tasks": [ - "PersistentSet formIntersection with Array (0% overlap)", - "PersistentSet formIntersection with Array (25% overlap)", - "PersistentSet formIntersection with Array (50% overlap)", - "PersistentSet formIntersection with Array (75% overlap)", - "PersistentSet formIntersection with Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "symmetricDifference with Self", - "tasks": [ - "PersistentSet symmetricDifference with Self (0% overlap)", - "PersistentSet symmetricDifference with Self (25% overlap)", - "PersistentSet symmetricDifference with Self (50% overlap)", - "PersistentSet symmetricDifference with Self (75% overlap)", - "PersistentSet symmetricDifference with Self (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "symmetricDifference with Array", - "tasks": [ - "PersistentSet symmetricDifference with Array (0% overlap)", - "PersistentSet symmetricDifference with Array (25% overlap)", - "PersistentSet symmetricDifference with Array (50% overlap)", - "PersistentSet symmetricDifference with Array (75% overlap)", - "PersistentSet symmetricDifference with Array (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "formSymmetricDifference with Self", - "tasks": [ - "PersistentSet formSymmetricDifference with Self (0% overlap)", - "PersistentSet formSymmetricDifference with Self (25% overlap)", - "PersistentSet formSymmetricDifference with Self (50% overlap)", - "PersistentSet formSymmetricDifference with Self (75% overlap)", - "PersistentSet formSymmetricDifference with Self (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "formSymmetricDifference with Array", - "tasks": [ - "PersistentSet formSymmetricDifference with Array (0% overlap)", - "PersistentSet formSymmetricDifference with Array (25% overlap)", - "PersistentSet formSymmetricDifference with Array (50% overlap)", - "PersistentSet formSymmetricDifference with Array (75% overlap)", - "PersistentSet formSymmetricDifference with Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "subtracting Self", - "tasks": [ - "PersistentSet subtracting Self (0% overlap)", - "PersistentSet subtracting Self (25% overlap)", - "PersistentSet subtracting Self (50% overlap)", - "PersistentSet subtracting Self (75% overlap)", - "PersistentSet subtracting Self (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtracting Array", - "tasks": [ - "PersistentSet subtracting Array (0% overlap)", - "PersistentSet subtracting Array (25% overlap)", - "PersistentSet subtracting Array (50% overlap)", - "PersistentSet subtracting Array (75% overlap)", - "PersistentSet subtracting Array (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtract Self", - "tasks": [ - "PersistentSet subtract Self (0% overlap)", - "PersistentSet subtract Self (25% overlap)", - "PersistentSet subtract Self (50% overlap)", - "PersistentSet subtract Self (75% overlap)", - "PersistentSet subtract Self (100% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtract with Array", - "tasks": [ - "PersistentSet subtract Array (0% overlap)", - "PersistentSet subtract Array (25% overlap)", - "PersistentSet subtract Array (50% overlap)", - "PersistentSet subtract Array (75% overlap)", - "PersistentSet subtract Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "group", - "title": "Reference comparisons", - "directory": "versus", - "contents": [ - { - "kind": "chart", - "title": "init from buffer of integers", - "tasks": [ - "PersistentSet init from unsafe buffer", - "Set init from unsafe buffer", - ] - }, - { - "kind": "chart", - "title": "init from range of integers", - "tasks": [ - "PersistentSet init from range", - "Set init from range", - ] - }, - { - "kind": "chart", - "title": "sequential iteration", - "tasks": [ - "PersistentSet sequential iteration", - "Set sequential iteration", - ] - }, - { - "kind": "chart", - "title": "sequential iteration using indices", - "tasks": [ - "PersistentSet sequential iteration, indices", - "Set sequential iteration, indices", - ] - }, - { - "kind": "chart", - "title": "successful random lookups", - "tasks": [ - "PersistentSet successful contains", - "Set successful contains", - ] - }, - { - "kind": "chart", - "title": "unsuccessful random lookups", - "tasks": [ - "PersistentSet unsuccessful contains", - "Set unsuccessful contains", - ] - }, - { - "kind": "chart", - "title": "insert", - "tasks": [ - "PersistentSet insert", - "Set insert", - "Set insert, reserving capacity", - ] - }, - { - "kind": "chart", - "title": "insert-shared", - "tasks": [ - "PersistentSet insert, shared", - "Set insert, shared", - ] - }, - { - "kind": "chart", - "title": "diffing", - "tasks": [ - "PersistentSet insert one + subtract, shared", - "Set insert one + subtract, shared", - ] - }, - { - "kind": "chart", - "title": "remove", - "tasks": [ - "PersistentSet remove", - "PersistentSet remove, shared", - "Set remove", - "Set remove, shared", - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "union (0% overlap)", - "tasks": [ - "OrderedSet union with Self (0% overlap)", - "OrderedSet union with Array (0% overlap)", - "Set union with Self (0% overlap)", - "Set union with Array (0% overlap)", - ] - }, - { - "kind": "chart", - "title": "union (25% overlap)", - "tasks": [ - "OrderedSet union with Self (25% overlap)", - "OrderedSet union with Array (25% overlap)", - "Set union with Self (25% overlap)", - "Set union with Array (25% overlap)", - ] - }, - { - "kind": "chart", - "title": "union (50% overlap)", - "tasks": [ - "OrderedSet union with Self (50% overlap)", - "OrderedSet union with Array (50% overlap)", - "Set union with Self (50% overlap)", - "Set union with Array (50% overlap)", - ] - }, - { - "kind": "chart", - "title": "union (75% overlap)", - "tasks": [ - "OrderedSet union with Self (75% overlap)", - "OrderedSet union with Array (75% overlap)", - "Set union with Self (75% overlap)", - "Set union with Array (75% overlap)", - ] - }, - { - "kind": "chart", - "title": "union (100% overlap)", - "tasks": [ - "OrderedSet union with Self (100% overlap)", - "OrderedSet union with Array (100% overlap)", - "Set union with Self (100% overlap)", - "Set union with Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "formUnion (0% overlap)", - "tasks": [ - "OrderedSet formUnion with Self (0% overlap)", - "OrderedSet formUnion with Array (0% overlap)", - "Set formUnion with Self (0% overlap)", - "Set formUnion with Array (0% overlap)", - ] - }, - { - "kind": "chart", - "title": "formUnion (25% overlap)", - "tasks": [ - "OrderedSet formUnion with Self (25% overlap)", - "OrderedSet formUnion with Array (25% overlap)", - "Set formUnion with Self (25% overlap)", - "Set formUnion with Array (25% overlap)", - ] - }, - { - "kind": "chart", - "title": "formUnion (50% overlap)", - "tasks": [ - "OrderedSet formUnion with Self (50% overlap)", - "OrderedSet formUnion with Array (50% overlap)", - "Set formUnion with Self (50% overlap)", - "Set formUnion with Array (50% overlap)", - ] - }, - { - "kind": "chart", - "title": "formUnion (75% overlap)", - "tasks": [ - "OrderedSet formUnion with Self (75% overlap)", - "OrderedSet formUnion with Array (75% overlap)", - "Set formUnion with Self (75% overlap)", - "Set formUnion with Array (75% overlap)", - ] - }, - { - "kind": "chart", - "title": "formUnion (100% overlap)", - "tasks": [ - "OrderedSet formUnion with Self (100% overlap)", - "OrderedSet formUnion with Array (100% overlap)", - "Set formUnion with Self (100% overlap)", - "Set formUnion with Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "intersection (0% overlap)", - "tasks": [ - "OrderedSet intersection with Self (0% overlap)", - "OrderedSet intersection with Array (0% overlap)", - "Set intersection with Self (0% overlap)", - "Set intersection with Array (0% overlap)", - ] - }, - { - "kind": "chart", - "title": "intersection (25% overlap)", - "tasks": [ - "OrderedSet intersection with Self (25% overlap)", - "OrderedSet intersection with Array (25% overlap)", - "Set intersection with Self (25% overlap)", - "Set intersection with Array (25% overlap)", - ] - }, - { - "kind": "chart", - "title": "intersection (50% overlap)", - "tasks": [ - "OrderedSet intersection with Self (50% overlap)", - "OrderedSet intersection with Array (50% overlap)", - "Set intersection with Self (50% overlap)", - "Set intersection with Array (50% overlap)", - ] - }, - { - "kind": "chart", - "title": "intersection (75% overlap)", - "tasks": [ - "OrderedSet intersection with Self (75% overlap)", - "OrderedSet intersection with Array (75% overlap)", - "Set intersection with Self (75% overlap)", - "Set intersection with Array (75% overlap)", - ] - }, - { - "kind": "chart", - "title": "intersection (100% overlap)", - "tasks": [ - "OrderedSet intersection with Self (100% overlap)", - "OrderedSet intersection with Array (100% overlap)", - "Set intersection with Self (100% overlap)", - "Set intersection with Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "formIntersection (0% overlap)", - "tasks": [ - "OrderedSet formIntersection with Self (0% overlap)", - "OrderedSet formIntersection with Array (0% overlap)", - "Set formIntersection with Self (0% overlap)", - "Set formIntersection with Array (0% overlap)", - ] - }, - { - "kind": "chart", - "title": "formIntersection (25% overlap)", - "tasks": [ - "OrderedSet formIntersection with Self (25% overlap)", - "OrderedSet formIntersection with Array (25% overlap)", - "Set formIntersection with Self (25% overlap)", - "Set formIntersection with Array (25% overlap)", - ] - }, - { - "kind": "chart", - "title": "formIntersection (50% overlap)", - "tasks": [ - "OrderedSet formIntersection with Self (50% overlap)", - "OrderedSet formIntersection with Array (50% overlap)", - "Set formIntersection with Self (50% overlap)", - "Set formIntersection with Array (50% overlap)", - ] - }, - { - "kind": "chart", - "title": "formIntersection (75% overlap)", - "tasks": [ - "OrderedSet formIntersection with Self (75% overlap)", - "OrderedSet formIntersection with Array (75% overlap)", - "Set formIntersection with Self (75% overlap)", - "Set formIntersection with Array (75% overlap)", - ] - }, - { - "kind": "chart", - "title": "formIntersection (100% overlap)", - "tasks": [ - "OrderedSet formIntersection with Self (100% overlap)", - "OrderedSet formIntersection with Array (100% overlap)", - "Set formIntersection with Self (100% overlap)", - "Set formIntersection with Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "symmetricDifference (0% overlap)", - "tasks": [ - "OrderedSet symmetricDifference with Self (0% overlap)", - "OrderedSet symmetricDifference with Array (0% overlap)", - "Set symmetricDifference with Self (0% overlap)", - "Set symmetricDifference with Array (0% overlap)", - ] - }, - { - "kind": "chart", - "title": "symmetricDifference (25% overlap)", - "tasks": [ - "OrderedSet symmetricDifference with Self (25% overlap)", - "OrderedSet symmetricDifference with Array (25% overlap)", - "Set symmetricDifference with Self (25% overlap)", - "Set symmetricDifference with Array (25% overlap)", - ] - }, - { - "kind": "chart", - "title": "symmetricDifference (50% overlap)", - "tasks": [ - "OrderedSet symmetricDifference with Self (50% overlap)", - "OrderedSet symmetricDifference with Array (50% overlap)", - "Set symmetricDifference with Self (50% overlap)", - "Set symmetricDifference with Array (50% overlap)", - ] - }, - { - "kind": "chart", - "title": "symmetricDifference (75% overlap)", - "tasks": [ - "OrderedSet symmetricDifference with Self (75% overlap)", - "OrderedSet symmetricDifference with Array (75% overlap)", - "Set symmetricDifference with Self (75% overlap)", - "Set symmetricDifference with Array (75% overlap)", - ] - }, - { - "kind": "chart", - "title": "symmetricDifference (100% overlap)", - "tasks": [ - "OrderedSet symmetricDifference with Self (100% overlap)", - "OrderedSet symmetricDifference with Array (100% overlap)", - "Set symmetricDifference with Self (100% overlap)", - "Set symmetricDifference with Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "formSymmetricDifference (0% overlap)", - "tasks": [ - "OrderedSet formSymmetricDifference with Self (0% overlap)", - "OrderedSet formSymmetricDifference with Array (0% overlap)", - "Set formSymmetricDifference with Self (0% overlap)", - "Set formSymmetricDifference with Array (0% overlap)", - ] - }, - { - "kind": "chart", - "title": "formSymmetricDifference (25% overlap)", - "tasks": [ - "OrderedSet formSymmetricDifference with Self (25% overlap)", - "OrderedSet formSymmetricDifference with Array (25% overlap)", - "Set formSymmetricDifference with Self (25% overlap)", - "Set formSymmetricDifference with Array (25% overlap)", - ] - }, - { - "kind": "chart", - "title": "formSymmetricDifference (50% overlap)", - "tasks": [ - "OrderedSet formSymmetricDifference with Self (50% overlap)", - "OrderedSet formSymmetricDifference with Array (50% overlap)", - "Set formSymmetricDifference with Self (50% overlap)", - "Set formSymmetricDifference with Array (50% overlap)", - ] - }, - { - "kind": "chart", - "title": "formSymmetricDifference (75% overlap)", - "tasks": [ - "OrderedSet formSymmetricDifference with Self (75% overlap)", - "OrderedSet formSymmetricDifference with Array (75% overlap)", - "Set formSymmetricDifference with Self (75% overlap)", - "Set formSymmetricDifference with Array (75% overlap)", - ] - }, - { - "kind": "chart", - "title": "formSymmetricDifference (100% overlap)", - "tasks": [ - "OrderedSet formSymmetricDifference with Self (100% overlap)", - "OrderedSet formSymmetricDifference with Array (100% overlap)", - "Set formSymmetricDifference with Self (100% overlap)", - "Set formSymmetricDifference with Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "subtracting (0% overlap)", - "tasks": [ - "OrderedSet subtracting Self (0% overlap)", - "OrderedSet subtracting Array (0% overlap)", - "Set subtracting Self (0% overlap)", - "Set subtracting Array (0% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtracting (25% overlap)", - "tasks": [ - "OrderedSet subtracting Self (25% overlap)", - "OrderedSet subtracting Array (25% overlap)", - "Set subtracting Self (25% overlap)", - "Set subtracting Array (25% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtracting (50% overlap)", - "tasks": [ - "OrderedSet subtracting Self (50% overlap)", - "OrderedSet subtracting Array (50% overlap)", - "Set subtracting Self (50% overlap)", - "Set subtracting Array (50% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtracting (75% overlap)", - "tasks": [ - "OrderedSet subtracting Self (75% overlap)", - "OrderedSet subtracting Array (75% overlap)", - "Set subtracting Self (75% overlap)", - "Set subtracting Array (75% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtracting (100% overlap)", - "tasks": [ - "OrderedSet subtracting Self (100% overlap)", - "OrderedSet subtracting Array (100% overlap)", - "Set subtracting Self (100% overlap)", - "Set subtracting Array (100% overlap)", - ] - }, - ] - }, - { - "kind": "variants", - "charts": [ - { - "kind": "chart", - "title": "subtract (0% overlap)", - "tasks": [ - "OrderedSet subtract Self (0% overlap)", - "OrderedSet subtract Array (0% overlap)", - "Set subtract Self (0% overlap)", - "Set subtract Array (0% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtract (25% overlap)", - "tasks": [ - "OrderedSet subtract Self (25% overlap)", - "OrderedSet subtract Array (25% overlap)", - "Set subtract Self (25% overlap)", - "Set subtract Array (25% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtract (50% overlap)", - "tasks": [ - "OrderedSet subtract Self (50% overlap)", - "OrderedSet subtract Array (50% overlap)", - "Set subtract Self (50% overlap)", - "Set subtract Array (50% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtract (75% overlap)", - "tasks": [ - "OrderedSet subtract Self (75% overlap)", - "OrderedSet subtract Array (75% overlap)", - "Set subtract Self (75% overlap)", - "Set subtract Array (75% overlap)", - ] - }, - { - "kind": "chart", - "title": "subtract (100% overlap)", - "tasks": [ - "OrderedSet subtract Self (100% overlap)", - "OrderedSet subtract Array (100% overlap)", - "Set subtract Self (100% overlap)", - "Set subtract Array (100% overlap)", - ] - }, - ] - }, - ] - }, - ] -} diff --git a/Benchmarks/Libraries/PersistentDictionary.json b/Benchmarks/Libraries/ShareableDictionary.json similarity index 61% rename from Benchmarks/Libraries/PersistentDictionary.json rename to Benchmarks/Libraries/ShareableDictionary.json index 2457a4d0..a568e0fd 100644 --- a/Benchmarks/Libraries/PersistentDictionary.json +++ b/Benchmarks/Libraries/ShareableDictionary.json @@ -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 init(uniqueKeysWithValues:)", - "PersistentDictionary sequential iteration", - "PersistentDictionary sequential iteration, indices", - "PersistentDictionary.Keys sequential iteration", - "PersistentDictionary.Values sequential iteration", - "PersistentDictionary indexing subscript", - "PersistentDictionary subscript, successful lookups", - "PersistentDictionary subscript, unsuccessful lookups", - "PersistentDictionary subscript, noop setter", - "PersistentDictionary subscript, set existing", - "PersistentDictionary subscript, _modify", - "PersistentDictionary subscript, insert, unique", - "PersistentDictionary subscript, insert, shared", - "PersistentDictionary subscript, remove existing, unique", - "PersistentDictionary subscript, remove existing, shared", - "PersistentDictionary subscript, remove missing", - "PersistentDictionary defaulted subscript, successful lookups", - "PersistentDictionary defaulted subscript, unsuccessful lookups", - "PersistentDictionary defaulted subscript, _modify existing", - "PersistentDictionary defaulted subscript, _modify missing", - "PersistentDictionary successful index(forKey:)", - "PersistentDictionary unsuccessful index(forKey:)", - "PersistentDictionary updateValue(_:forKey:), existing", - "PersistentDictionary updateValue(_:forKey:), insert", - "PersistentDictionary random removals (existing keys)", - "PersistentDictionary random removals (missing keys)", + "ShareableDictionary init(uniqueKeysWithValues:)", + "ShareableDictionary sequential iteration", + "ShareableDictionary sequential iteration, indices", + "ShareableDictionary.Keys sequential iteration", + "ShareableDictionary.Values sequential iteration", + "ShareableDictionary indexing subscript", + "ShareableDictionary subscript, successful lookups", + "ShareableDictionary subscript, unsuccessful lookups", + "ShareableDictionary subscript, noop setter", + "ShareableDictionary subscript, set existing", + "ShareableDictionary subscript, _modify", + "ShareableDictionary subscript, insert, unique", + "ShareableDictionary subscript, insert, shared", + "ShareableDictionary subscript, remove existing, unique", + "ShareableDictionary subscript, remove existing, shared", + "ShareableDictionary subscript, remove missing", + "ShareableDictionary defaulted subscript, successful lookups", + "ShareableDictionary defaulted subscript, unsuccessful lookups", + "ShareableDictionary defaulted subscript, _modify existing", + "ShareableDictionary defaulted subscript, _modify missing", + "ShareableDictionary successful index(forKey:)", + "ShareableDictionary unsuccessful index(forKey:)", + "ShareableDictionary updateValue(_:forKey:), existing", + "ShareableDictionary updateValue(_:forKey:), insert", + "ShareableDictionary random removals (existing keys)", + "ShareableDictionary random removals (missing keys)", ] } ] @@ -50,7 +50,7 @@ "kind": "chart", "title": "init(uniqueKeysWithValues:)", "tasks": [ - "PersistentDictionary init(uniqueKeysWithValues:)", + "ShareableDictionary init(uniqueKeysWithValues:)", "Dictionary init(uniqueKeysWithValues:)", "OrderedDictionary init(uniqueKeysWithValues:)", ] @@ -59,7 +59,7 @@ "kind": "chart", "title": "sequential iteration", "tasks": [ - "PersistentDictionary sequential iteration", + "ShareableDictionary sequential iteration", "Dictionary sequential iteration", "OrderedDictionary sequential iteration", ] @@ -68,7 +68,7 @@ "kind": "chart", "title": "sequential iteration [Keys]", "tasks": [ - "PersistentDictionary.Keys sequential iteration", + "ShareableDictionary.Keys sequential iteration", "Dictionary.Keys sequential iteration", "OrderedDictionary.Keys sequential iteration", ] @@ -77,7 +77,7 @@ "kind": "chart", "title": "sequential iteration [Values]", "tasks": [ - "PersistentDictionary.Values sequential iteration", + "ShareableDictionary.Values sequential iteration", "Dictionary.Values sequential iteration", "OrderedDictionary.Values sequential iteration", ] @@ -86,7 +86,7 @@ "kind": "chart", "title": "sequential iteration using indices", "tasks": [ - "PersistentDictionary sequential iteration, indices", + "ShareableDictionary sequential iteration, indices", "Dictionary sequential iteration, indices", "OrderedDictionary sequential iteration, indices", ] @@ -95,7 +95,7 @@ "kind": "chart", "title": "indexing subscript", "tasks": [ - "PersistentDictionary indexing subscript", + "ShareableDictionary indexing subscript", "Dictionary indexing subscript", "OrderedDictionary indexing subscript", ] @@ -104,7 +104,7 @@ "kind": "chart", "title": "subscript, successful lookups", "tasks": [ - "PersistentDictionary subscript, successful lookups", + "ShareableDictionary subscript, successful lookups", "Dictionary subscript, successful lookups", "OrderedDictionary subscript, successful lookups", ] @@ -113,7 +113,7 @@ "kind": "chart", "title": "subscript, unsuccessful lookups", "tasks": [ - "PersistentDictionary subscript, unsuccessful lookups", + "ShareableDictionary subscript, unsuccessful lookups", "Dictionary subscript, unsuccessful lookups", "OrderedDictionary subscript, unsuccessful lookups", ] @@ -122,7 +122,7 @@ "kind": "chart", "title": "subscript, insert into unique collection", "tasks": [ - "PersistentDictionary subscript, insert, unique", + "ShareableDictionary subscript, insert, unique", "Dictionary subscript, insert, unique", "Dictionary subscript, insert, reserving capacity", "OrderedDictionary subscript, append, unique", @@ -133,7 +133,7 @@ "kind": "chart", "title": "subscript, insert into shared collection", "tasks": [ - "PersistentDictionary subscript, insert, shared", + "ShareableDictionary subscript, insert, shared", "Dictionary subscript, insert, shared", "OrderedDictionary subscript, append, shared", ] @@ -142,7 +142,7 @@ "kind": "chart", "title": "subscript, remove existing from unique collection", "tasks": [ - "PersistentDictionary subscript, remove existing, unique", + "ShareableDictionary subscript, remove existing, unique", "Dictionary subscript, remove existing, unique", "OrderedDictionary subscript, remove existing, unique", ] @@ -151,7 +151,7 @@ "kind": "chart", "title": "subscript, remove existing from shared collection", "tasks": [ - "PersistentDictionary subscript, remove existing, shared", + "ShareableDictionary subscript, remove existing, shared", "Dictionary subscript, remove existing, shared", "OrderedDictionary subscript, remove existing, shared", ] @@ -160,8 +160,8 @@ "kind": "chart", "title": "subscript, _modify existing", "tasks": [ - "PersistentDictionary subscript, _modify", - "PersistentDictionary defaulted subscript, _modify existing", + "ShareableDictionary subscript, _modify", + "ShareableDictionary defaulted subscript, _modify existing", "Dictionary subscript, _modify", "Dictionary defaulted subscript, _modify existing", "OrderedDictionary subscript, _modify", @@ -173,7 +173,7 @@ "kind": "chart", "title": "index(forKey:), successful index(forKey:)", "tasks": [ - "PersistentDictionary successful index(forKey:)", + "ShareableDictionary successful index(forKey:)", "Dictionary successful index(forKey:)", "OrderedDictionary successful index(forKey:)", ] @@ -182,7 +182,7 @@ "kind": "chart", "title": "index(forKey:), unsuccessful index(forKey:)", "tasks": [ - "PersistentDictionary unsuccessful index(forKey:)", + "ShareableDictionary unsuccessful index(forKey:)", "Dictionary unsuccessful index(forKey:)", "OrderedDictionary unsuccessful index(forKey:)", ] @@ -191,7 +191,7 @@ "kind": "chart", "title": "updateValue(_:forKey:), existing", "tasks": [ - "PersistentDictionary updateValue(_:forKey:), existing", + "ShareableDictionary updateValue(_:forKey:), existing", "Dictionary updateValue(_:forKey:), existing", "OrderedDictionary updateValue(_:forKey:), existing" ] @@ -200,7 +200,7 @@ "kind": "chart", "title": "updateValue(_:forKey:), insert", "tasks": [ - "PersistentDictionary updateValue(_:forKey:), insert", + "ShareableDictionary updateValue(_:forKey:), insert", "Dictionary updateValue(_:forKey:), insert", "OrderedDictionary updateValue(_:forKey:), append" ] diff --git a/Benchmarks/Libraries/ShareableSet.json b/Benchmarks/Libraries/ShareableSet.json new file mode 100644 index 00000000..aa84b21f --- /dev/null +++ b/Benchmarks/Libraries/ShareableSet.json @@ -0,0 +1,882 @@ +{ + "kind": "group", + "title": "ShareableSet Benchmarks", + "directory": "Results", + "contents": [ + { + "kind": "chart", + "title": "operations", + "tasks": [ + "ShareableSet init from range", + "ShareableSet init from unsafe buffer", + "ShareableSet sequential iteration", + "ShareableSet successful contains", + "ShareableSet unsuccessful contains", + "ShareableSet insert", + "ShareableSet remove" + ] + }, + { + "kind": "chart", + "title": "initializers", + "tasks": [ + "ShareableSet init from range", + "ShareableSet init from unsafe buffer", + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "union with Self, distinct", + "tasks": [ + "ShareableSet union with Self (0% overlap, distinct)", + "ShareableSet union with Self (25% overlap, distinct)", + "ShareableSet union with Self (50% overlap, distinct)", + "ShareableSet union with Self (75% overlap, distinct)", + "ShareableSet union with Self (100% overlap, distinct)", + ] + }, + { + "kind": "chart", + "title": "union with Self, shared", + "tasks": [ + "ShareableSet union with Self (0% overlap, shared)", + "ShareableSet union with Self (25% overlap, shared)", + "ShareableSet union with Self (50% overlap, shared)", + "ShareableSet union with Self (75% overlap, shared)", + "ShareableSet union with Self (100% overlap, shared)", + ] + }, + { + "kind": "chart", + "title": "union with Array", + "tasks": [ + "ShareableSet union with Array (0% overlap)", + "ShareableSet union with Array (25% overlap)", + "ShareableSet union with Array (50% overlap)", + "ShareableSet union with Array (75% overlap)", + "ShareableSet union with Array (100% overlap)", + ] + }, + { + "kind": "chart", + "title": "formUnion with Self, distinct", + "tasks": [ + "ShareableSet formUnion with Self (0% overlap, distinct)", + "ShareableSet formUnion with Self (25% overlap, distinct)", + "ShareableSet formUnion with Self (50% overlap, distinct)", + "ShareableSet formUnion with Self (75% overlap, distinct)", + "ShareableSet formUnion with Self (100% overlap, distinct)", + ] + }, + { + "kind": "chart", + "title": "formUnion with Self, shared", + "tasks": [ + "ShareableSet formUnion with Self (0% overlap, shared)", + "ShareableSet formUnion with Self (25% overlap, shared)", + "ShareableSet formUnion with Self (50% overlap, shared)", + "ShareableSet formUnion with Self (75% overlap, shared)", + "ShareableSet formUnion with Self (100% overlap, shared)", + ] + }, + { + "kind": "chart", + "title": "formUnion with Array", + "tasks": [ + "ShareableSet formUnion with Array (0% overlap)", + "ShareableSet formUnion with Array (25% overlap)", + "ShareableSet formUnion with Array (50% overlap)", + "ShareableSet formUnion with Array (75% overlap)", + "ShareableSet formUnion with Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "intersection with Self, distinct", + "tasks": [ + "ShareableSet intersection with Self (0% overlap, distinct)", + "ShareableSet intersection with Self (25% overlap, distinct)", + "ShareableSet intersection with Self (50% overlap, distinct)", + "ShareableSet intersection with Self (75% overlap, distinct)", + "ShareableSet intersection with Self (100% overlap, distinct)", + ] + }, + { + "kind": "chart", + "title": "intersection with Self, shared", + "tasks": [ + "ShareableSet intersection with Self (0% overlap, shared)", + "ShareableSet intersection with Self (25% overlap, shared)", + "ShareableSet intersection with Self (50% overlap, shared)", + "ShareableSet intersection with Self (75% overlap, shared)", + "ShareableSet intersection with Self (100% overlap, shared)", + ] + }, + { + "kind": "chart", + "title": "intersection with Array", + "tasks": [ + "ShareableSet intersection with Array (0% overlap)", + "ShareableSet intersection with Array (25% overlap)", + "ShareableSet intersection with Array (50% overlap)", + "ShareableSet intersection with Array (75% overlap)", + "ShareableSet intersection with Array (100% overlap)", + ] + }, + { + "kind": "chart", + "title": "formIntersection with Self, distinct", + "tasks": [ + "ShareableSet formIntersection with Self (0% overlap, distinct)", + "ShareableSet formIntersection with Self (25% overlap, distinct)", + "ShareableSet formIntersection with Self (50% overlap, distinct)", + "ShareableSet formIntersection with Self (75% overlap, distinct)", + "ShareableSet formIntersection with Self (100% overlap, distinct)", + ] + }, + { + "kind": "chart", + "title": "formIntersection with Self, shared", + "tasks": [ + "ShareableSet formIntersection with Self (0% overlap, shared)", + "ShareableSet formIntersection with Self (25% overlap, shared)", + "ShareableSet formIntersection with Self (50% overlap, shared)", + "ShareableSet formIntersection with Self (75% overlap, shared)", + "ShareableSet formIntersection with Self (100% overlap, shared)", + ] + }, + { + "kind": "chart", + "title": "formIntersection with Array", + "tasks": [ + "ShareableSet formIntersection with Array (0% overlap)", + "ShareableSet formIntersection with Array (25% overlap)", + "ShareableSet formIntersection with Array (50% overlap)", + "ShareableSet formIntersection with Array (75% overlap)", + "ShareableSet formIntersection with Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "symmetricDifference with Self, distinct", + "tasks": [ + "ShareableSet symmetricDifference with Self (0% overlap, distinct)", + "ShareableSet symmetricDifference with Self (25% overlap, distinct)", + "ShareableSet symmetricDifference with Self (50% overlap, distinct)", + "ShareableSet symmetricDifference with Self (75% overlap, distinct)", + "ShareableSet symmetricDifference with Self (100% overlap, distinct)", + ] + }, + { + "kind": "chart", + "title": "symmetricDifference with Self, shared", + "tasks": [ + "ShareableSet symmetricDifference with Self (0% overlap, shared)", + "ShareableSet symmetricDifference with Self (25% overlap, shared)", + "ShareableSet symmetricDifference with Self (50% overlap, shared)", + "ShareableSet symmetricDifference with Self (75% overlap, shared)", + "ShareableSet symmetricDifference with Self (100% overlap, shared)", + ] + }, + { + "kind": "chart", + "title": "symmetricDifference with Array", + "tasks": [ + "ShareableSet symmetricDifference with Array (0% overlap)", + "ShareableSet symmetricDifference with Array (25% overlap)", + "ShareableSet symmetricDifference with Array (50% overlap)", + "ShareableSet symmetricDifference with Array (75% overlap)", + "ShareableSet symmetricDifference with Array (100% overlap)", + ] + }, + { + "kind": "chart", + "title": "formSymmetricDifference with Self, distinct", + "tasks": [ + "ShareableSet formSymmetricDifference with Self (0% overlap, distinct)", + "ShareableSet formSymmetricDifference with Self (25% overlap, distinct)", + "ShareableSet formSymmetricDifference with Self (50% overlap, distinct)", + "ShareableSet formSymmetricDifference with Self (75% overlap, distinct)", + "ShareableSet formSymmetricDifference with Self (100% overlap, distinct)", + ] + }, + { + "kind": "chart", + "title": "formSymmetricDifference with Self, shared", + "tasks": [ + "ShareableSet formSymmetricDifference with Self (0% overlap, shared)", + "ShareableSet formSymmetricDifference with Self (25% overlap, shared)", + "ShareableSet formSymmetricDifference with Self (50% overlap, shared)", + "ShareableSet formSymmetricDifference with Self (75% overlap, shared)", + "ShareableSet formSymmetricDifference with Self (100% overlap, shared)", + ] + }, + { + "kind": "chart", + "title": "formSymmetricDifference with Array", + "tasks": [ + "ShareableSet formSymmetricDifference with Array (0% overlap)", + "ShareableSet formSymmetricDifference with Array (25% overlap)", + "ShareableSet formSymmetricDifference with Array (50% overlap)", + "ShareableSet formSymmetricDifference with Array (75% overlap)", + "ShareableSet formSymmetricDifference with Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "subtracting Self, distinct", + "tasks": [ + "ShareableSet subtracting Self (0% overlap, distinct)", + "ShareableSet subtracting Self (25% overlap, distinct)", + "ShareableSet subtracting Self (50% overlap, distinct)", + "ShareableSet subtracting Self (75% overlap, distinct)", + "ShareableSet subtracting Self (100% overlap, distinct)", + ] + }, + { + "kind": "chart", + "title": "subtracting Self, shared", + "tasks": [ + "ShareableSet subtracting Self (0% overlap, shared)", + "ShareableSet subtracting Self (25% overlap, shared)", + "ShareableSet subtracting Self (50% overlap, shared)", + "ShareableSet subtracting Self (75% overlap, shared)", + "ShareableSet subtracting Self (100% overlap, shared)", + ] + }, + { + "kind": "chart", + "title": "subtracting Array", + "tasks": [ + "ShareableSet subtracting Array (0% overlap)", + "ShareableSet subtracting Array (25% overlap)", + "ShareableSet subtracting Array (50% overlap)", + "ShareableSet subtracting Array (75% overlap)", + "ShareableSet subtracting Array (100% overlap)", + ] + }, + { + "kind": "chart", + "title": "subtract Self, distinct", + "tasks": [ + "ShareableSet subtract Self (0% overlap, distinct)", + "ShareableSet subtract Self (25% overlap, distinct)", + "ShareableSet subtract Self (50% overlap, distinct)", + "ShareableSet subtract Self (75% overlap, distinct)", + "ShareableSet subtract Self (100% overlap, distinct)", + ] + }, + { + "kind": "chart", + "title": "subtract Self, shared", + "tasks": [ + "ShareableSet subtract Self (0% overlap, shared)", + "ShareableSet subtract Self (25% overlap, shared)", + "ShareableSet subtract Self (50% overlap, shared)", + "ShareableSet subtract Self (75% overlap, shared)", + "ShareableSet subtract Self (100% overlap, shared)", + ] + }, + { + "kind": "chart", + "title": "subtract with Array", + "tasks": [ + "ShareableSet subtract Array (0% overlap)", + "ShareableSet subtract Array (25% overlap)", + "ShareableSet subtract Array (50% overlap)", + "ShareableSet subtract Array (75% overlap)", + "ShareableSet subtract Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "group", + "title": "Reference comparisons", + "directory": "versus", + "contents": [ + { + "kind": "chart", + "title": "init from buffer of integers", + "tasks": [ + "ShareableSet init from unsafe buffer", + "Set init from unsafe buffer", + ] + }, + { + "kind": "chart", + "title": "init from range of integers", + "tasks": [ + "ShareableSet init from range", + "Set init from range", + ] + }, + { + "kind": "chart", + "title": "sequential iteration", + "tasks": [ + "ShareableSet sequential iteration", + "Set sequential iteration", + ] + }, + { + "kind": "chart", + "title": "sequential iteration using indices", + "tasks": [ + "ShareableSet sequential iteration, indices", + "Set sequential iteration, indices", + ] + }, + { + "kind": "chart", + "title": "successful random lookups", + "tasks": [ + "ShareableSet successful contains", + "Set successful contains", + ] + }, + { + "kind": "chart", + "title": "unsuccessful random lookups", + "tasks": [ + "ShareableSet unsuccessful contains", + "Set unsuccessful contains", + ] + }, + { + "kind": "chart", + "title": "insert", + "tasks": [ + "ShareableSet insert", + "Set insert", + "Set insert, reserving capacity", + ] + }, + { + "kind": "chart", + "title": "insert-shared", + "tasks": [ + "ShareableSet insert, shared", + "Set insert, shared", + ] + }, + { + "kind": "chart", + "title": "model building with constant diffing", + "tasks": [ + "ShareableSet model diffing", + "Set model diffing", + ] + }, + { + "kind": "chart", + "title": "remove", + "tasks": [ + "ShareableSet remove", + "ShareableSet remove, shared", + "Set remove", + "Set remove, shared", + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "union (0% overlap)", + "tasks": [ + "ShareableSet union with Self (0% overlap, distinct)", + "ShareableSet union with Self (0% overlap, shared)", + "ShareableSet union with Array (0% overlap)", + "Set union with Self (0% overlap)", + "Set union with Array (0% overlap)", + ] + }, + { + "kind": "chart", + "title": "union (25% overlap)", + "tasks": [ + "ShareableSet union with Self (25% overlap, distinct)", + "ShareableSet union with Self (25% overlap, shared)", + "ShareableSet union with Array (25% overlap)", + "Set union with Self (25% overlap)", + "Set union with Array (25% overlap)", + ] + }, + { + "kind": "chart", + "title": "union (50% overlap)", + "tasks": [ + "ShareableSet union with Self (50% overlap, distinct)", + "ShareableSet union with Self (50% overlap, shared)", + "ShareableSet union with Array (50% overlap)", + "Set union with Self (50% overlap)", + "Set union with Array (50% overlap)", + ] + }, + { + "kind": "chart", + "title": "union (75% overlap)", + "tasks": [ + "ShareableSet union with Self (75% overlap, distinct)", + "ShareableSet union with Self (75% overlap, shared)", + "ShareableSet union with Array (75% overlap)", + "Set union with Self (75% overlap)", + "Set union with Array (75% overlap)", + ] + }, + { + "kind": "chart", + "title": "union (100% overlap)", + "tasks": [ + "ShareableSet union with Self (100% overlap, distinct)", + "ShareableSet union with Self (100% overlap, shared)", + "ShareableSet union with Array (100% overlap)", + "Set union with Self (100% overlap)", + "Set union with Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "formUnion (0% overlap)", + "tasks": [ + "ShareableSet formUnion with Self (0% overlap, distinct)", + "ShareableSet formUnion with Self (0% overlap, shared)", + "ShareableSet formUnion with Array (0% overlap)", + "Set formUnion with Self (0% overlap)", + "Set formUnion with Array (0% overlap)", + ] + }, + { + "kind": "chart", + "title": "formUnion (25% overlap)", + "tasks": [ + "ShareableSet formUnion with Self (25% overlap, distinct)", + "ShareableSet formUnion with Self (25% overlap, shared)", + "ShareableSet formUnion with Array (25% overlap)", + "Set formUnion with Self (25% overlap)", + "Set formUnion with Array (25% overlap)", + ] + }, + { + "kind": "chart", + "title": "formUnion (50% overlap)", + "tasks": [ + "ShareableSet formUnion with Self (50% overlap, distinct)", + "ShareableSet formUnion with Self (50% overlap, shared)", + "ShareableSet formUnion with Array (50% overlap)", + "Set formUnion with Self (50% overlap)", + "Set formUnion with Array (50% overlap)", + ] + }, + { + "kind": "chart", + "title": "formUnion (75% overlap)", + "tasks": [ + "ShareableSet formUnion with Self (75% overlap, distinct)", + "ShareableSet formUnion with Self (75% overlap, shared)", + "ShareableSet formUnion with Array (75% overlap)", + "Set formUnion with Self (75% overlap)", + "Set formUnion with Array (75% overlap)", + ] + }, + { + "kind": "chart", + "title": "formUnion (100% overlap)", + "tasks": [ + "ShareableSet formUnion with Self (100% overlap, distinct)", + "ShareableSet formUnion with Self (100% overlap, shared)", + "ShareableSet formUnion with Array (100% overlap)", + "Set formUnion with Self (100% overlap)", + "Set formUnion with Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "intersection (0% overlap)", + "tasks": [ + "ShareableSet intersection with Self (0% overlap, distinct)", + "ShareableSet intersection with Self (0% overlap, shared)", + "ShareableSet intersection with Array (0% overlap)", + "Set intersection with Self (0% overlap)", + "Set intersection with Array (0% overlap)", + ] + }, + { + "kind": "chart", + "title": "intersection (25% overlap)", + "tasks": [ + "ShareableSet intersection with Self (25% overlap, distinct)", + "ShareableSet intersection with Self (25% overlap, shared)", + "ShareableSet intersection with Array (25% overlap)", + "Set intersection with Self (25% overlap)", + "Set intersection with Array (25% overlap)", + ] + }, + { + "kind": "chart", + "title": "intersection (50% overlap)", + "tasks": [ + "ShareableSet intersection with Self (50% overlap, distinct)", + "ShareableSet intersection with Self (50% overlap, shared)", + "ShareableSet intersection with Array (50% overlap)", + "Set intersection with Self (50% overlap)", + "Set intersection with Array (50% overlap)", + ] + }, + { + "kind": "chart", + "title": "intersection (75% overlap)", + "tasks": [ + "ShareableSet intersection with Self (75% overlap, distinct)", + "ShareableSet intersection with Self (75% overlap, shared)", + "ShareableSet intersection with Array (75% overlap)", + "Set intersection with Self (75% overlap)", + "Set intersection with Array (75% overlap)", + ] + }, + { + "kind": "chart", + "title": "intersection (100% overlap)", + "tasks": [ + "ShareableSet intersection with Self (100% overlap, distinct)", + "ShareableSet intersection with Self (100% overlap, shared)", + "ShareableSet intersection with Array (100% overlap)", + "Set intersection with Self (100% overlap)", + "Set intersection with Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "formIntersection (0% overlap)", + "tasks": [ + "ShareableSet formIntersection with Self (0% overlap, distinct)", + "ShareableSet formIntersection with Self (0% overlap, shared)", + "ShareableSet formIntersection with Array (0% overlap)", + "Set formIntersection with Self (0% overlap)", + "Set formIntersection with Array (0% overlap)", + ] + }, + { + "kind": "chart", + "title": "formIntersection (25% overlap)", + "tasks": [ + "ShareableSet formIntersection with Self (25% overlap, distinct)", + "ShareableSet formIntersection with Self (25% overlap, shared)", + "ShareableSet formIntersection with Array (25% overlap)", + "Set formIntersection with Self (25% overlap)", + "Set formIntersection with Array (25% overlap)", + ] + }, + { + "kind": "chart", + "title": "formIntersection (50% overlap)", + "tasks": [ + "ShareableSet formIntersection with Self (50% overlap, distinct)", + "ShareableSet formIntersection with Self (50% overlap, shared)", + "ShareableSet formIntersection with Array (50% overlap)", + "Set formIntersection with Self (50% overlap)", + "Set formIntersection with Array (50% overlap)", + ] + }, + { + "kind": "chart", + "title": "formIntersection (75% overlap)", + "tasks": [ + "ShareableSet formIntersection with Self (75% overlap, distinct)", + "ShareableSet formIntersection with Self (75% overlap, shared)", + "ShareableSet formIntersection with Array (75% overlap)", + "Set formIntersection with Self (75% overlap)", + "Set formIntersection with Array (75% overlap)", + ] + }, + { + "kind": "chart", + "title": "formIntersection (100% overlap)", + "tasks": [ + "ShareableSet formIntersection with Self (100% overlap, distinct)", + "ShareableSet formIntersection with Self (100% overlap, shared)", + "ShareableSet formIntersection with Array (100% overlap)", + "Set formIntersection with Self (100% overlap)", + "Set formIntersection with Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "symmetricDifference (0% overlap)", + "tasks": [ + "ShareableSet symmetricDifference with Self (0% overlap, distinct)", + "ShareableSet symmetricDifference with Self (0% overlap, shared)", + "ShareableSet symmetricDifference with Array (0% overlap)", + "Set symmetricDifference with Self (0% overlap)", + "Set symmetricDifference with Array (0% overlap)", + ] + }, + { + "kind": "chart", + "title": "symmetricDifference (25% overlap)", + "tasks": [ + "ShareableSet symmetricDifference with Self (25% overlap, distinct)", + "ShareableSet symmetricDifference with Self (25% overlap, shared)", + "ShareableSet symmetricDifference with Array (25% overlap)", + "Set symmetricDifference with Self (25% overlap)", + "Set symmetricDifference with Array (25% overlap)", + ] + }, + { + "kind": "chart", + "title": "symmetricDifference (50% overlap)", + "tasks": [ + "ShareableSet symmetricDifference with Self (50% overlap, distinct)", + "ShareableSet symmetricDifference with Self (50% overlap, shared)", + "ShareableSet symmetricDifference with Array (50% overlap)", + "Set symmetricDifference with Self (50% overlap)", + "Set symmetricDifference with Array (50% overlap)", + ] + }, + { + "kind": "chart", + "title": "symmetricDifference (75% overlap)", + "tasks": [ + "ShareableSet symmetricDifference with Self (75% overlap, distinct)", + "ShareableSet symmetricDifference with Self (75% overlap, shared)", + "ShareableSet symmetricDifference with Array (75% overlap)", + "Set symmetricDifference with Self (75% overlap)", + "Set symmetricDifference with Array (75% overlap)", + ] + }, + { + "kind": "chart", + "title": "symmetricDifference (100% overlap)", + "tasks": [ + "ShareableSet symmetricDifference with Self (100% overlap, distinct)", + "ShareableSet symmetricDifference with Self (100% overlap, shared)", + "ShareableSet symmetricDifference with Array (100% overlap)", + "Set symmetricDifference with Self (100% overlap)", + "Set symmetricDifference with Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "formSymmetricDifference (0% overlap)", + "tasks": [ + "ShareableSet formSymmetricDifference with Self (0% overlap, distinct)", + "ShareableSet formSymmetricDifference with Self (0% overlap, shared)", + "ShareableSet formSymmetricDifference with Array (0% overlap)", + "Set formSymmetricDifference with Self (0% overlap)", + "Set formSymmetricDifference with Array (0% overlap)", + ] + }, + { + "kind": "chart", + "title": "formSymmetricDifference (25% overlap)", + "tasks": [ + "ShareableSet formSymmetricDifference with Self (25% overlap, distinct)", + "ShareableSet formSymmetricDifference with Self (25% overlap, shared)", + "ShareableSet formSymmetricDifference with Array (25% overlap)", + "Set formSymmetricDifference with Self (25% overlap)", + "Set formSymmetricDifference with Array (25% overlap)", + ] + }, + { + "kind": "chart", + "title": "formSymmetricDifference (50% overlap)", + "tasks": [ + "ShareableSet formSymmetricDifference with Self (50% overlap, distinct)", + "ShareableSet formSymmetricDifference with Self (50% overlap, shared)", + "ShareableSet formSymmetricDifference with Array (50% overlap)", + "Set formSymmetricDifference with Self (50% overlap)", + "Set formSymmetricDifference with Array (50% overlap)", + ] + }, + { + "kind": "chart", + "title": "formSymmetricDifference (75% overlap)", + "tasks": [ + "ShareableSet formSymmetricDifference with Self (75% overlap, distinct)", + "ShareableSet formSymmetricDifference with Self (75% overlap, shared)", + "ShareableSet formSymmetricDifference with Array (75% overlap)", + "Set formSymmetricDifference with Self (75% overlap)", + "Set formSymmetricDifference with Array (75% overlap)", + ] + }, + { + "kind": "chart", + "title": "formSymmetricDifference (100% overlap)", + "tasks": [ + "ShareableSet formSymmetricDifference with Self (100% overlap, distinct)", + "ShareableSet formSymmetricDifference with Self (100% overlap, shared)", + "ShareableSet formSymmetricDifference with Array (100% overlap)", + "Set formSymmetricDifference with Self (100% overlap)", + "Set formSymmetricDifference with Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "subtracting (0% overlap)", + "tasks": [ + "ShareableSet subtracting Self (0% overlap, distinct)", + "ShareableSet subtracting Self (0% overlap, shared)", + "ShareableSet subtracting Array (0% overlap)", + "Set subtracting Self (0% overlap)", + "Set subtracting Array (0% overlap)", + ] + }, + { + "kind": "chart", + "title": "subtracting (25% overlap)", + "tasks": [ + "ShareableSet subtracting Self (25% overlap, distinct)", + "ShareableSet subtracting Self (25% overlap, shared)", + "ShareableSet subtracting Array (25% overlap)", + "Set subtracting Self (25% overlap)", + "Set subtracting Array (25% overlap)", + ] + }, + { + "kind": "chart", + "title": "subtracting (50% overlap)", + "tasks": [ + "ShareableSet subtracting Self (50% overlap, distinct)", + "ShareableSet subtracting Self (50% overlap, shared)", + "ShareableSet subtracting Array (50% overlap)", + "Set subtracting Self (50% overlap)", + "Set subtracting Array (50% overlap)", + ] + }, + { + "kind": "chart", + "title": "subtracting (75% overlap)", + "tasks": [ + "ShareableSet subtracting Self (75% overlap, distinct)", + "ShareableSet subtracting Self (75% overlap, shared)", + "ShareableSet subtracting Array (75% overlap)", + "Set subtracting Self (75% overlap)", + "Set subtracting Array (75% overlap)", + ] + }, + { + "kind": "chart", + "title": "subtracting (100% overlap)", + "tasks": [ + "ShareableSet subtracting Self (100% overlap, distinct)", + "ShareableSet subtracting Self (100% overlap, shared)", + "ShareableSet subtracting Array (100% overlap)", + "Set subtracting Self (100% overlap)", + "Set subtracting Array (100% overlap)", + ] + }, + ] + }, + { + "kind": "variants", + "charts": [ + { + "kind": "chart", + "title": "subtract (0% overlap)", + "tasks": [ + "ShareableSet subtract Self (0% overlap, distinct)", + "ShareableSet subtract Self (0% overlap, shared)", + "ShareableSet subtract Array (0% overlap)", + "Set subtract Self (0% overlap)", + "Set subtract Array (0% overlap)", + ] + }, + { + "kind": "chart", + "title": "subtract (25% overlap)", + "tasks": [ + "ShareableSet subtract Self (25% overlap, distinct)", + "ShareableSet subtract Self (25% overlap, shared)", + "ShareableSet subtract Array (25% overlap)", + "Set subtract Self (25% overlap)", + "Set subtract Array (25% overlap)", + ] + }, + { + "kind": "chart", + "title": "subtract (50% overlap)", + "tasks": [ + "ShareableSet subtract Self (50% overlap, distinct)", + "ShareableSet subtract Self (50% overlap, shared)", + "ShareableSet subtract Array (50% overlap)", + "Set subtract Self (50% overlap)", + "Set subtract Array (50% overlap)", + ] + }, + { + "kind": "chart", + "title": "subtract (75% overlap)", + "tasks": [ + "ShareableSet subtract Self (75% overlap, distinct)", + "ShareableSet subtract Self (75% overlap, shared)", + "ShareableSet subtract Array (75% overlap)", + "Set subtract Self (75% overlap)", + "Set subtract Array (75% overlap)", + ] + }, + { + "kind": "chart", + "title": "subtract (100% overlap)", + "tasks": [ + "ShareableSet subtract Self (100% overlap, distinct)", + "ShareableSet subtract Self (100% overlap, shared)", + "ShareableSet subtract Array (100% overlap)", + "Set subtract Self (100% overlap)", + "Set subtract Array (100% overlap)", + ] + }, + ] + }, + ] + }, + ] +} diff --git a/Benchmarks/Sources/Benchmarks/PersistentDictionaryBenchmarks.swift b/Benchmarks/Sources/Benchmarks/ShareableDictionaryBenchmarks.swift similarity index 63% rename from Benchmarks/Sources/Benchmarks/PersistentDictionaryBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/ShareableDictionaryBenchmarks.swift index 8e09cf5c..288b13d2 100644 --- a/Benchmarks/Sources/Benchmarks/PersistentDictionaryBenchmarks.swift +++ b/Benchmarks/Sources/Benchmarks/ShareableDictionaryBenchmarks.swift @@ -10,25 +10,25 @@ //===----------------------------------------------------------------------===// import CollectionsBenchmark -import PersistentCollections +import ShareableHashedCollections extension Benchmark { - public mutating func addPersistentDictionaryBenchmarks() { + public mutating func addShareableDictionaryBenchmarks() { self.add( - title: "PersistentDictionary init(uniqueKeysWithValues:)", + title: "ShareableDictionary 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 sequential iteration", + title: "ShareableDictionary 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.Keys sequential iteration", + title: "ShareableDictionary.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.Values sequential iteration", + title: "ShareableDictionary.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 sequential iteration, indices", + title: "ShareableDictionary 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 striding, 10 steps", + title: "ShareableDictionary 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 indexing subscript", + title: "ShareableDictionary 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 subscript, successful lookups", + title: "ShareableDictionary 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 subscript, unsuccessful lookups", + title: "ShareableDictionary 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 subscript, noop setter", + title: "ShareableDictionary 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 subscript, set existing", + title: "ShareableDictionary 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 subscript, _modify", + title: "ShareableDictionary 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 subscript, insert, unique", + title: "ShareableDictionary subscript, insert, unique", input: [Int].self ) { input in - var d: PersistentDictionary = [:] + var d: ShareableDictionary = [:] for i in input { d[i] = 2 * i } @@ -191,10 +191,10 @@ extension Benchmark { } self.addSimple( - title: "PersistentDictionary subscript, insert, shared", + title: "ShareableDictionary subscript, insert, shared", input: [Int].self ) { input in - var d: PersistentDictionary = [:] + var d: ShareableDictionary = [:] for i in input { let copy = d d[i] = 2 * i @@ -205,11 +205,11 @@ extension Benchmark { } self.add( - title: "PersistentDictionary subscript, remove existing, unique", + title: "ShareableDictionary 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 subscript, remove existing, shared", + title: "ShareableDictionary 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 subscript, remove missing", + title: "ShareableDictionary 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 defaulted subscript, successful lookups", + title: "ShareableDictionary 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 defaulted subscript, unsuccessful lookups", + title: "ShareableDictionary 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 defaulted subscript, _modify existing", + title: "ShareableDictionary 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 defaulted subscript, _modify missing", + title: "ShareableDictionary 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 successful index(forKey:)", + title: "ShareableDictionary 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 unsuccessful index(forKey:)", + title: "ShareableDictionary 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 updateValue(_:forKey:), existing", + title: "ShareableDictionary 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 updateValue(_:forKey:), insert", + title: "ShareableDictionary 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 random removals (existing keys)", + title: "ShareableDictionary 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 random removals (missing keys)", + title: "ShareableDictionary 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 subscript, insert, unique", + title: "ShareableDictionary subscript, insert, unique", input: [Large].self ) { input in return { timer in - var d: PersistentDictionary = [:] + var d: ShareableDictionary = [:] timer.measure { for value in input { d[value] = value @@ -419,11 +419,11 @@ extension Benchmark { } self.add( - title: "PersistentDictionary subscript, insert, shared", + title: "ShareableDictionary subscript, insert, shared", input: [Large].self ) { input in return { timer in - var d: PersistentDictionary = [:] + var d: ShareableDictionary = [:] timer.measure { for value in input { let copy = d @@ -437,11 +437,11 @@ extension Benchmark { } self.add( - title: "PersistentDictionary subscript, remove existing, unique", + title: "ShareableDictionary 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 subscript, remove existing, shared", + title: "ShareableDictionary 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 { diff --git a/Benchmarks/Sources/Benchmarks/PersistentSetBenchmarks.swift b/Benchmarks/Sources/Benchmarks/ShareableSetBenchmarks.swift similarity index 51% rename from Benchmarks/Sources/Benchmarks/PersistentSetBenchmarks.swift rename to Benchmarks/Sources/Benchmarks/ShareableSetBenchmarks.swift index d4877da2..73aceb72 100644 --- a/Benchmarks/Sources/Benchmarks/PersistentSetBenchmarks.swift +++ b/Benchmarks/Sources/Benchmarks/ShareableSetBenchmarks.swift @@ -10,31 +10,31 @@ //===----------------------------------------------------------------------===// import CollectionsBenchmark -import PersistentCollections +import ShareableHashedCollections extension Benchmark { - public mutating func addPersistentSetBenchmarks() { + public mutating func addShareableSetBenchmarks() { self.addSimple( - title: "PersistentSet init from range", + title: "ShareableSet init from range", input: Int.self ) { size in - blackHole(PersistentSet(0 ..< size)) + blackHole(ShareableSet(0 ..< size)) } self.addSimple( - title: "PersistentSet init from unsafe buffer", + title: "ShareableSet init from unsafe buffer", input: [Int].self ) { input in input.withUnsafeBufferPointer { buffer in - blackHole(PersistentSet(buffer)) + blackHole(ShareableSet(buffer)) } } self.add( - title: "PersistentSet sequential iteration", + title: "ShareableSet 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 sequential iteration, indices", + title: "ShareableSet 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 successful contains", + title: "ShareableSet 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 unsuccessful contains", + title: "ShareableSet 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 insert", + title: "ShareableSet insert", input: [Int].self ) { input in - var set: PersistentSet = [] + var set: ShareableSet = [] for i in input { set.insert(i) } @@ -92,10 +92,10 @@ extension Benchmark { } self.addSimple( - title: "PersistentSet insert, shared", + title: "ShareableSet insert, shared", input: [Int].self ) { input in - var set: PersistentSet = [] + var set: ShareableSet = [] for i in input { let copy = set set.insert(i) @@ -105,26 +105,11 @@ extension Benchmark { blackHole(set) } - self.add( - title: "PersistentSet insert one + subtract, shared", - input: [Int].self - ) { input in - let original = PersistentSet(input) - let newMember = input.count - return { timer in - var copy = original - copy.insert(newMember) - let diff = copy.subtracting(original) - precondition(diff.count == 1 && diff.first == newMember) - blackHole(copy) - } - } - self.addSimple( - title: "PersistentSet model diffing", + title: "ShareableSet model diffing", input: Int.self ) { input in - typealias Model = PersistentSet + typealias Model = ShareableSet var _state: Model = [] // Private func updateState( @@ -145,11 +130,11 @@ extension Benchmark { } self.add( - title: "PersistentSet remove", + title: "ShareableSet 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 +144,11 @@ extension Benchmark { } self.add( - title: "PersistentSet remove, shared", + title: "ShareableSet 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) @@ -184,58 +169,68 @@ extension Benchmark { // SetAlgebra operations with Self do { - for (percentage, start) in overlaps { - self.add( - title: "PersistentSet 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) - return { timer in - blackHole(a.union(identity(b))) - } + func makeB( + _ a: ShareableSet, _ range: Range, shared: Bool + ) -> ShareableSet { + guard shared else { + return ShareableSet(range) } + var b = a + b.subtract(0 ..< range.lowerBound) + b.formUnion(range) + return b } for (percentage, start) in overlaps { - self.add( - title: "PersistentSet 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) - return { timer in - blackHole(a.intersection(identity(b))) - } - } - } + for shared in [false, true] { + let qualifier = "\(percentage) overlap, \(shared ? "shared" : "distinct")" - for (percentage, start) in overlaps { - self.add( - title: "PersistentSet 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) - return { timer in - blackHole(a.symmetricDifference(identity(b))) + self.add( + title: "ShareableSet union with Self (\(qualifier))", + input: [Int].self + ) { input in + let start = start(input.count) + let a = ShareableSet(input) + let b = makeB(a, start ..< start + input.count, shared: shared) + return { timer in + blackHole(a.union(identity(b))) + } } - } - } - for (percentage, start) in overlaps { - self.add( - title: "PersistentSet 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) - return { timer in - blackHole(a.subtracting(identity(b))) + self.add( + title: "ShareableSet intersection with Self (\(qualifier))", + input: [Int].self + ) { input in + let start = start(input.count) + let a = ShareableSet(input) + let b = makeB(a, start ..< start + input.count, shared: shared) + return { timer in + blackHole(a.intersection(identity(b))) + } + } + + self.add( + title: "ShareableSet symmetricDifference with Self (\(qualifier))", + input: [Int].self + ) { input in + let start = start(input.count) + let a = ShareableSet(input) + let b = makeB(a, start ..< start + input.count, shared: shared) + return { timer in + blackHole(a.symmetricDifference(identity(b))) + } + } + + self.add( + title: "ShareableSet subtracting Self (\(qualifier))", + input: [Int].self + ) { input in + let start = start(input.count) + let a = ShareableSet(input) + let b = makeB(a, start ..< start + input.count, shared: shared) + return { timer in + blackHole(a.subtracting(identity(b))) + } } } } @@ -245,11 +240,11 @@ extension Benchmark { do { for (percentage, start) in overlaps { self.add( - title: "PersistentSet union with Array (\(percentage) overlap)", + title: "ShareableSet 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 +254,11 @@ extension Benchmark { for (percentage, start) in overlaps { self.add( - title: "PersistentSet intersection with Array (\(percentage) overlap)", + title: "ShareableSet 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 +268,11 @@ extension Benchmark { for (percentage, start) in overlaps { self.add( - title: "PersistentSet symmetricDifference with Array (\(percentage) overlap)", + title: "ShareableSet 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 +282,11 @@ extension Benchmark { for (percentage, start) in overlaps { self.add( - title: "PersistentSet subtracting Array (\(percentage) overlap)", + title: "ShareableSet 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))) @@ -302,70 +297,80 @@ extension Benchmark { // SetAlgebra mutations with Self do { - for (percentage, start) in overlaps { - self.add( - title: "PersistentSet formUnion with Self (\(percentage) overlap)", - input: [Int].self - ) { input in - let start = start(input.count) - let b = PersistentSet(start ..< start + input.count) - return { timer in - var a = PersistentSet(input) - timer.measure { - a.formUnion(identity(b)) - } - blackHole(a) - } + func makeB( + _ a: ShareableSet, _ range: Range, shared: Bool + ) -> ShareableSet { + guard shared else { + return ShareableSet(range) } + var b = a + b.subtract(0 ..< range.lowerBound) + b.formUnion(range) + return b } for (percentage, start) in overlaps { - self.add( - title: "PersistentSet formIntersection with Self (\(percentage) overlap)", - input: [Int].self - ) { input in - let start = start(input.count) - let b = PersistentSet(start ..< start + input.count) - return { timer in - var a = PersistentSet(input) - timer.measure { - a.formIntersection(identity(b)) - } - blackHole(a) - } - } - } + for shared in [false, true] { + let qualifier = "\(percentage) overlap, \(shared ? "shared" : "distinct")" - for (percentage, start) in overlaps { - self.add( - title: "PersistentSet formSymmetricDifference with Self (\(percentage) overlap)", - input: [Int].self - ) { input in - let start = start(input.count) - let b = PersistentSet(start ..< start + input.count) - return { timer in - var a = PersistentSet(input) - timer.measure { - a.formSymmetricDifference(identity(b)) + self.add( + title: "ShareableSet formUnion with Self (\(qualifier))", + input: [Int].self + ) { input in + let start = start(input.count) + return { timer in + var a = ShareableSet(input) + let b = makeB(a, start ..< start + input.count, shared: shared) + timer.measure { + a.formUnion(identity(b)) + } + blackHole(a) } - blackHole(a) } - } - } - for (percentage, start) in overlaps { - self.add( - title: "PersistentSet subtract Self (\(percentage) overlap)", - input: [Int].self - ) { input in - let start = start(input.count) - let b = PersistentSet(start ..< start + input.count) - return { timer in - var a = PersistentSet(input) - timer.measure { - a.subtract(identity(b)) + self.add( + title: "ShareableSet formIntersection with Self (\(qualifier))", + input: [Int].self + ) { input in + let start = start(input.count) + return { timer in + var a = ShareableSet(input) + let b = makeB(a, start ..< start + input.count, shared: shared) + timer.measure { + a.formIntersection(identity(b)) + } + blackHole(a) + } + } + + self.add( + title: "ShareableSet formSymmetricDifference with Self (\(qualifier))", + input: [Int].self + ) { input in + let start = start(input.count) + return { timer in + var a = ShareableSet(input) + let b = makeB(a, start ..< start + input.count, shared: shared) + timer.measure { + a.formSymmetricDifference(identity(b)) + } + blackHole(a) + } + } + + self.add( + title: "ShareableSet subtract Self (\(qualifier))", + input: [Int].self + ) { input in + let start = start(input.count) + return { timer in + var a = ShareableSet(input) + let b = makeB(a, start ..< start + input.count, shared: shared) + timer.measure { + a.subtract(identity(b)) + } + blackHole(a) } - blackHole(a) } } } @@ -375,13 +380,13 @@ extension Benchmark { do { for (percentage, start) in overlaps { self.add( - title: "PersistentSet formUnion with Array (\(percentage) overlap)", + title: "ShareableSet 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 +397,13 @@ extension Benchmark { for (percentage, start) in overlaps { self.add( - title: "PersistentSet formIntersection with Array (\(percentage) overlap)", + title: "ShareableSet 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 +414,13 @@ extension Benchmark { for (percentage, start) in overlaps { self.add( - title: "PersistentSet formSymmetricDifference with Array (\(percentage) overlap)", + title: "ShareableSet 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 +431,13 @@ extension Benchmark { for (percentage, start) in overlaps { self.add( - title: "PersistentSet subtract Array (\(percentage) overlap)", + title: "ShareableSet 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)) } diff --git a/Benchmarks/Sources/benchmark-tool/main.swift b/Benchmarks/Sources/benchmark-tool/main.swift index 9231fb25..fa89957d 100644 --- a/Benchmarks/Sources/benchmark-tool/main.swift +++ b/Benchmarks/Sources/benchmark-tool/main.swift @@ -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() diff --git a/Benchmarks/Sources/memory-benchmark/MemoryBenchmarks.swift b/Benchmarks/Sources/memory-benchmark/MemoryBenchmarks.swift index b42df2ae..40635b27 100644 --- a/Benchmarks/Sources/memory-benchmark/MemoryBenchmarks.swift +++ b/Benchmarks/Sources/memory-benchmark/MemoryBenchmarks.swift @@ -30,11 +30,11 @@ struct MemoryBenchmarks: ParsableCommand { var i = 0 var d: Dictionary = [:] - var pd: PersistentDictionary = [:] + var pd: ShareableDictionary = [:] print(""" Size,"Dictionary",\ - "PersistentDictionary",\ + "ShareableDictionary",\ "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) diff --git a/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableHashedCollections.md b/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableHashedCollections.md new file mode 100644 index 00000000..c7ef11fc --- /dev/null +++ b/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableHashedCollections.md @@ -0,0 +1,349 @@ +# Shareable Hashed Collections Module + +- Authors: [Michael Steindorfer](https://github.com/msteindorfer), [Karoy Lorentey](https://forums.swift.org/u/lorentey) +- Implementation: https://github.com/apple/swift-collections/tree/release/1.1/Sources/ShareableHashedCollections + +## Table of contents + +* [Introduction](#introduction) +* [Motivation](#motivation) +* [Proposed solution](#proposed-solution) + - [`ShareableSet`](#shareableset) + - [`ShareableDictionary`](#shareabledictionary) +* [Detailed design](#detailed-design) + +## Introduction + +`ShareableHashedCollections` is a new module in Swift Collections, containing new hashed collection types that store their elements in a prefix tree structure, based on their hash values. The new types are tree-based equivalents to the standard `Set` and `Dictionary`; they're called `ShareableSet` and `ShareableDictionary`. + +Like the standard hashed collections, `ShareableSet` and `ShareableDictionary` are unordered collections of unique items. However, the new collections are optimizing for making mutations of shared copies as efficient as practical, both by making such changes faster, but, just as importantly, by letting mutated copies of the same collection value share as much of their structure as possible, saving a considerable amount of memory. + +## Motivation + +Well-behaved Swift collection types are typically expected to implement the copy-on-write optimization: in this scheme, making copies of collection values is an O(1) operation, but the first time one of the copies gets mutated, its storage needs to be made unique. + +In the case of the standard collection types, the only way to make a collection value's storage unique is to copy the entire collection into newly allocated storage. This maintains the illusion of value semantics, but such all-or-nothing copying can lead to undesirable spikes in complexity. Inserting an item will usually take constant time, but if we aren't careful about making copies, it _sometimes_ jumps to linear complexity, which can easily render the code unusably slow, especially when the operation is called inside a loop. + +As a toy example, consider a case of a system where we want to allow the user to arbitrarily mutate a set of integers, then periodically (say, every time we want to refresh the screen) we compare the current set to the one we previously saw, and do something based on the differences. To keep things simple, let's say we are just inserting a sequence of integers one by one, and we want to update the display state after every insertion: + +```swift +typealias Model = Set + +var _state: Model // Private +func updateState( + with model: Model +) -> (insertions: Set, removals: Set) { + let insertions = model.subtracting(_state) + let removals = _state.subtracting(model) + _state = model + return (insertions, removals) +} + +let c = 1_000_000 +var model: Model = [] +for i in 0 ..< c { + model.insert(i) + let r = updateState(with: model) + precondition(r.insertions.count == 1 && r.removals.count = 0) +} +``` + +(Of course, ideally the set would remember precisely what items got inserted/removed in it since the last time a snapshot was made, so calculating the difference would be a trivial operation. But if we aren't able to maintain such a change log, this might be a reasonably pragmatic fallback approach.) + +With the standard `Set` type, having to keep a copy of the model around is inconvenient: it not only makes the first mutation after the `updateState` call slow, but it also roughly doubles the memory that we need to use, as the new version of the model will need to have its own, completely independent storage. Even worse, calculating the differences between the current model and its previous snapshot is quite expensive: we don't have any information about what changed, so the `subtracting` operations need to carefully compare each item one by one -- there aren't any useful shortcuts. + +Overall, the model update and the diffing operations all take time that's proportional to the number of items in the set, making it difficult to update the display state with high enough frequency once the set grows above a certain size. + +This all-or-nothing copy-on-write behavior can be eliminated by organizing the contents of hashed collections into a prefix tree of hash values rather than a single flat hash table. `ShareableSet` and `ShareableDictionary` use tree nodes that contain at most 32 items -- each of which can either be a direct key-value pair, or a reference to a child node containing more items. The nodes themselves work like tiny hash tables themselves: each node along the path from the root to any given item handles 5 bits (2^5 == 32) worth of data from the item's hash value. New nodes get created whenever a new item's hash value matches another's up to the depth currently covered by its path; such collisions are resolved by allocating a new node that looks at 5 more bits' worth of information until the items can be distinguished or we exhaust all available bits in the hash value. (Special collision nodes handle items that fall in the latter case.) + +A key aspect of this structure is that individual nodes can be reference counted, so they can be easily shared across different instances of the same collection type. Copies of collection values can be made just as easily as with the flat hash table -- we just need to make a copy of the reference to the root node, incrementing its reference count. Furthermore, when we need to insert a new item (or remove an existing one) from such a copy, we only need to make copies of the nodes along its path: all other nodes can continue to be linked into both trees. + +This boosts the performance of shared mutations from linear to logarithmic time, bringing along a corresponding improvement to memory use -- two set values that only diverged slightly are still expected to share most of their storage. + +Better, the trees are able to organically grow or shrink their storage to fit their contents: we don't need to think about reserving capacity, and we don't need to worry about temporary spikes in a collection's size inducing a corresponding increase in its size that lingers long after the collection is restored to a more typical size. + +Sharing storage nodes between collection instances also brings about additional benefits: when comparing or combining two sets (or dictionaries), we can easily detect shared nodes and we can typically handle their entire subtree as a single unit, instead of having to individually compare/combine their items. For example, when subtracting one set from another, nodes that are shared between them can simply be skipped when building the result, without even looking at any of their contained items. + +For example, simply changing the model type from `Set` to `ShareableSet` leads to an algorithmic improvement to running time: + +```swift +typealias Model = ShareableSet + +... // Same code as before +``` + +For a million items, the code that uses `Set` would have taken roughly five hours to run; the variant that uses `ShareableCode` runs in about two seconds! + +Plotting the average time spent over one iteration of the loop on a log-log chart, we get the following result: + +![](ShareableSet-model-diffing.png) + +Over the entire spread of item counts from 1 to a million, `Set` goes from 100ns to >10ms spent in each iteration -- an increase of five orders of magnitude, corresponding to a linear growth rate. Meanwhile `PeristentSet`'s growth is kept nicely logarithmic: its 8-10x growth factor is far removed from the growth rate of its input data. + +For this particular use case, hash-array mapped prefix trees proved to be a far better data structure than a flat hash table. Of course, this does not mean that `ShareableSet` is going to always be a better choice than `Set` -- as always, it depends on the use case. + +Maintaining the prefix tree involves a lot more bookkeeping than a flat hash table, including having to descend through multiple nodes when looking up items or iterating through the collection: + +![](ShareableSet-sequential%20iteration.png) + +Not having to think about reserving capacity also means that the tree cannot preallocate nodes in advance, even if we know exactly how many items we will need to insert -- it needs to organically allocate/deallocate nodes as needed. The more complicated structure therefore leads to worse expected behavior (by a constant factor) when the use case cannot exercise the benefits of node sharing, such as when we only mutate a single dictionary in place, without ever making a copy of it. + +![](ShareableSet-insert.png) + +(Still, certain use cases might still accept the constant-factor slowdown in exchange for the freedom of not having to worry about memory management.) + +## Proposed solution + +We propose to introduce a new Swift Collections module, called `ShareableHashedCollections`, with two top-level public types, `ShareableSet` and `ShareableDictionary`. + +### `ShareableSet` + +`ShareableSet` is a type with one generic argument, `Element`, required to be `Hashable`. Like the standard `Set`, `ShareableSet` is a `SetAlgebra` that is a forward-only, unordered `Collection` with an opaque index type. It is `Hashable` and conditionally `Sendable` and `Codable`, depending on its `Element`: + +```swift +struct ShareableSet + : Sequence, Collection, + SetAlgebra, + Equatable, Hashable, + CustomStringConvertible, CustomDebugStringConvertible, CustomReflectable, + ExpressibleByArrayLiteral +{} + +extension ShareableSet: Sendable where Element: Sendable {} +extension ShareableSet: Decodable where Element: Decodable {} +extension ShareableSet: Encodable where Element: Encodable {} +``` + +Internally, `ShareableSet` organizes its elements into a hash-array mapped prefix tree. To speed up indexing operations in such a structure, each index in a `ShareableSet` value contains a direct storage reference to the node within the tree that contains the element addressed. This means that unlike with `Set`, `ShareableSet` indices need to get invalidated on every mutation. + +#### Creating a Set + +```swift +init() +init(S) +init(`Self`) +init(ShareableDictionary.Keys) +``` + +#### Finding Elements + +```swift +func contains(Element) -> Bool +func firstIndex(of: Element) -> Index? +func lastIndex(of: Element) -> Index? +``` + +#### Adding and Updating Elements + +```swift +func insert(Element) -> (inserted: Bool, memberAfterInsert: Element) +func update(with: Element) -> Element? +func update(Element, at: Index) -> Element +``` + +#### Removing Elements + +```swift +func remove(Element) -> Element? +func remove(at: Index) -> Element +func filter((Element) throws -> Bool) rethrows -> ShareableSet +mutating func removeAll(where shouldBeRemoved: (Element) throws -> Bool) rethrows +``` + +#### Combining Sets + +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 `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. + +```swift +func intersection(`Self`) -> ShareableSet +func intersection(ShareableDictionary.Keys) -> ShareableSet +func intersection(S) -> ShareableSet + +func union(`Self`) -> ShareableSet +func union(ShareableDictionary.Keys) -> ShareableSet +func union(S) -> ShareableSet + +func subtracting(`Self`) -> ShareableSet +func subtracting(ShareableDictionary.Keys) -> ShareableSet +func subtracting(S) -> ShareableSet + +func symmetricDifference(`Self`) -> ShareableSet +func symmetricDifference(ShareableDictionary.Keys) -> ShareableSet +func symmetricDifference(S) -> ShareableSet + +func formIntersection(`Self`) +func formIntersection(ShareableDictionary.Keys) +func formIntersection(S) + +func formUnion(`Self`) +func formUnion(ShareableDictionary.Keys) +func formUnion(S) + +func subtract(`Self`) +func subtract(ShareableDictionary.Keys) +func subtract(S) + +func formSymmetricDifference(`Self`) +func formSymmetricDifference(ShareableDictionary.Keys) +func formSymmetricDifference(S) +``` + +#### Comparing Sets + +`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 `ShareableSet` consists of exactly the same members as an arbitrary sequence. Like `==`, the `isEqualSet` functions ignore element ordering and duplicates (if any). + +```swift +static func == (`Self`, `Self`) -> Bool +func isEqualSet(to: `Self`) -> Bool +func isEqualSet(to: ShareableDictionary.Keys) -> Bool +func isEqualSet(to: S) -> Bool + +func isSubset(of: `Self`) -> Bool +func isSubset(of: ShareableDictionary.Keys) -> Bool +func isSubset(of: S) -> Bool + +func isSuperset(of: `Self`) -> Bool +func isSuperset(of: ShareableDictionary.Keys) -> Bool +func isSuperset(of: S) -> Bool + +func isStrictSubset(of: `Self`) -> Bool +func isStrictSubset(of: ShareableDictionary.Keys) -> Bool +func isStrictSubset(of: S) -> Bool + +func isStrictSuperset(of: `Self`) -> Bool +func isStrictSuperset(of: ShareableDictionary.Keys) -> Bool +func isStrictSuperset(of: S) -> Bool + +func isDisjoint(with: `Self`) -> Bool +func isDisjoint(with: ShareableDictionary.Keys) -> Bool +func isDisjoint(with: S) -> Bool +``` + +### `ShareableDictionary` + +`ShareableDictionary` is a type with two generic arguments, `Key` and `Value`, of which `Key` is required to be `Hashable`. Like the standard `Dictionary`, it implements a forward-only, unordered `Collection` of key-value pairs, with custom members providing efficient support for retrieving the value of any given key. `ShareableDictionary` is conditionally `Sendable`, `Codable`, `Equatable` and `Hashable`, depending on its `Key` and `Value` types. + +```swift +struct ShareableDictionary + : Sequence, Collection, + CustomStringConvertible, CustomDebugStringConvertible, CustomReflectable, + ExpressibleByDictionaryLiteral +{} + +extension ShareableDictionary: Sendable where Key: Sendable, Value: Sendable {} +extension ShareableDictionary: Equatable where Value: Equatable {} +extension ShareableDictionary: Hashable where Value: Hashable {} +extension ShareableDictionary: Decodable where Key: Decodable, Value: Decodable {} +extension ShareableDictionary: Encodable where Key: Encodable, Value: Encodable {} +``` + +Internally, `ShareableDictionary` organizes its elements into a hash-array mapped prefix tree. To speed up indexing operations in such a structure, each index in a `ShareableDictionary` value contains a direct storage reference to the node within the tree that contains the element addressed. This means that unlike with `Dictionary`, `ShareableDictionary` indices are invalidated on every mutation, including mutations that only affect a value within the dictionary. + +#### Collection Views + +`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 `ShareableDictionary` needs to invalidate indices on every mutation, its `Values` view is not a `MutableCollection`. + +```swift +ShareableDictionary.Keys +ShareableDictionary.Values + +var keys: Keys +var values: Values + +extension ShareableDictionary.Keys { + func contains(Element) -> Bool + + func intersection(ShareableSet) -> Self + func intersection(ShareableDictionary.Keys) -> Self + + func subtracting(ShareableSet) -> Self + func subtracting(ShareableDictionary.Keys) -> Self +} +``` + +#### Creating a Dictionary + +```swift +init() +init(ShareableDictionary) +init(Dictionary) +init(uniqueKeysWithValues: S) +init(S, uniquingKeysWith: (Value, Value) throws -> Value) rethrows +init(grouping: S, by: (S.Element) throws -> Key) rethrows +init(keys: ShareableSet, valueGenerator: (Key) throws -> Value) rethrows +``` + +#### Inspecting a Dictionary + +```swift +var isEmpty: Bool +var count: Int +``` + +#### Accessing Keys and Values + +```swift +subscript(Key) -> Value? +subscript(Key, default _: () -> Value) -> Value +func index(forKey: Key) -> Index? +``` + +#### Adding or Updating Keys and Values + +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.) `ShareableDictionary` also provides the standard `merge` and `merging` operations for combining dictionary values. + +```swift +func updateValue(Value, forKey: Key) -> Value? +func updateValue(forKey: Key, with: (inout Value?) throws -> R) rethrows -> R +func updateValue(forKey: Key, default: () -> Value, with: (inout Value) throws -> R) rethrows -> R + +func merge(`Self`, uniquingKeysWith: (Value, Value) throws -> Value) rethrows +func merge(S, uniquingKeysWith: (Value, Value) throws -> Value) rethrows + +func merging(`Self`, uniquingKeysWith: (Value, Value) throws -> Value) rethrows -> ShareableDictionary +func merging(S, uniquingKeysWith: (Value, Value) throws -> Value) rethrows -> ShareableDictionary +``` + +#### Removing Keys and Values + +```swift +func removeValue(forKey: Key) -> Value? +func remove(at: Index) -> Element +func filter((Element) throws -> Bool) rethrows -> ShareableDictionary +mutating func removeAll(where shouldBeRemoved: (Element) throws -> Bool) rethrows +``` + +#### Comparing Dictionaries + +```swift +static func == (`Self`, `Self`) -> Bool +``` + +#### Transforming a Dictionary + +```swift +func mapValues((Value) throws -> T) rethrows -> ShareableDictionary +func compactMapValues((Value) throws -> T?) rethrows -> ShareableDictionary +``` + +## Detailed design + +For a precise list of all public APIs in the `ShareableHashedCollections` module, see the DocC documentation that is (temporarily) available at: + +[https://lorentey.github.io/swift-collections/ShareableHashedCollections/documentation/shareablehashedcollections/](https://lorentey.github.io/swift-collections/ShareableHashedCollections/documentation/shareablehashedcollections/) + +Alternatively, you can browse the proposed implementation at: + +[https://github.com/apple/swift-collections/tree/release/1.1/Sources/ShareableHashedCollections](https://github.com/apple/swift-collections/tree/release/1.1/Sources/ShareableHashedCollections) + +## Alternatives Considered + +### Naming + +The initial version of this document proposed to name the new types `PersistentSet` and `PersistentDictionary`, after the term of art "persistent data structure". Based on review feedback, we changed this to the current names. The new names eliminate confusion about the word "persistent", while also preserving the following important properties: + +1. The name succinctly labels the primary feature that distinguishes them from existing collection types in this package and the Standard Library. In our case, this feature is that these types are pretty good at mutating copied values. because they can continue to share parts of their storage with their copies after such mutations. +2. The meaning is still at least _somewhat_ understandable to folks who are familiar with this feature in, say, a purely functional context. (There is a bit of handwaving here -- the precise term "shareable" have never been applied to data structures in this (or from what I can tell, any other) sense. However, pointing out the possibility of shared storage seems to be striking a chord that other options have failed to match.) + +Another widespread preexisting alternative term for such data structures is "immutable"; unfortunately, it is not applicable here. + diff --git a/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableSet-insert.png b/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableSet-insert.png new file mode 100644 index 00000000..450a6749 Binary files /dev/null and b/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableSet-insert.png differ diff --git a/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableSet-model-diffing.png b/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableSet-model-diffing.png new file mode 100644 index 00000000..62cb390a Binary files /dev/null and b/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableSet-model-diffing.png differ diff --git a/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableSet-sequential iteration.png b/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableSet-sequential iteration.png new file mode 100644 index 00000000..1bfe32d6 Binary files /dev/null and b/Documentation/Reviews/2022-10-31.ShareableHashedCollections/ShareableSet-sequential iteration.png differ diff --git a/Package.swift b/Package.swift index 54292671..2f2d13de 100644 --- a/Package.swift +++ b/Package.swift @@ -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, PersistentDictionary + // ShareableSet, ShareableDictionary .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), ] ) diff --git a/README.md b/README.md index 51009808..b14dbd5c 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The package currently provides the following implementations: - [`OrderedDictionary`][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. diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 7db3a61b..05839a57 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -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) diff --git a/Sources/Collections/CMakeLists.txt b/Sources/Collections/CMakeLists.txt index 2a948e7e..86c8abda 100644 --- a/Sources/Collections/CMakeLists.txt +++ b/Sources/Collections/CMakeLists.txt @@ -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}) diff --git a/Sources/Collections/Collections.docc/Collections.md b/Sources/Collections/Collections.docc/Collections.md index c2a559c2..99c301de 100644 --- a/Sources/Collections/Collections.docc/Collections.md +++ b/Sources/Collections/Collections.docc/Collections.md @@ -34,5 +34,5 @@ ### Persistent Collections -- ``PersistentSet`` -- ``PersistentDictionary`` +- ``ShareableSet`` +- ``ShareableDictionary`` diff --git a/Sources/Collections/Collections.docc/Extensions/PersistentDictionary.md b/Sources/Collections/Collections.docc/Extensions/ShareableDictionary.md similarity index 59% rename from Sources/Collections/Collections.docc/Extensions/PersistentDictionary.md rename to Sources/Collections/Collections.docc/Extensions/ShareableDictionary.md index 2fe56d6f..65efd408 100644 --- a/Sources/Collections/Collections.docc/Extensions/PersistentDictionary.md +++ b/Sources/Collections/Collections.docc/Extensions/ShareableDictionary.md @@ -1,4 +1,4 @@ -# ``Collections/PersistentDictionary`` +# ``Collections/ShareableDictionary`` @@ -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`` @@ -28,46 +28,46 @@ mutation, its `Values` view is not a `MutableCollection`. ### Creating a Dictionary - ``init()`` -- ``init(_:)-7jshe`` -- ``init(_:)-8ls8p`` -- ``init(uniqueKeysWithValues:)-65ax0`` -- ``init(uniqueKeysWithValues:)-5ok18`` -- ``init(_:uniquingKeysWith:)-7fuzu`` -- ``init(_:uniquingKeysWith:)-4jee3`` -- ``init(grouping:by:)-8ntzv`` -- ``init(grouping:by:)-7cu86`` +- ``init(_:)-68s80`` +- ``init(_:)-2ngkk`` +- ``init(uniqueKeysWithValues:)-688fi`` +- ``init(uniqueKeysWithValues:)-3h2xe`` +- ``init(_:uniquingKeysWith:)-6t92n`` +- ``init(_:uniquingKeysWith:)-9opgv`` +- ``init(grouping:by:)-6ddmm`` +- ``init(grouping:by:)-9rc24`` - ``init(keys:valueGenerator:)`` ### Inspecting a Dictionary -- ``isEmpty-65s43`` -- ``count-9cdqd`` +- ``isEmpty-25p4`` +- ``count-8s588`` ### Accessing Keys and Values -- ``subscript(_:)-g0oi`` +- ``subscript(_:)-6jbab`` - ``subscript(_:default:)`` - ``index(forKey:)`` ### 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:)`` - ``updateValue(forKey:with:)`` - ``updateValue(forKey:default:with:)`` -- ``merge(_:uniquingKeysWith:)-853bf`` -- ``merge(_:uniquingKeysWith:)-19xxn`` -- ``merge(_:uniquingKeysWith:)-2osh`` -- ``merging(_:uniquingKeysWith:)-2a7cl`` -- ``merging(_:uniquingKeysWith:)-1tq3e`` -- ``merging(_:uniquingKeysWith:)-2kjqq`` +- ``merge(_:uniquingKeysWith:)-218dc`` +- ``merge(_:uniquingKeysWith:)-8gdr2`` +- ``merge(_:uniquingKeysWith:)-6j72k`` +- ``merging(_:uniquingKeysWith:)-88sah`` +- ``merging(_:uniquingKeysWith:)-2qknu`` +- ``merging(_:uniquingKeysWith:)-3hao7`` ### Removing Keys and Values @@ -75,11 +75,6 @@ operation.) `PersistentDictionary` also provides the standard `merge` and - ``remove(at:)`` - ``filter(_:)`` -### Non-mutating Dictionary Operations - -- ``updatingValue(_:forKey:)`` -- ``removingValue(forKey:)`` - ### Comparing Dictionaries - ``==(_:_:)`` diff --git a/Sources/Collections/Collections.docc/Extensions/PersistentSet.md b/Sources/Collections/Collections.docc/Extensions/ShareableSet.md similarity index 66% rename from Sources/Collections/Collections.docc/Extensions/PersistentSet.md rename to Sources/Collections/Collections.docc/Extensions/ShareableSet.md index bfa12980..83a906df 100644 --- a/Sources/Collections/Collections.docc/Extensions/PersistentSet.md +++ b/Sources/Collections/Collections.docc/Extensions/ShareableSet.md @@ -1,11 +1,11 @@ -# ``Collections/PersistentSet`` +# ``Collections/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 @@ -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. @@ -74,9 +74,9 @@ average -- typically they will need to compare against just one member. ### Creating a Set - ``init()`` -- ``init(_:)-6nn9e`` -- ``init(_:)-6qbps`` -- ``init(_:)-30nei`` +- ``init(_:)-1qufh`` +- ``init(_:)-49yo2`` +- ``init(_:)-56pm1`` ### Finding Elements @@ -95,89 +95,80 @@ average -- typically they will need to compare against just one member. - ``remove(_:)`` - ``remove(at:)`` - ``filter(_:)`` - -### Non-mutating Set Operations - -To acknowledge the efficiency of `PersistentSet` 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. - -- ``inserting(_:)`` -- ``updating(with:)`` -- ``removing(_:)`` +- ``removeAll(where:)`` ### Combining Sets 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. -- ``intersection(_:)-9dx2a`` -- ``intersection(_:)-5z4my`` -- ``intersection(_:)-1d4e0`` +- ``intersection(_:)-8few3`` +- ``intersection(_:)-61b7q`` +- ``intersection(_:)-2ncm4`` -- ``union(_:)-1nk1t`` -- ``union(_:)-8otnp`` -- ``union(_:)-6eysm`` +- ``union(_:)-3e3nw`` +- ``union(_:)-8twku`` +- ``union(_:)-9f4y4`` -- ``subtracting(_:)-8sczx`` -- ``subtracting(_:)-2iv0a`` -- ``subtracting(_:)-63bfb`` +- ``subtracting(_:)-6v3hx`` +- ``subtracting(_:)-zt78`` +- ``subtracting(_:)-9n0oc`` -- ``symmetricDifference(_:)-76bw`` -- ``symmetricDifference(_:)-92ha9`` -- ``symmetricDifference(_:)-1n89g`` +- ``symmetricDifference(_:)-7o2iv`` +- ``symmetricDifference(_:)-3jhi3`` +- ``symmetricDifference(_:)-2hxgg`` -- ``formIntersection(_:)-4s0od`` -- ``formIntersection(_:)-7dqfx`` -- ``formIntersection(_:)-8i59p`` +- ``formIntersection(_:)-48ki1`` +- ``formIntersection(_:)-8qfxe`` +- ``formIntersection(_:)-nne6`` -- ``formUnion(_:)-68pog`` -- ``formUnion(_:)-82rrc`` -- ``formUnion(_:)-4r7qz`` +- ``formUnion(_:)-1qwuq`` +- ``formUnion(_:)-2raoj`` +- ``formUnion(_:)-ew7g`` -- ``subtract(_:)-7rmd3`` -- ``subtract(_:)-47r93`` -- ``subtract(_:)-3v8ms`` +- ``subtract(_:)-24txa`` +- ``subtract(_:)-69g3`` +- ``subtract(_:)-5l8bb`` -- ``formSymmetricDifference(_:)-499uq`` -- ``formSymmetricDifference(_:)-8wue8`` -- ``formSymmetricDifference(_:)-4t8jr`` +- ``formSymmetricDifference(_:)-6zqa1`` +- ``formSymmetricDifference(_:)-mv0q`` +- ``formSymmetricDifference(_:)-2qzlu`` ### 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`` -- ``isEqualSet(to:)-4t0k5`` -- ``isEqualSet(to:)-7s0cu`` +- ``isEqualSet(to:)-5lpwv`` +- ``isEqualSet(to:)-6ont2`` +- ``isEqualSet(to:)-58q8h`` -- ``isSubset(of:)-9mp7l`` -- ``isSubset(of:)-2jlh`` -- ``isSubset(of:)-8vn0j`` +- ``isSubset(of:)-2itju`` +- ``isSubset(of:)-2nice`` +- ``isSubset(of:)-8qszd`` -- ``isSuperset(of:)-5af8o`` -- ``isSuperset(of:)-6mvxj`` -- ``isSuperset(of:)-864jy`` +- ``isSuperset(of:)-9mp0j`` +- ``isSuperset(of:)-3pm0f`` +- ``isSuperset(of:)-63haf`` -- ``isStrictSubset(of:)-48nx2`` -- ``isStrictSubset(of:)-2j680`` -- ``isStrictSubset(of:)-1s6n9`` +- ``isStrictSubset(of:)-1cdr`` +- ``isStrictSubset(of:)-3xlgn`` +- ``isStrictSubset(of:)-8oyb4`` -- ``isStrictSuperset(of:)-nd5j`` -- ``isStrictSuperset(of:)-5z263`` -- ``isStrictSuperset(of:)-ivbh`` +- ``isStrictSuperset(of:)-7qgvz`` +- ``isStrictSuperset(of:)-3fdsl`` +- ``isStrictSuperset(of:)-2ujyn`` -- ``isDisjoint(with:)-12irx`` -- ``isDisjoint(with:)-1hhyf`` -- ``isDisjoint(with:)-61lde`` +- ``isDisjoint(with:)-eq16`` +- ``isDisjoint(with:)-8bgbj`` +- ``isDisjoint(with:)-5b64c`` diff --git a/Sources/Collections/Collections.swift b/Sources/Collections/Collections.swift index 3d138e4b..d3889cc3 100644 --- a/Sources/Collections/Collections.swift +++ b/Sources/Collections/Collections.swift @@ -13,4 +13,4 @@ @_exported import DequeModule @_exported import HeapModule @_exported import OrderedCollections -@_exported import PersistentCollections +@_exported import ShareableHashedCollections diff --git a/Sources/PersistentCollections/CMakeLists.txt b/Sources/PersistentCollections/CMakeLists.txt deleted file mode 100644 index 544cd601..00000000 --- a/Sources/PersistentCollections/CMakeLists.txt +++ /dev/null @@ -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) diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Fluent Operations.swift b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Fluent Operations.swift deleted file mode 100644 index 57eaf17c..00000000 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Fluent Operations.swift +++ /dev/null @@ -1,61 +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 -// -//===----------------------------------------------------------------------===// - -extension PersistentDictionary { - /// Return a new dictionary that has the specified key-value pair in addition - /// to all existing elements in this dictionary. - /// - /// If `self` already contains the given key, then the result replaces its - /// original value in `self` with `value`, without updating the existing key. - /// (In some cases, equal keys may be distinguishable from each other by - /// identity comparison or some other means.) - /// - /// - Parameters: - /// - value: The new value to add to the dictionary. - /// - key: The key to associate with `value`. If `key` already exists in - /// the dictionary, `value` replaces the existing associated value in the - /// result. If `key` isn't already a key of the dictionary, then the - /// `(key, value)` pair is added to the result. - /// - /// - Returns: A new dictionary with the update applied. - /// - /// - Complexity: This operation is expected to copy at most O(log(`count`)) - /// existing members and to perform at most O(1) hashing/comparison - /// operations on the `Element` type, as long as `Element` properly - /// implements hashing. - @inlinable - public func updatingValue(_ value: Value, forKey key: Key) -> Self { - var copy = self - copy.updateValue(value, forKey: key) - return copy - } - - /// Return a new dictionary that contains all key-value pairs that are in - /// this dictionary except for the pair that matches given `key`. - /// - /// If this dictionary does not contain a value for `key`, then this - /// method simply returns `self`. - /// - /// - Parameter key: The key to remove from the returned dictionary. - /// - /// - Returns: A new dictionary with all existing key-value pairs in `self` - /// except for the one that matches `key` (if any). - /// - /// - Complexity: This operation is expected to copy at most O(log(`count`)) - /// existing members and to perform at most O(1) hashing/comparison - /// operations on the `Element` type, as long as `Element` properly - /// implements hashing. - @inlinable - public func removingValue(forKey key: Key) -> Self { - guard let r = _root.removing(.top, key, _Hash(key)) else { return self } - return Self(_new: r.replacement.finalize(.top)) - } -} diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra fluent basics.swift b/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra fluent basics.swift deleted file mode 100644 index 796ee066..00000000 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra fluent basics.swift +++ /dev/null @@ -1,77 +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 -// -//===----------------------------------------------------------------------===// - -extension PersistentSet { - /// Return a new set that contains `newMember` in addition to all existing - /// elements in this set. - /// - /// If `self` already contains `newMember`, then this simply returns `self`. - /// - /// - Parameter newMember: The element to insert into the set. - /// - /// - Returns: A new set containing `newMember` and all existing members of - /// `self`. - /// - /// - Complexity: This operation is expected to copy at most O(log(`count`)) - /// existing members and to perform at most O(1) hashing/comparison - /// operations on the `Element` type, as long as `Element` properly - /// implements hashing. - @inlinable - public func inserting(_ newMember: __owned Element) -> Self { - let hash = _Hash(newMember) - let r = _root.inserting(.top, (newMember, ()), hash) - return PersistentSet(_new: r.node) - } - - /// Return a new set that contains all members of this set except `member`. - /// - /// If `self` does not contain `member`, then this simply returns `self`. - /// - /// - Parameter member: The element to remove. - /// - /// - Returns: A new set with all existing members of `self` except `member`. - /// - /// - Complexity: This operation is expected to copy at most O(log(`count`)) - /// existing members and to perform at most O(1) hashing/comparison - /// operations on the `Element` type, as long as `Element` properly - /// implements hashing. - @inlinable - public func removing(_ member: Element) -> Self { - let hash = _Hash(member) - 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 a new set that contains `newMember` in addition to all members of - /// this set. - /// - /// If an element equal to `newMember` is already contained in this set, - /// then `newMember` replaces the existing element in the returned result. - /// In some cases, the original element may be distinguishable from - /// `newMember` by identity comparison or some other means. - /// - /// - Parameter newMember: An element to update in the set. - /// - /// - Returns: A new set containing all existing members and `newMember`. - /// - /// - Complexity: This operation is expected to copy at most O(log(`count`)) - /// existing members and to perform at most O(1) hashing/comparison - /// operations on the `Element` type, as long as `Element` properly - /// implements hashing. - @inlinable - public func updating(with newMember: __owned Element) -> Self { - var copy = self - copy.update(with: newMember) - return copy - } -} diff --git a/Sources/ShareableHashedCollections/CMakeLists.txt b/Sources/ShareableHashedCollections/CMakeLists.txt new file mode 100644 index 00000000..3ce2da64 --- /dev/null +++ b/Sources/ShareableHashedCollections/CMakeLists.txt @@ -0,0 +1,103 @@ +#[[ +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+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 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) diff --git a/Sources/PersistentCollections/Node/_AncestorSlots.swift b/Sources/ShareableHashedCollections/Node/_AncestorSlots.swift similarity index 100% rename from Sources/PersistentCollections/Node/_AncestorSlots.swift rename to Sources/ShareableHashedCollections/Node/_AncestorSlots.swift diff --git a/Sources/PersistentCollections/Node/_Bitmap.swift b/Sources/ShareableHashedCollections/Node/_Bitmap.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Bitmap.swift rename to Sources/ShareableHashedCollections/Node/_Bitmap.swift diff --git a/Sources/PersistentCollections/Node/_Bucket.swift b/Sources/ShareableHashedCollections/Node/_Bucket.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Bucket.swift rename to Sources/ShareableHashedCollections/Node/_Bucket.swift diff --git a/Sources/PersistentCollections/Node/_Hash.swift b/Sources/ShareableHashedCollections/Node/_Hash.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Hash.swift rename to Sources/ShareableHashedCollections/Node/_Hash.swift diff --git a/Sources/PersistentCollections/Node/_HashTreeIterator.swift b/Sources/ShareableHashedCollections/Node/_HashTreeIterator.swift similarity index 100% rename from Sources/PersistentCollections/Node/_HashTreeIterator.swift rename to Sources/ShareableHashedCollections/Node/_HashTreeIterator.swift diff --git a/Sources/PersistentCollections/Node/_HashTreeStatistics.swift b/Sources/ShareableHashedCollections/Node/_HashTreeStatistics.swift similarity index 100% rename from Sources/PersistentCollections/Node/_HashTreeStatistics.swift rename to Sources/ShareableHashedCollections/Node/_HashTreeStatistics.swift diff --git a/Sources/PersistentCollections/Node/_Level.swift b/Sources/ShareableHashedCollections/Node/_Level.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Level.swift rename to Sources/ShareableHashedCollections/Node/_Level.swift diff --git a/Sources/PersistentCollections/Node/_Node+Builder.swift b/Sources/ShareableHashedCollections/Node/_Node+Builder.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Builder.swift rename to Sources/ShareableHashedCollections/Node/_Node+Builder.swift diff --git a/Sources/PersistentCollections/Node/_Node+Debugging.swift b/Sources/ShareableHashedCollections/Node/_Node+Debugging.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Debugging.swift rename to Sources/ShareableHashedCollections/Node/_Node+Debugging.swift diff --git a/Sources/PersistentCollections/Node/_Node+Initializers.swift b/Sources/ShareableHashedCollections/Node/_Node+Initializers.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Initializers.swift rename to Sources/ShareableHashedCollections/Node/_Node+Initializers.swift diff --git a/Sources/PersistentCollections/Node/_Node+Invariants.swift b/Sources/ShareableHashedCollections/Node/_Node+Invariants.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Invariants.swift rename to Sources/ShareableHashedCollections/Node/_Node+Invariants.swift diff --git a/Sources/PersistentCollections/Node/_Node+Lookups.swift b/Sources/ShareableHashedCollections/Node/_Node+Lookups.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Lookups.swift rename to Sources/ShareableHashedCollections/Node/_Node+Lookups.swift diff --git a/Sources/PersistentCollections/Node/_Node+Primitive Insertions.swift b/Sources/ShareableHashedCollections/Node/_Node+Primitive Insertions.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Primitive Insertions.swift rename to Sources/ShareableHashedCollections/Node/_Node+Primitive Insertions.swift diff --git a/Sources/PersistentCollections/Node/_Node+Primitive Removals.swift b/Sources/ShareableHashedCollections/Node/_Node+Primitive Removals.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Primitive Removals.swift rename to Sources/ShareableHashedCollections/Node/_Node+Primitive Removals.swift diff --git a/Sources/PersistentCollections/Node/_Node+Primitive Replacement.swift b/Sources/ShareableHashedCollections/Node/_Node+Primitive Replacement.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Primitive Replacement.swift rename to Sources/ShareableHashedCollections/Node/_Node+Primitive Replacement.swift diff --git a/Sources/PersistentCollections/Node/_Node+Storage.swift b/Sources/ShareableHashedCollections/Node/_Node+Storage.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Storage.swift rename to Sources/ShareableHashedCollections/Node/_Node+Storage.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural compactMapValues.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural compactMapValues.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural compactMapValues.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural compactMapValues.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural filter.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural filter.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural filter.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural filter.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural intersection.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural intersection.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural intersection.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural intersection.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural isDisjoint.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural isDisjoint.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural isDisjoint.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural isDisjoint.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural isEqualSet.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural isEqualSet.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural isEqualSet.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural isEqualSet.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural isSubset.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural isSubset.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural isSubset.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural isSubset.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural mapValues.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural mapValues.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural mapValues.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural mapValues.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural merge.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural merge.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural merge.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural merge.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural subtracting.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural subtracting.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural subtracting.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural subtracting.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural symmetricDifference.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural symmetricDifference.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural symmetricDifference.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural symmetricDifference.swift diff --git a/Sources/PersistentCollections/Node/_Node+Structural union.swift b/Sources/ShareableHashedCollections/Node/_Node+Structural union.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Structural union.swift rename to Sources/ShareableHashedCollections/Node/_Node+Structural union.swift diff --git a/Sources/PersistentCollections/Node/_Node+Subtree Insertions.swift b/Sources/ShareableHashedCollections/Node/_Node+Subtree Insertions.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Subtree Insertions.swift rename to Sources/ShareableHashedCollections/Node/_Node+Subtree Insertions.swift diff --git a/Sources/PersistentCollections/Node/_Node+Subtree Modify.swift b/Sources/ShareableHashedCollections/Node/_Node+Subtree Modify.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Subtree Modify.swift rename to Sources/ShareableHashedCollections/Node/_Node+Subtree Modify.swift diff --git a/Sources/PersistentCollections/Node/_Node+Subtree Removals.swift b/Sources/ShareableHashedCollections/Node/_Node+Subtree Removals.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+Subtree Removals.swift rename to Sources/ShareableHashedCollections/Node/_Node+Subtree Removals.swift diff --git a/Sources/PersistentCollections/Node/_Node+UnsafeHandle.swift b/Sources/ShareableHashedCollections/Node/_Node+UnsafeHandle.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node+UnsafeHandle.swift rename to Sources/ShareableHashedCollections/Node/_Node+UnsafeHandle.swift diff --git a/Sources/PersistentCollections/Node/_Node.swift b/Sources/ShareableHashedCollections/Node/_Node.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Node.swift rename to Sources/ShareableHashedCollections/Node/_Node.swift diff --git a/Sources/PersistentCollections/Node/_RawNode+UnsafeHandle.swift b/Sources/ShareableHashedCollections/Node/_RawNode+UnsafeHandle.swift similarity index 100% rename from Sources/PersistentCollections/Node/_RawNode+UnsafeHandle.swift rename to Sources/ShareableHashedCollections/Node/_RawNode+UnsafeHandle.swift diff --git a/Sources/PersistentCollections/Node/_RawNode.swift b/Sources/ShareableHashedCollections/Node/_RawNode.swift similarity index 100% rename from Sources/PersistentCollections/Node/_RawNode.swift rename to Sources/ShareableHashedCollections/Node/_RawNode.swift diff --git a/Sources/PersistentCollections/Node/_Slot.swift b/Sources/ShareableHashedCollections/Node/_Slot.swift similarity index 100% rename from Sources/PersistentCollections/Node/_Slot.swift rename to Sources/ShareableHashedCollections/Node/_Slot.swift diff --git a/Sources/PersistentCollections/Node/_Stack.swift b/Sources/ShareableHashedCollections/Node/_Stack.swift similarity index 99% rename from Sources/PersistentCollections/Node/_Stack.swift rename to Sources/ShareableHashedCollections/Node/_Stack.swift index d862e92b..de443adc 100644 --- a/Sources/PersistentCollections/Node/_Stack.swift +++ b/Sources/ShareableHashedCollections/Node/_Stack.swift @@ -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 { diff --git a/Sources/PersistentCollections/Node/_StorageHeader.swift b/Sources/ShareableHashedCollections/Node/_StorageHeader.swift similarity index 100% rename from Sources/PersistentCollections/Node/_StorageHeader.swift rename to Sources/ShareableHashedCollections/Node/_StorageHeader.swift diff --git a/Sources/PersistentCollections/Node/_UnmanagedNode.swift b/Sources/ShareableHashedCollections/Node/_UnmanagedNode.swift similarity index 100% rename from Sources/PersistentCollections/Node/_UnmanagedNode.swift rename to Sources/ShareableHashedCollections/Node/_UnmanagedNode.swift diff --git a/Sources/PersistentCollections/Node/_UnsafePath.swift b/Sources/ShareableHashedCollections/Node/_UnsafePath.swift similarity index 100% rename from Sources/PersistentCollections/Node/_UnsafePath.swift rename to Sources/ShareableHashedCollections/Node/_UnsafePath.swift diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Codable.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Codable.swift similarity index 97% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Codable.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Codable.swift index 11dd98b0..424651fe 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Codable.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Codable.swift @@ -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. diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Collection.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Collection.swift similarity index 92% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Collection.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Collection.swift index 51341042..e84b3902 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Collection.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Collection.swift @@ -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. diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+CustomReflectable.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+CustomReflectable.swift similarity index 91% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+CustomReflectable.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+CustomReflectable.swift index 8d967200..481970d7 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+CustomReflectable.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+CustomReflectable.swift @@ -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) diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Debugging.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Debugging.swift similarity index 97% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Debugging.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Debugging.swift index 65e7a49b..5c3a552a 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Debugging.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Debugging.swift @@ -11,7 +11,7 @@ import _CollectionsUtilities -extension PersistentDictionary { +extension ShareableDictionary { /// True if consistency checking is enabled in the implementation of this /// type, false otherwise. /// diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Descriptions.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Descriptions.swift similarity index 83% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Descriptions.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Descriptions.swift index 6e16251e..cb986ec0 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Descriptions.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Descriptions.swift @@ -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)>" } } diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Equatable.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Equatable.swift similarity index 92% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Equatable.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Equatable.swift index e2c01e0b..8a745e04 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Equatable.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Equatable.swift @@ -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 diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+ExpressibleByDictionaryLiteral.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+ExpressibleByDictionaryLiteral.swift similarity index 95% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+ExpressibleByDictionaryLiteral.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+ExpressibleByDictionaryLiteral.swift index fa7cc08f..e9776d8f 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+ExpressibleByDictionaryLiteral.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+ExpressibleByDictionaryLiteral.swift @@ -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. diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Filter.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Filter.swift similarity index 51% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Filter.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Filter.swift index 823e4922..7fcb2bbb 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Filter.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Filter.swift @@ -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,31 @@ 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)) } + + /// Removes all the elements that satisfy the given predicate. + /// + /// Use this method to remove every element in the dictionary that meets + /// particular criteria. + /// This example removes all the odd valued items from a + /// dictionary mapping strings to numbers: + /// + /// var numbers: ShareableDictionary = ["a": 5, "b": 6, "c": 7, "d": 8] + /// numbers.removeAll(where: { $0.value % 2 != 0 }) + /// // numbers == ["b": 6, "d": 8] + /// + /// - Parameter shouldBeRemoved: A closure that takes an element of the + /// dictionary as its argument and returns a Boolean value indicating + /// whether the element should be removed from the collection. + /// + /// - Complexity: O(`count`) + @inlinable + public mutating func removeAll( + where shouldBeRemoved: (Element) throws -> Bool + ) rethrows { + // FIXME: Implement in-place reductions + self = try filter { try !shouldBeRemoved($0) } + } + } diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Hashable.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Hashable.swift similarity index 93% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Hashable.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Hashable.swift index 6d230aaa..8e27d527 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Hashable.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Hashable.swift @@ -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. /// diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Initializers.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Initializers.swift similarity index 95% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Initializers.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Initializers.swift index 5818b2e2..d4780053 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Initializers.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Initializers.swift @@ -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) { + public init(_ other: ShareableDictionary) { self = other } @@ -45,7 +45,7 @@ extension PersistentDictionary { /// - Complexity: O(`other.count`) @inlinable public init( - keys: PersistentSet, + keys: ShareableSet, 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' diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Keys.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Keys.swift similarity index 79% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Keys.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Keys.swift index 7ad05ae6..2143e178 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Keys.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Keys.swift @@ -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 + internal typealias _Node = ShareableHashedCollections._Node @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( - _ other: PersistentDictionary.Keys + _ other: ShareableDictionary.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) -> Self { + public func intersection(_ other: ShareableSet) -> 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( - _ other: PersistentDictionary.Keys + _ other: ShareableDictionary.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) -> Self { + public func subtracting(_ other: ShareableSet) -> Self { guard let r = _base._root.subtracting(.top, other._root) else { return self } - return PersistentDictionary(_new: r).keys + return ShareableDictionary(_new: r).keys } } diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+MapValues.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+MapValues.swift similarity index 87% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+MapValues.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+MapValues.swift index 499286e5..7b74cd4c 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+MapValues.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+MapValues.swift @@ -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( _ transform: (Value) throws -> T - ) rethrows -> PersistentDictionary { + ) rethrows -> ShareableDictionary { let transformed = try _root.mapValues { try transform($0.value) } - return PersistentDictionary(_new: transformed) + return ShareableDictionary(_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( _ transform: (Value) throws -> T? - ) rethrows -> PersistentDictionary { + ) rethrows -> ShareableDictionary { let result = try _root.compactMapValues(.top, transform) - return PersistentDictionary(_new: result.finalize(.top)) + return ShareableDictionary(_new: result.finalize(.top)) } } diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Merge.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Merge.swift similarity index 97% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Merge.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Merge.swift index 520fa8bc..ace32cbb 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Merge.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Merge.swift @@ -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 } diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sendable.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Sendable.swift similarity index 90% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sendable.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Sendable.swift index b53df23b..00e56919 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sendable.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Sendable.swift @@ -10,6 +10,6 @@ //===----------------------------------------------------------------------===// #if swift(>=5.5) -extension PersistentDictionary: @unchecked Sendable +extension ShareableDictionary: @unchecked Sendable where Key: Sendable, Value: Sendable {} #endif diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sequence.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Sequence.swift similarity index 92% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sequence.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Sequence.swift index bf600835..c03469cc 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sequence.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Sequence.swift @@ -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) diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Values.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Values.swift similarity index 80% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Values.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Values.swift index 1f593755..b48ef468 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Values.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary+Values.swift @@ -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 + internal typealias _Node = ShareableHashedCollections._Node @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) diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary.swift b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary.swift similarity index 95% rename from Sources/PersistentCollections/PersistentDictionary/PersistentDictionary.swift rename to Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary.swift index 86286bfa..cb157b0e 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary.swift +++ b/Sources/ShareableHashedCollections/ShareableDictionary/ShareableDictionary.swift @@ -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 { +public struct ShareableDictionary { @usableFromInline - internal typealias _Node = PersistentCollections._Node + internal typealias _Node = ShareableHashedCollections._Node @usableFromInline internal typealias _UnsafeHandle = _Node.UnsafeHandle @@ -90,7 +90,7 @@ public struct PersistentDictionary { } } -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 = [:] + /// var letterCounts: ShareableDictionary = [:] /// 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 = [:] + /// var letterCounts: ShareableDictionary = [:] /// 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 = [:] + /// var letterCounts: ShareableDictionary = [:] /// 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] diff --git a/Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentDictionary.md b/Sources/ShareableHashedCollections/ShareableHashedCollections.docc/Extensions/ShareableDictionary.md similarity index 58% rename from Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentDictionary.md rename to Sources/ShareableHashedCollections/ShareableHashedCollections.docc/Extensions/ShareableDictionary.md index 92c4673e..96895b8c 100644 --- a/Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentDictionary.md +++ b/Sources/ShareableHashedCollections/ShareableHashedCollections.docc/Extensions/ShareableDictionary.md @@ -1,4 +1,4 @@ -# ``PersistentCollections/PersistentDictionary`` +# ``ShareableHashedCollections/ShareableDictionary`` @@ -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`` @@ -25,46 +25,46 @@ mutation, its `Values` view is not a `MutableCollection`. ### Creating a Dictionary - ``init()`` -- ``init(_:)-7jshe`` -- ``init(_:)-8ls8p`` -- ``init(uniqueKeysWithValues:)-65ax0`` -- ``init(uniqueKeysWithValues:)-5ok18`` -- ``init(_:uniquingKeysWith:)-7fuzu`` -- ``init(_:uniquingKeysWith:)-4jee3`` -- ``init(grouping:by:)-8ntzv`` -- ``init(grouping:by:)-7cu86`` +- ``init(_:)-68s80`` +- ``init(_:)-2ngkk`` +- ``init(uniqueKeysWithValues:)-688fi`` +- ``init(uniqueKeysWithValues:)-3h2xe`` +- ``init(_:uniquingKeysWith:)-6t92n`` +- ``init(_:uniquingKeysWith:)-9opgv`` +- ``init(grouping:by:)-6ddmm`` +- ``init(grouping:by:)-9rc24`` - ``init(keys:valueGenerator:)`` ### Inspecting a Dictionary -- ``isEmpty-65s43`` -- ``count-9cdqd`` +- ``isEmpty-25p4`` +- ``count-8s588`` ### Accessing Keys and Values -- ``subscript(_:)-g0oi`` +- ``subscript(_:)-6jbab`` - ``subscript(_:default:)`` - ``index(forKey:)`` ### 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:)`` - ``updateValue(forKey:with:)`` - ``updateValue(forKey:default:with:)`` -- ``merge(_:uniquingKeysWith:)-853bf`` -- ``merge(_:uniquingKeysWith:)-19xxn`` -- ``merge(_:uniquingKeysWith:)-2osh`` -- ``merging(_:uniquingKeysWith:)-2a7cl`` -- ``merging(_:uniquingKeysWith:)-1tq3e`` -- ``merging(_:uniquingKeysWith:)-2kjqq`` +- ``merge(_:uniquingKeysWith:)-218dc`` +- ``merge(_:uniquingKeysWith:)-8gdr2`` +- ``merge(_:uniquingKeysWith:)-6j72k`` +- ``merging(_:uniquingKeysWith:)-88sah`` +- ``merging(_:uniquingKeysWith:)-2qknu`` +- ``merging(_:uniquingKeysWith:)-3hao7`` ### Removing Keys and Values @@ -72,11 +72,6 @@ operation.) `PersistentDictionary` also provides the standard `merge` and - ``remove(at:)`` - ``filter(_:)`` -### Non-mutating Dictionary Operations - -- ``updatingValue(_:forKey:)`` -- ``removingValue(forKey:)`` - ### Comparing Dictionaries - ``==(_:_:)`` diff --git a/Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentSet.md b/Sources/ShareableHashedCollections/ShareableHashedCollections.docc/Extensions/ShareableSet.md similarity index 66% rename from Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentSet.md rename to Sources/ShareableHashedCollections/ShareableHashedCollections.docc/Extensions/ShareableSet.md index f19ede36..23bd8ce8 100644 --- a/Sources/PersistentCollections/PersistentCollections.docc/Extensions/PersistentSet.md +++ b/Sources/ShareableHashedCollections/ShareableHashedCollections.docc/Extensions/ShareableSet.md @@ -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. @@ -71,9 +71,9 @@ average -- typically they will need to compare against just one member. ### Creating a Set - ``init()`` -- ``init(_:)-6nn9e`` -- ``init(_:)-6qbps`` -- ``init(_:)-30nei`` +- ``init(_:)-1qufh`` +- ``init(_:)-49yo2`` +- ``init(_:)-56pm1`` ### Finding Elements @@ -92,89 +92,80 @@ average -- typically they will need to compare against just one member. - ``remove(_:)`` - ``remove(at:)`` - ``filter(_:)`` - -### Non-mutating Set Operations - -To acknowledge the efficiency of `PersistentSet` 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. - -- ``inserting(_:)`` -- ``updating(with:)`` -- ``removing(_:)`` +- ``removeAll(where:)`` ### Combining Sets 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. -- ``intersection(_:)-9dx2a`` -- ``intersection(_:)-5z4my`` -- ``intersection(_:)-1d4e0`` +- ``intersection(_:)-8few3`` +- ``intersection(_:)-61b7q`` +- ``intersection(_:)-2ncm4`` -- ``union(_:)-1nk1t`` -- ``union(_:)-8otnp`` -- ``union(_:)-6eysm`` +- ``union(_:)-3e3nw`` +- ``union(_:)-8twku`` +- ``union(_:)-9f4y4`` -- ``subtracting(_:)-8sczx`` -- ``subtracting(_:)-2iv0a`` -- ``subtracting(_:)-63bfb`` +- ``subtracting(_:)-6v3hx`` +- ``subtracting(_:)-zt78`` +- ``subtracting(_:)-9n0oc`` -- ``symmetricDifference(_:)-76bw`` -- ``symmetricDifference(_:)-92ha9`` -- ``symmetricDifference(_:)-1n89g`` +- ``symmetricDifference(_:)-7o2iv`` +- ``symmetricDifference(_:)-3jhi3`` +- ``symmetricDifference(_:)-2hxgg`` -- ``formIntersection(_:)-4s0od`` -- ``formIntersection(_:)-7dqfx`` -- ``formIntersection(_:)-8i59p`` +- ``formIntersection(_:)-48ki1`` +- ``formIntersection(_:)-8qfxe`` +- ``formIntersection(_:)-nne6`` -- ``formUnion(_:)-68pog`` -- ``formUnion(_:)-82rrc`` -- ``formUnion(_:)-4r7qz`` +- ``formUnion(_:)-1qwuq`` +- ``formUnion(_:)-2raoj`` +- ``formUnion(_:)-ew7g`` -- ``subtract(_:)-7rmd3`` -- ``subtract(_:)-47r93`` -- ``subtract(_:)-3v8ms`` +- ``subtract(_:)-24txa`` +- ``subtract(_:)-69g3`` +- ``subtract(_:)-5l8bb`` -- ``formSymmetricDifference(_:)-499uq`` -- ``formSymmetricDifference(_:)-8wue8`` -- ``formSymmetricDifference(_:)-4t8jr`` +- ``formSymmetricDifference(_:)-6zqa1`` +- ``formSymmetricDifference(_:)-mv0q`` +- ``formSymmetricDifference(_:)-2qzlu`` ### 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`` -- ``isEqualSet(to:)-4t0k5`` -- ``isEqualSet(to:)-7s0cu`` +- ``isEqualSet(to:)-5lpwv`` +- ``isEqualSet(to:)-6ont2`` +- ``isEqualSet(to:)-58q8h`` -- ``isSubset(of:)-9mp7l`` -- ``isSubset(of:)-2jlh`` -- ``isSubset(of:)-8vn0j`` +- ``isSubset(of:)-2itju`` +- ``isSubset(of:)-2nice`` +- ``isSubset(of:)-8qszd`` -- ``isSuperset(of:)-5af8o`` -- ``isSuperset(of:)-6mvxj`` -- ``isSuperset(of:)-864jy`` +- ``isSuperset(of:)-9mp0j`` +- ``isSuperset(of:)-3pm0f`` +- ``isSuperset(of:)-63haf`` -- ``isStrictSubset(of:)-48nx2`` -- ``isStrictSubset(of:)-2j680`` -- ``isStrictSubset(of:)-1s6n9`` +- ``isStrictSubset(of:)-1cdr`` +- ``isStrictSubset(of:)-3xlgn`` +- ``isStrictSubset(of:)-8oyb4`` -- ``isStrictSuperset(of:)-nd5j`` -- ``isStrictSuperset(of:)-5z263`` -- ``isStrictSuperset(of:)-ivbh`` +- ``isStrictSuperset(of:)-7qgvz`` +- ``isStrictSuperset(of:)-3fdsl`` +- ``isStrictSuperset(of:)-2ujyn`` -- ``isDisjoint(with:)-12irx`` -- ``isDisjoint(with:)-1hhyf`` -- ``isDisjoint(with:)-61lde`` +- ``isDisjoint(with:)-eq16`` +- ``isDisjoint(with:)-8bgbj`` +- ``isDisjoint(with:)-5b64c`` diff --git a/Sources/PersistentCollections/PersistentCollections.docc/PersistentCollections.md b/Sources/ShareableHashedCollections/ShareableHashedCollections.docc/ShareableHashedCollections.md similarity index 83% rename from Sources/PersistentCollections/PersistentCollections.docc/PersistentCollections.md rename to Sources/ShareableHashedCollections/ShareableHashedCollections.docc/ShareableHashedCollections.md index 36f3a571..44c795e3 100644 --- a/Sources/PersistentCollections/PersistentCollections.docc/PersistentCollections.md +++ b/Sources/ShareableHashedCollections/ShareableHashedCollections.docc/ShareableHashedCollections.md @@ -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`` diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Codable.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Codable.swift similarity index 92% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Codable.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Codable.swift index c8b87f10..5e7d8282 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Codable.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Codable.swift @@ -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 diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Collection.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Collection.swift similarity index 94% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Collection.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Collection.swift index 37dfe0f7..fa94c290 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Collection.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Collection.swift @@ -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. diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+CustomReflectable.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+CustomReflectable.swift similarity index 92% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+CustomReflectable.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+CustomReflectable.swift index 9f97b071..d6d726d9 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+CustomReflectable.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+CustomReflectable.swift @@ -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) diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Debugging.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Debugging.swift similarity index 98% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Debugging.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Debugging.swift index 58e4cfb7..38a6e7c8 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Debugging.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Debugging.swift @@ -11,7 +11,7 @@ import _CollectionsUtilities -extension PersistentSet { +extension ShareableSet { /// True if consistency checking is enabled in the implementation of this /// type, false otherwise. /// diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Descriptions.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Descriptions.swift similarity index 85% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Descriptions.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Descriptions.swift index 13a3dd7f..2beb7eba 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Descriptions.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Descriptions.swift @@ -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)>" } } diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Equatable.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Equatable.swift similarity index 89% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Equatable.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Equatable.swift index 56d51a70..418cf98d 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Equatable.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Equatable.swift @@ -11,13 +11,13 @@ 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 /// elements, but not necessarily in the same order. /// - /// - Note: This simply forwards to the ``isEqualSet(to:)-7egih`` method. + /// - Note: This simply forwards to the ``isEqualSet(to:)-5lpwv`` method. /// That method has additional overloads that can be used to compare /// persistent sets with additional types. /// diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+ExpressibleByArrayLiteral.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+ExpressibleByArrayLiteral.swift similarity index 96% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+ExpressibleByArrayLiteral.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+ExpressibleByArrayLiteral.swift index d2eb3a8b..d050043f 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+ExpressibleByArrayLiteral.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+ExpressibleByArrayLiteral.swift @@ -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 diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Extras.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Extras.swift similarity index 97% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Extras.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Extras.swift index 9166654d..d1ee5076 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Extras.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Extras.swift @@ -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. diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Filter.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Filter.swift similarity index 53% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Filter.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Filter.swift index 8e520aae..0514e6c0 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Filter.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Filter.swift @@ -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,6 +26,30 @@ 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. + /// + /// Use this method to remove every element in the set that meets + /// particular criteria. + /// This example removes all the odd values from a + /// set of numbers: + /// + /// var numbers: ShareableSet = [5, 6, 7, 8, 9, 10, 11] + /// numbers.removeAll(where: { $0 % 2 != 0 }) + /// // numbers == [6, 8, 10] + /// + /// - Parameter shouldBeRemoved: A closure that takes an element of the + /// set as its argument and returns a Boolean value indicating + /// whether the element should be removed from the collection. + /// + /// - Complexity: O(`count`) + @inlinable + public mutating func removeAll( + where shouldBeRemoved: (Element) throws -> Bool + ) rethrows { + // FIXME: Implement in-place reductions + self = try filter { try !shouldBeRemoved($0) } } } diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Hashable.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Hashable.swift similarity index 95% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Hashable.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Hashable.swift index 42cbf623..481c83f8 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Hashable.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Hashable.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -extension PersistentSet: Hashable { +extension ShareableSet: Hashable { /// Hashes the essential components of this value by feeding them into the /// given hasher. /// diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Sendable.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Sendable.swift similarity index 86% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Sendable.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Sendable.swift index d933acd1..e1da09c8 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Sendable.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Sendable.swift @@ -10,5 +10,5 @@ //===----------------------------------------------------------------------===// #if swift(>=5.5) -extension PersistentSet: @unchecked Sendable where Element: Sendable {} +extension ShareableSet: @unchecked Sendable where Element: Sendable {} #endif diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+Sequence.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Sequence.swift similarity index 91% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+Sequence.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Sequence.swift index f27adcbf..447f4662 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+Sequence.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+Sequence.swift @@ -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 diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra Initializers.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra Initializers.swift similarity index 95% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra Initializers.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra Initializers.swift index 66861b6e..6ff84625 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra Initializers.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra Initializers.swift @@ -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( - _ item: __owned PersistentDictionary.Keys + _ item: __owned ShareableDictionary.Keys ) { self.init(_new: item._base._root.mapValues { _ in () }) } diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra basics.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra basics.swift similarity index 99% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra basics.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra basics.swift index ec2cfd27..da4b3376 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra basics.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra basics.swift @@ -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. /// diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra formIntersection.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra formIntersection.swift similarity index 90% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra formIntersection.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra formIntersection.swift index 466169dc..94636a68 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra formIntersection.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra formIntersection.swift @@ -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]` /// @@ -30,6 +30,7 @@ extension PersistentSet { /// parts of the input trees directly into the result. @inlinable public mutating func formIntersection(_ other: Self) { + // FIXME: Implement in-place reductions self = intersection(other) } @@ -49,14 +50,15 @@ extension PersistentSet { /// parts of the input trees directly into the result. @inlinable public mutating func formIntersection( - _ other: PersistentDictionary.Keys + _ other: ShareableDictionary.Keys ) { + // FIXME: Implement in-place reductions self = intersection(other) } /// 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]` diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra formSymmetricDifference.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra formSymmetricDifference.swift similarity index 87% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra formSymmetricDifference.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra formSymmetricDifference.swift index cf1b6cdd..c8c2fc54 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra formSymmetricDifference.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra formSymmetricDifference.swift @@ -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( - _ other: __owned PersistentDictionary.Keys + _ other: __owned ShareableDictionary.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]` diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra formUnion.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra formUnion.swift similarity index 91% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra formUnion.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra formUnion.swift index 3b3dc667..bebf0c7c 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra formUnion.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra formUnion.swift @@ -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( - _ other: __owned PersistentDictionary.Keys + _ other: __owned ShareableDictionary.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]` diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra intersection.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra intersection.swift similarity index 90% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra intersection.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra intersection.swift index bce0e00f..8db89140 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra intersection.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra intersection.swift @@ -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( - _ other: PersistentDictionary.Keys + _ other: ShareableDictionary.Keys ) -> Self { _intersection(other._base._root) } @inlinable internal func _intersection( - _ other: PersistentCollections._Node + _ other: ShareableHashedCollections._Node ) -> 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]` diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isDisjoint.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isDisjoint.swift similarity index 87% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isDisjoint.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isDisjoint.swift index 6f70f20e..dad58572 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isDisjoint.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isDisjoint.swift @@ -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( - with other: PersistentDictionary.Keys + with other: ShareableDictionary.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 diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqualSet.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isEqualSet.swift similarity index 97% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqualSet.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isEqualSet.swift index 5409dbe7..6bd1c2e2 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isEqualSet.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isEqualSet.swift @@ -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( - to other: PersistentDictionary.Keys + to other: ShareableDictionary.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 diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isStrictSubset.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isStrictSubset.swift similarity index 93% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isStrictSubset.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isStrictSubset.swift index 9ccb06b8..ef71df7d 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isStrictSubset.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isStrictSubset.swift @@ -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( - of other: PersistentDictionary.Keys + of other: ShareableDictionary.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 diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isStrictSuperset.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isStrictSuperset.swift similarity index 92% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isStrictSuperset.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isStrictSuperset.swift index 6625c7eb..84497997 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isStrictSuperset.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isStrictSuperset.swift @@ -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( - of other: PersistentDictionary.Keys + of other: ShareableDictionary.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 diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isSubset.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isSubset.swift similarity index 91% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isSubset.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isSubset.swift index 542d1df2..e9e96618 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isSubset.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isSubset.swift @@ -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( - of other: PersistentDictionary.Keys + of other: ShareableDictionary.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 diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isSuperset.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isSuperset.swift similarity index 89% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isSuperset.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isSuperset.swift index 58dee925..c5608480 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra isSuperset.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra isSuperset.swift @@ -9,15 +9,15 @@ // //===----------------------------------------------------------------------===// -extension PersistentSet { +extension ShareableSet { /// Returns a Boolean value that indicates whether this set is a superset of /// the given set. /// /// Set *A* is a superset of another set *B* if every member of *B* is also a /// member of *A*, 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] /// a.isSuperset(of: b) // true /// /// - Parameter other: Another set. @@ -39,8 +39,8 @@ extension PersistentSet { /// Set *A* is a superset of another set *B* if every member of *B* is also a /// member of *A*, 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] /// a.isSuperset(of: b) // true /// /// - Parameter other: The keys view of a persistent dictionary. @@ -53,7 +53,7 @@ extension PersistentSet { /// e.g. by skipping over parts of the input trees. @inlinable public func isSuperset( - of other: PersistentDictionary.Keys + of other: ShareableDictionary.Keys ) -> Bool { other._base._root.isSubset(.top, of: self._root) } @@ -64,8 +64,8 @@ extension PersistentSet { /// Set *A* is a superset of another set *B* if every member of *B* is also a /// member of *A*, 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] /// a.isSuperset(of: b) // true /// /// - Parameter other: A sequence of elements, some of whose elements may diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra subtract.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra subtract.swift similarity index 84% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra subtract.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra subtract.swift index 6463d527..0f432665 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra subtract.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra subtract.swift @@ -9,11 +9,11 @@ // //===----------------------------------------------------------------------===// -extension PersistentSet { +extension ShareableSet { /// Removes the elements of the given set from 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.subtract(b) /// // `a` is now some permutation of `[1, 3]` /// @@ -26,14 +26,15 @@ extension PersistentSet { /// parts of the input trees directly into the result. @inlinable public mutating func subtract(_ other: Self) { + // FIXME: Implement in-place reductions self = subtracting(other) } /// Removes the elements of the given keys view of a persistent dictionary /// from 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.subtract(b.keys) /// // `a` is now some permutation of `[1, 3]` /// @@ -46,14 +47,15 @@ extension PersistentSet { /// parts of the input trees directly into the result. @inlinable public mutating func subtract( - _ other: PersistentDictionary.Keys + _ other: ShareableDictionary.Keys ) { + // FIXME: Implement in-place reductions self = subtracting(other) } /// Removes the elements of the given sequence from this set. /// - /// var a: PersistentSet = [1, 2, 3, 4] + /// var a: ShareableSet = [1, 2, 3, 4] /// let b = [0, 2, 4, 6] /// a.subtract(b) /// // `a` is now some permutation of `[1, 3]` diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra subtracting.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra subtracting.swift similarity index 88% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra subtracting.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra subtracting.swift index bbdb76be..5eab5660 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra subtracting.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra subtracting.swift @@ -9,12 +9,12 @@ // //===----------------------------------------------------------------------===// -extension PersistentSet { +extension ShareableSet { /// Returns a new set containing the elements of this set that do not occur /// in the given other 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] /// let c = a.subtracting(b) /// // `c` is some permutation of `[1, 3]` /// @@ -33,8 +33,8 @@ extension PersistentSet { /// Returns a new set containing the elements of this set that do not occur /// in the given 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.subtracting(b.keys) /// // `c` is some permutation of `[1, 3]` /// @@ -47,14 +47,14 @@ extension PersistentSet { /// parts of the input trees directly into the result. @inlinable public __consuming func subtracting( - _ other: PersistentDictionary.Keys + _ other: ShareableDictionary.Keys ) -> Self { _subtracting(other._base._root) } @inlinable internal __consuming func _subtracting( - _ other: PersistentCollections._Node + _ other: ShareableHashedCollections._Node ) -> Self { guard let r = _root.subtracting(.top, other) else { return self } return Self(_new: r) @@ -63,7 +63,7 @@ extension PersistentSet { /// Returns a new set containing the elements of this set that do not occur /// in the given sequence. /// - /// var a: PersistentSet = [1, 2, 3, 4] + /// var a: ShareableSet = [1, 2, 3, 4] /// let b = [0, 2, 4, 6] /// let c = a.subtracting(b) /// // `c` is some permutation of `[1, 3]` diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra symmetricDifference.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra symmetricDifference.swift similarity index 89% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra symmetricDifference.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra symmetricDifference.swift index 5fd662a2..5c4fff76 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra symmetricDifference.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra symmetricDifference.swift @@ -11,12 +11,12 @@ import _CollectionsUtilities -extension PersistentSet { +extension ShareableSet { /// Returns a new set with the elements that are either in this set or in /// `other`, but not in 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] /// let c = a.symmetricDifference(b) /// // `c` is some permutation of `[0, 1, 3, 6]` /// @@ -33,14 +33,14 @@ extension PersistentSet { guard let branch = branch else { return self } let root = branch.finalize(.top) root._fullInvariantCheck() - return PersistentSet(_new: root) + return ShareableSet(_new: root) } /// Returns a new set with the elements that are either in this set or in /// `other`, but not in 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"] /// let c = a.symmetricDifference(b.keys) /// // `c` is some permutation of `[0, 1, 3, 6]` /// @@ -53,19 +53,19 @@ extension PersistentSet { /// parts of the input trees directly into the result. @inlinable public func symmetricDifference( - _ other: __owned PersistentDictionary.Keys + _ other: __owned ShareableDictionary.Keys ) -> Self { let branch = _root.symmetricDifference(.top, other._base._root) guard let branch = branch else { return self } let root = branch.finalize(.top) root._fullInvariantCheck() - return PersistentSet(_new: root) + return ShareableSet(_new: root) } /// Returns a new set with the elements that are either in this set or in /// the given sequence, but not in both. /// - /// var a: PersistentSet = [1, 2, 3, 4] + /// var a: ShareableSet = [1, 2, 3, 4] /// let b = [0, 2, 4, 6, 6, 2] /// let c = a.symmetricDifference(b) /// // `c` is some permutation of `[0, 1, 3, 6]` @@ -106,7 +106,7 @@ extension PersistentSet { // If `other` may contain duplicates, we need to be more // careful (and slower). - let other = PersistentSet(other) + let other = ShareableSet(other) return self.symmetricDifference(other) } } diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra union.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra union.swift similarity index 90% rename from Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra union.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra union.swift index eb83644b..615599d2 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra union.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet+SetAlgebra union.swift @@ -9,11 +9,11 @@ // //===----------------------------------------------------------------------===// -extension PersistentSet { +extension ShareableSet { /// Returns a new set with the elements of both this and the given 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] /// let c = a.union(b) /// // `c` is some permutation of `[0, 1, 2, 3, 4, 6]` /// @@ -34,14 +34,14 @@ extension PersistentSet { let r = _root.union(.top, other._root) guard r.copied else { return self } r.node._fullInvariantCheck() - return PersistentSet(_new: r.node) + return ShareableSet(_new: r.node) } /// Returns a new set with the elements of both this set and the given /// 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.union(b) /// // `c` is some permutation of `[0, 1, 2, 3, 4, 6]` /// @@ -59,18 +59,18 @@ extension PersistentSet { /// parts of the input trees directly into the result. @inlinable public func union( - _ other: __owned PersistentDictionary.Keys + _ other: __owned ShareableDictionary.Keys ) -> Self { let r = _root.union(.top, other._base._root) guard r.copied else { return self } r.node._fullInvariantCheck() - return PersistentSet(_new: r.node) + return ShareableSet(_new: r.node) } /// Returns a new set with the elements of both this set and the given /// sequence. /// - /// var a: PersistentSet = [1, 2, 3, 4] + /// var a: ShareableSet = [1, 2, 3, 4] /// let b = [0, 2, 4, 6, 0, 2] /// let c = a.union(b) /// // `c` is some permutation of `[0, 1, 2, 3, 4, 6]` diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet.swift b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet.swift similarity index 83% rename from Sources/PersistentCollections/PersistentSet/PersistentSet.swift rename to Sources/ShareableHashedCollections/ShareableSet/ShareableSet.swift index 8a99be1b..05d48859 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet.swift +++ b/Sources/ShareableHashedCollections/ShareableSet/ShareableSet.swift @@ -12,22 +12,22 @@ /// An unordered collection of unique elements, optimized for mutating shared /// copies and comparing different snapshots of the same collection. /// -/// `PersistentSet` has the same functionality as a standard `Set`, and +/// `ShareableSet` has the same functionality as a standard `Set`, and /// it largely implements the same APIs: both are hashed collection /// types that conform to `SetAlgebra`, and both are unordered -- neither type /// provides any guarantees about the ordering of their members. /// -/// However, `PersistentSet` is optimizing specifically for use cases that +/// However, `ShareableSet` is optimizing specifically for use cases that /// need to mutate shared copies or to compare a set value to one of its older /// snapshots. /// /// The standard `Set` stores its members in a single, flat hash table, and it /// implements value semantics with all-or-nothing copy-on-write behavior: every /// time a shared copy of a set is mutated, the mutation needs to make a full -/// copy of the set's storage. `PersistentSet` takes a different approach: it +/// copy of the set's storage. `ShareableSet` 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 set -/// value, `PersistentSet` is able to simply link the unchanged parts of the +/// value, `ShareableSet` 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 set @@ -36,14 +36,14 @@ /// constant time, leading to a dramatic performance boost when the two inputs /// are still largely unchanged: /// -/// var set = PersistentSet(0 ..< 10_000) +/// var set = ShareableSet(0 ..< 10_000) /// let copy = set /// set.insert(20_000) // Expected to be an O(log(n)) operation /// let diff = set.subtracting(copy) // Also O(log(n))! /// // `diff` now holds the single item 20_000. /// /// The tree structure also eliminates the need to reserve capacity in advance: -/// `PersistentSet` creates, destroys and resizes individual nodes as needed, +/// `ShareableSet` 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 long after @@ -51,15 +51,15 @@ /// /// Of course, switching to a tree structure comes with some trade offs. In /// particular, inserting new items, removing existing ones, and iterating over -/// a `PersistentSet` is expected to be a constant factor slower than a standard +/// a `ShareableSet` is expected to be a constant factor slower than a standard /// `Set` -- 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 PersistentSet { +public struct ShareableSet { @usableFromInline - internal typealias _Node = PersistentCollections._Node + internal typealias _Node = ShareableHashedCollections._Node @usableFromInline internal typealias _UnsafeHandle = _Node.UnsafeHandle diff --git a/Sources/_CollectionsTestSupport/Utilities/DictionaryAPIChecker.swift b/Sources/_CollectionsTestSupport/Utilities/DictionaryAPIChecker.swift index dc16bfc6..8c60c9be 100644 --- a/Sources/_CollectionsTestSupport/Utilities/DictionaryAPIChecker.swift +++ b/Sources/_CollectionsTestSupport/Utilities/DictionaryAPIChecker.swift @@ -134,7 +134,7 @@ public protocol DictionaryAPIExtras: DictionaryAPIChecker { ) rethrows -> R #if false - // Potential additions implemented by PersistentDictionary: + // Potential additions implemented by ShareableDictionary: func contains(_ key: Key) -> Bool diff --git a/Tests/PersistentCollectionsTests/Colliders.swift b/Tests/ShareableHashedCollectionsTests/Colliders.swift similarity index 100% rename from Tests/PersistentCollectionsTests/Colliders.swift rename to Tests/ShareableHashedCollectionsTests/Colliders.swift diff --git a/Tests/PersistentCollectionsTests/Hash.swift b/Tests/ShareableHashedCollectionsTests/Hash.swift similarity index 100% rename from Tests/PersistentCollectionsTests/Hash.swift rename to Tests/ShareableHashedCollectionsTests/Hash.swift diff --git a/Tests/PersistentCollectionsTests/PersistentDictionary Smoke Tests.swift b/Tests/ShareableHashedCollectionsTests/ShareableDictionary Smoke Tests.swift similarity index 84% rename from Tests/PersistentCollectionsTests/PersistentDictionary Smoke Tests.swift rename to Tests/ShareableHashedCollectionsTests/ShareableDictionary Smoke Tests.swift index e21bcb54..9dc853c2 100644 --- a/Tests/PersistentCollectionsTests/PersistentDictionary Smoke Tests.swift +++ b/Tests/ShareableHashedCollectionsTests/ShareableDictionary Smoke Tests.swift @@ -10,17 +10,17 @@ //===----------------------------------------------------------------------===// import _CollectionsTestSupport -import PersistentCollections +import ShareableHashedCollections -extension PersistentDictionary { +extension ShareableDictionary { fileprivate func contains(_ key: Key) -> Bool { self[key] != nil } } -final class PersistentDictionarySmokeTests: CollectionTestCase { +final class ShareableDictionarySmokeTests: CollectionTestCase { func testDummy() { - let map = PersistentDictionary( + let map = ShareableDictionary( uniqueKeysWithValues: (0 ..< 100).map { ($0, 2 * $0) }) var it = map.makeIterator() var seen: Set = [] @@ -40,7 +40,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testSubscriptAdd() { - var map: PersistentDictionary = [1: "a", 2: "b"] + var map: ShareableDictionary = [1: "a", 2: "b"] map[3] = "x" map[4] = "y" @@ -53,7 +53,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testSubscriptOverwrite() { - var map: PersistentDictionary = [1: "a", 2: "b"] + var map: ShareableDictionary = [1: "a", 2: "b"] map[1] = "x" map[2] = "y" @@ -64,7 +64,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testSubscriptRemove() { - var map: PersistentDictionary = [1: "a", 2: "b"] + var map: ShareableDictionary = [1: "a", 2: "b"] map[1] = nil map[2] = nil @@ -75,21 +75,20 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testTriggerOverwrite1() { - let map: PersistentDictionary = [1: "a", 2: "b"] + var map: ShareableDictionary = [1: "a", 2: "b"] - _ = map - .updatingValue("x", forKey: 1) // triggers COW - .updatingValue("y", forKey: 2) // triggers COW + map.updateValue("x", forKey: 1) // triggers COW + map.updateValue("y", forKey: 2) // triggers COW - var res1: PersistentDictionary = [:] + var res1: ShareableDictionary = [:] res1.updateValue("a", forKey: 1) // in-place res1.updateValue("b", forKey: 2) // in-place - var res2: PersistentDictionary = [:] + var res2: ShareableDictionary = [:] res2[1] = "a" // in-place res2[2] = "b" // in-place - var res3: PersistentDictionary = res2 + var res3: ShareableDictionary = res2 res3[1] = "x" // triggers COW res3[2] = "y" // in-place @@ -103,7 +102,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testTriggerOverwrite2() { - var res1: PersistentDictionary = [:] + var res1: ShareableDictionary = [:] res1.updateValue("a", forKey: Collider(10, 01)) // in-place res1.updateValue("a", forKey: Collider(11, 33)) // in-place res1.updateValue("b", forKey: Collider(20, 02)) // in-place @@ -112,7 +111,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { res1.updateValue("x", forKey: Collider(11, 33)) // in-place res1.updateValue("y", forKey: Collider(20, 02)) // in-place - var res2: PersistentDictionary = res1 + var res2: ShareableDictionary = res1 res2.updateValue("a", forKey: Collider(10, 01)) // triggers COW res2.updateValue("a", forKey: Collider(11, 33)) // in-place res2.updateValue("b", forKey: Collider(20, 02)) // in-place @@ -131,13 +130,13 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { let upperBound = 1_000 // Populating `map1` - var map1: PersistentDictionary = [:] + var map1: ShareableDictionary = [:] for index in 0.. = map1 + var map2: ShareableDictionary = map1 for index in 0.. = map2 + var map3: ShareableDictionary = map2 for index in 0.. = [1: "a", 2: "b"] + let map: ShareableDictionary = [1: "a", 2: "b"] let hashPair1 = hashPair(1, "a") let hashPair2 = hashPair(2, "b") @@ -191,7 +190,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testCollisionNodeNotEqual() { - let map: PersistentDictionary = [:] + let map: ShareableDictionary = [:] var res12 = map res12[Collider(1, 1)] = Collider(1, 1) @@ -211,7 +210,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testCompactionWhenDeletingFromHashCollisionNode1() { - let map: PersistentDictionary = [:] + let map: ShareableDictionary = [:] var res1 = map @@ -222,7 +221,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectTrue(res1.contains(Collider(12, 1))) expectEqual(res1.count, 2) - expectEqual(PersistentDictionary([ + expectEqual(ShareableDictionary([ Collider(11, 1): Collider(11, 1), Collider(12, 1): Collider(12, 1) ]), res1) @@ -236,7 +235,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res2.count, 1) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(11, 1): Collider(11, 1) ]), res2) @@ -250,7 +249,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res3.count, 1) expectEqual( - PersistentDictionary([Collider(12, 1): Collider(12, 1)]), + ShareableDictionary([Collider(12, 1): Collider(12, 1)]), res3) @@ -264,7 +263,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(resX.count, 2) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(11, 1): Collider(11, 1), Collider(32769): Collider(32769)]), resX) @@ -280,14 +279,14 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(resY.count, 2) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(11, 1): Collider(11, 1), Collider(12, 1): Collider(12, 1)]), resY) } func testCompactionWhenDeletingFromHashCollisionNode2() { - let map: PersistentDictionary = [:] + let map: ShareableDictionary = [:] var res1 = map @@ -299,7 +298,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res1.count, 2) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(32769_1, 32769): Collider(32769_1, 32769), Collider(32769_2, 32769): Collider(32769_2, 32769)]), res1) @@ -314,7 +313,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res2.count, 3) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(1): Collider(1), Collider(32769_1, 32769): Collider(32769_1, 32769), Collider(32769_2, 32769): Collider(32769_2, 32769)]), @@ -329,14 +328,14 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res3.count, 2) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(1): Collider(1), Collider(32769_1, 32769): Collider(32769_1, 32769)]), res3) } func testCompactionWhenDeletingFromHashCollisionNode3() { - let map: PersistentDictionary = [:] + let map: ShareableDictionary = [:] var res1 = map @@ -348,7 +347,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res1.count, 2) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(32769_1, 32769): Collider(32769_1, 32769), Collider(32769_2, 32769): Collider(32769_2, 32769)]), res1) @@ -363,7 +362,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res2.count, 3) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(1): Collider(1), Collider(32769_1, 32769): Collider(32769_1, 32769), Collider(32769_2, 32769): Collider(32769_2, 32769)]), @@ -378,7 +377,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res3.count, 2) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(32769_1, 32769): Collider(32769_1, 32769), Collider(32769_2, 32769): Collider(32769_2, 32769)]), res3) @@ -388,7 +387,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testCompactionWhenDeletingFromHashCollisionNode4() { - let map: PersistentDictionary = [:] + let map: ShareableDictionary = [:] var res1 = map @@ -400,7 +399,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res1.count, 2) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(32769_1, 32769): Collider(32769_1, 32769), Collider(32769_2, 32769): Collider(32769_2, 32769)]), res1) @@ -415,7 +414,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res2.count, 3) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(5): Collider(5), Collider(32769_1, 32769): Collider(32769_1, 32769), Collider(32769_2, 32769): Collider(32769_2, 32769)]), @@ -430,7 +429,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res3.count, 2) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(32769_1, 32769): Collider(32769_1, 32769), Collider(32769_2, 32769): Collider(32769_2, 32769)]), res3) @@ -440,7 +439,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testCompactionWhenDeletingFromHashCollisionNode5() { - let map: PersistentDictionary = [:] + let map: ShareableDictionary = [:] var res1 = map @@ -456,7 +455,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res1.count, 4) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(1): Collider(1), Collider(1026): Collider(1026), Collider(32770_1, 32770): Collider(32770_1, 32770), @@ -474,14 +473,14 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { expectEqual(res2.count, 3) expectEqual( - PersistentDictionary([ + ShareableDictionary([ Collider(1): Collider(1), Collider(32770_1, 32770): Collider(32770_1, 32770), Collider(32770_2, 32770): Collider(32770_2, 32770)]), res2) } - func inferSize(_ map: PersistentDictionary) -> Int { + func inferSize(_ map: ShareableDictionary) -> Int { var size = 0 for _ in map { @@ -495,7 +494,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { let upperBound = 1_000 // '+' prefixed values - var map1: PersistentDictionary = [:] + var map1: ShareableDictionary = [:] for index in 0.. = map1 + var map2: ShareableDictionary = map1 for index in 0.. = map1 + var map3: ShareableDictionary = map1 for index in 0.. = [:] + var map1: ShareableDictionary = [:] for index in 0..( - _ map1: PersistentDictionary + _ map1: ShareableDictionary ) { var count = 0 for _ in map1 { @@ -554,13 +553,13 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func testIteratorEnumeratesAll() { - let map1: PersistentDictionary = [ + let map1: ShareableDictionary = [ Collider(11, 1): "a", Collider(12, 1): "a", Collider(32769): "b" ] - var map2: PersistentDictionary = [:] + var map2: ShareableDictionary = [:] for (key, value) in map1 { map2[key] = value } @@ -572,7 +571,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { let a = Collider(1, "1000") let b = Collider(2, "1000") let c = Collider(3, "1001") - let map: PersistentDictionary = [ + let map: ShareableDictionary = [ a: "a", b: "b", c: "c", @@ -580,7 +579,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { let indices = Array(map.indices) - typealias Index = PersistentDictionary.Index + typealias Index = ShareableDictionary.Index expectEqual(map.index(forKey: a), indices[1]) expectEqual(map.index(forKey: b), indices[2]) expectEqual(map.index(forKey: c), indices[0]) @@ -589,7 +588,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { func test_indexForKey() { let input = 0 ..< 10_000 - let d = PersistentDictionary( + let d = ShareableDictionary( uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) }) for key in input { expectNotNil(d.index(forKey: key)) { index in @@ -602,7 +601,7 @@ final class PersistentDictionarySmokeTests: CollectionTestCase { } func test_indexForKey_exhaustIndices() { - var map: PersistentDictionary = [:] + var map: ShareableDictionary = [:] let range = 0 ..< 10_000 diff --git a/Tests/PersistentCollectionsTests/PersistentDictionary Tests.swift b/Tests/ShareableHashedCollectionsTests/ShareableDictionary Tests.swift similarity index 89% rename from Tests/PersistentCollectionsTests/PersistentDictionary Tests.swift rename to Tests/ShareableHashedCollectionsTests/ShareableDictionary Tests.swift index b366f088..1efef57c 100644 --- a/Tests/PersistentCollectionsTests/PersistentDictionary Tests.swift +++ b/Tests/ShareableHashedCollectionsTests/ShareableDictionary Tests.swift @@ -10,13 +10,13 @@ //===----------------------------------------------------------------------===// import _CollectionsTestSupport -import PersistentCollections +import ShareableHashedCollections -extension PersistentDictionary: DictionaryAPIExtras {} +extension ShareableDictionary: DictionaryAPIExtras {} -class PersistentDictionaryTests: CollectionTestCase { +class ShareableDictionaryTests: CollectionTestCase { func test_empty() { - let d = PersistentDictionary() + let d = ShareableDictionary() expectEqualElements(d, []) expectEqual(d.count, 0) @@ -31,7 +31,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_remove_update_basics() throws { - var d = PersistentDictionary() + var d = ShareableDictionary() d.updateValue(1, forKey: "One") d.updateValue(2, forKey: "Two") @@ -72,7 +72,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_subscript_setter_basics() throws { - var d = PersistentDictionary() + var d = ShareableDictionary() d["One"] = 1 d["Two"] = 2 @@ -113,7 +113,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_add_remove() throws { - var d = PersistentDictionary() + var d = ShareableDictionary() let c = 400 for i in 0 ..< c { @@ -143,7 +143,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_collisions() throws { - var d = PersistentDictionary() + var d = ShareableDictionary() let count = 100 let groups = 20 @@ -174,7 +174,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_shared_copies() throws { - var d = PersistentDictionary() + var d = ShareableDictionary() let c = 200 for i in 0 ..< c { @@ -201,7 +201,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_Sequence_basic() { - var d: PersistentDictionary = [1: 2] + var d: ShareableDictionary = [1: 2] var it = d.makeIterator() expectEquivalent(it.next(), (1, 2), by: { $0 == $1 }) expectNil(it.next()) @@ -214,7 +214,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_Sequence_400() { - var d = PersistentDictionary() + var d = ShareableDictionary() let c = 400 for i in 0 ..< c { expectNil(d.updateValue(i, forKey: i)) @@ -230,7 +230,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_Sequence_collisions() { - var d = PersistentDictionary() + var d = ShareableDictionary() let count = 100 let groups = 20 @@ -253,7 +253,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_BidirectionalCollection_fixtures() { withEachFixture { fixture in withLifetimeTracking { tracker in - let (d, ref) = tracker.persistentDictionary(for: fixture) + let (d, ref) = tracker.shareableDictionary(for: fixture) checkCollection(d, expectedContents: ref, by: ==) _checkBidirectionalCollection_indexOffsetBy( d, expectedContents: ref, by: ==) @@ -262,7 +262,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_BidirectionalCollection_random100() { - let d = PersistentDictionary( + let d = ShareableDictionary( uniqueKeysWithValues: (0 ..< 100).map { ($0, $0) }) let ref = Array(d) checkCollection(d, expectedContents: ref, by: ==) @@ -297,13 +297,13 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_Encodable() throws { - let d1: PersistentDictionary = [ + let d1: ShareableDictionary = [ "one": 1, "two": 2, "three": 3] let v1: MinimalEncoder.Value = .dictionary([ "one": .int(1), "two": .int(2), "three": .int(3)]) expectEqual(try MinimalEncoder.encode(d1), v1) - let d2: PersistentDictionary = [ + let d2: ShareableDictionary = [ 1: "one", 2: "two", 3: "three"] let v2: MinimalEncoder.Value = .dictionary([ "1": .string("one"), @@ -314,7 +314,7 @@ class PersistentDictionaryTests: CollectionTestCase { #if swift(>=5.6) if #available(macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4, *) { - let d3: PersistentDictionary = [ + let d3: ShareableDictionary = [ FancyDictionaryKey(1): 10, FancyDictionaryKey(2): 20 ] let v3: MinimalEncoder.Value = .dictionary([ @@ -324,7 +324,7 @@ class PersistentDictionaryTests: CollectionTestCase { } #endif - let d4: PersistentDictionary = [ + let d4: ShareableDictionary = [ // Note: we only have a single element to prevent ordering // problems. BoringDictionaryKey(42): 23 @@ -337,9 +337,9 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_Decodable() throws { - typealias PD = PersistentDictionary + typealias PD = ShareableDictionary - let d1: PersistentDictionary = [ + let d1: ShareableDictionary = [ "one": 1, "two": 2, "three": 3] let v1: MinimalEncoder.Value = .dictionary([ "one": .int(1), "two": .int(2), "three": .int(3)]) @@ -347,7 +347,7 @@ class PersistentDictionaryTests: CollectionTestCase { try MinimalDecoder.decode(v1, as: PD.self), d1) - let d2: PersistentDictionary = [ + let d2: ShareableDictionary = [ 1: "one", 2: "two", 3: "three"] let v2: MinimalEncoder.Value = .dictionary([ "1": .string("one"), @@ -360,7 +360,7 @@ class PersistentDictionaryTests: CollectionTestCase { #if swift(>=5.6) if #available(macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4, *) { - let d3: PersistentDictionary = [ + let d3: ShareableDictionary = [ FancyDictionaryKey(1): 10, FancyDictionaryKey(2): 20 ] let v3: MinimalEncoder.Value = .dictionary([ @@ -372,7 +372,7 @@ class PersistentDictionaryTests: CollectionTestCase { } #endif - let d4: PersistentDictionary = [ + let d4: ShareableDictionary = [ // Note: we only have a single element to prevent ordering // problems. BoringDictionaryKey(42): 23 @@ -425,7 +425,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_CustomReflectable() { do { - let d: PersistentDictionary = [1: 2, 3: 4, 5: 6] + let d: ShareableDictionary = [1: 2, 3: 4, 5: 6] let mirror = Mirror(reflecting: d) expectEqual(mirror.displayStyle, .dictionary) expectNil(mirror.superclassMirror) @@ -437,7 +437,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_Equatable_Hashable() { - let samples: [[PersistentDictionary]] = [ + let samples: [[ShareableDictionary]] = [ [[:], [:]], [[1: 100], [1: 100]], [[2: 200], [2: 200]], @@ -457,15 +457,15 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_CustomStringConvertible() { - let a: PersistentDictionary = [:] + let a: ShareableDictionary = [:] expectEqual(a.description, "[:]") - let b: PersistentDictionary = [ + let b: ShareableDictionary = [ RawCollider(0): 1 ] expectEqual(b.description, "[0#0: 1]") - let c: PersistentDictionary = [ + let c: ShareableDictionary = [ RawCollider(0): 1, RawCollider(2): 3, RawCollider(4): 5, @@ -474,26 +474,26 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_CustomDebugStringConvertible() { - let a: PersistentDictionary = [:] + let a: ShareableDictionary = [:] expectEqual( a.debugDescription, - "PersistentDictionary([:])") + "ShareableDictionary([:])") - let b: PersistentDictionary = [0: 1] + let b: ShareableDictionary = [0: 1] expectEqual( b.debugDescription, - "PersistentDictionary([0: 1])") + "ShareableDictionary([0: 1])") - let c: PersistentDictionary = [0: 1, 2: 3, 4: 5] + let c: ShareableDictionary = [0: 1, 2: 3, 4: 5] let cd = c.map { "\($0.key): \($0.value)"}.joined(separator: ", ") expectEqual( c.debugDescription, - "PersistentDictionary([\(cd)])") + "ShareableDictionary([\(cd)])") } func test_index_descriptions() { - let a: PersistentDictionary = [ + let a: ShareableDictionary = [ RawCollider(1, "1"): 1, RawCollider(2, "21"): 2, RawCollider(3, "22"): 3, @@ -521,7 +521,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var d: PersistentDictionary, LifetimeTracked> = [:] + var d: ShareableDictionary, LifetimeTracked> = [:] var ref: Dictionary, LifetimeTracked> = [:] withEvery("i", in: 0 ..< fixture.count) { i in withHiddenCopies(if: isShared, of: &d) { d in @@ -545,7 +545,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var d: PersistentDictionary, Empty> = [:] + var d: ShareableDictionary, Empty> = [:] var ref: Dictionary, Empty> = [:] withEvery("i", in: 0 ..< fixture.count) { i in withHiddenCopies(if: isShared, of: &d) { d in @@ -566,7 +566,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("offset", in: 0 ..< fixture.count) { offset in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withHiddenCopies(if: isShared, of: &d) { d in let old = d.removeValue(forKey: ref[offset].key) d._invariantCheck() @@ -584,7 +584,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) var rng = RepeatableRandomNumberGenerator(seed: 0) withEvery("i", in: 0 ..< fixture.count) { _ in withHiddenCopies(if: isShared, of: &d) { d in @@ -605,7 +605,7 @@ class PersistentDictionaryTests: CollectionTestCase { func check(count: Int, generator: G) { context.withTrace("count: \(count), generator: \(generator)") { withLifetimeTracking { tracker in - let (d, ref) = tracker.persistentDictionary(0 ..< count, with: generator) + let (d, ref) = tracker.shareableDictionary(0 ..< count, with: generator) withEvery("key", in: 0 ..< count) { key in let key = tracker.instance(for: generator.key(for: key)) expectEqual(d[key], ref[key]) @@ -624,7 +624,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_subscript_getter_fixtures() { withEachFixture { fixture in withLifetimeTracking { tracker in - let (d, ref) = tracker.persistentDictionary(for: fixture) + let (d, ref) = tracker.shareableDictionary(for: fixture) for (k, v) in ref { expectEqual(d[k], v, "\(k)") } @@ -638,7 +638,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("key", in: 0 ..< count) { key in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary( + var (d, ref) = tracker.shareableDictionary( 0 ..< count, with: generator) let key = tracker.instance(for: generator.key(for: key)) let value = tracker.instance(for: generator.value(for: -1)) @@ -662,7 +662,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("offset", in: 0 ..< fixture.count) { offset in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) let replacement = tracker.instance(for: -1000) withHiddenCopies(if: isShared, of: &d) { d in let key = ref[offset].key @@ -682,7 +682,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("key", in: 0 ..< count) { key in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, reference) = tracker.persistentDictionary(keys: 0 ..< count) + var (d, reference) = tracker.shareableDictionary(keys: 0 ..< count) let key = tracker.instance(for: key) withHiddenCopies(if: isShared, of: &d) { d in d[key] = nil @@ -704,7 +704,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("offset", in: 0 ..< fixture.count) { offset in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withHiddenCopies(if: isShared, of: &d) { d in d[ref[offset].key] = nil ref.remove(at: offset) @@ -720,7 +720,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withEvery("i", in: 0 ..< ref.count) { _ in withHiddenCopies(if: isShared, of: &d) { d in d[ref[0].key] = nil @@ -742,7 +742,7 @@ class PersistentDictionaryTests: CollectionTestCase { for: (0 ..< count).map { generator.key(for: $0) }) let values = tracker.instances( for: (0 ..< count).map { generator.value(for: $0) }) - var d: PersistentDictionary, LifetimeTracked> = [:] + var d: ShareableDictionary, LifetimeTracked> = [:] var ref: Dictionary, LifetimeTracked> = [:] withEvery("offset", in: 0 ..< count) { offset in withHiddenCopies(if: isShared, of: &d) { d in @@ -764,7 +764,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var d: PersistentDictionary, LifetimeTracked> = [:] + var d: ShareableDictionary, LifetimeTracked> = [:] var ref: Dictionary, LifetimeTracked> = [:] withEvery("i", in: 0 ..< fixture.count) { i in withHiddenCopies(if: isShared, of: &d) { d in @@ -786,7 +786,7 @@ class PersistentDictionaryTests: CollectionTestCase { context.withTrace("count: \(count), generator: \(generator)") { withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(0 ..< count, with: generator) + var (d, ref) = tracker.shareableDictionary(0 ..< count, with: generator) let key = tracker.instance(for: generator.key(for: -1)) withHiddenCopies(if: isShared, of: &d) { d in d[key] = nil @@ -804,7 +804,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_subscript_modify_basics() { func check(count: Int, generator: G) where G.Value == Int { context.withTrace("count: \(count), generator: \(generator)") { - var d: PersistentDictionary = [:] + var d: ShareableDictionary = [:] var ref: Dictionary = [:] // Insertions @@ -858,7 +858,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("key", in: 0 ..< count) { key in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary( + var (d, ref) = tracker.shareableDictionary( 0 ..< count, with: generator) let key = tracker.instance(for: generator.key(for: key)) let replacement = tracker.instance(for: generator.value(for: -1)) @@ -885,7 +885,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("offset", in: 0 ..< fixture.count) { offset in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) let replacement = tracker.instance(for: -1000) withHiddenCopies(if: isShared, of: &d) { d in let key = ref[offset].key @@ -906,7 +906,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withEvery("offset", in: 0 ..< fixture.count) { offset in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) let key = ref[offset].key mutate(&d[key]) { value in expectNotNil(value) @@ -924,7 +924,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("offset", in: 0 ..< fixture.count) { offset in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withHiddenCopies(if: isShared, of: &d) { d in mutate(&d[ref[offset].key]) { value in expectNotNil(value) @@ -943,7 +943,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withEvery("i", in: 0 ..< ref.count) { i in withHiddenCopies(if: isShared, of: &d) { d in mutate(&d[ref[0].key]) { value in @@ -968,7 +968,7 @@ class PersistentDictionaryTests: CollectionTestCase { for: (0 ..< count).map { generator.key(for: $0) }) let values = tracker.instances( for: (0 ..< count).map { generator.value(for: $0) }) - var d: PersistentDictionary, LifetimeTracked> = [:] + var d: ShareableDictionary, LifetimeTracked> = [:] var ref: Dictionary, LifetimeTracked> = [:] withEvery("offset", in: 0 ..< count) { offset in withHiddenCopies(if: isShared, of: &d) { d in @@ -994,7 +994,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("seed", in: 0..<3) { seed in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var d: PersistentDictionary, LifetimeTracked> = [:] + var d: ShareableDictionary, LifetimeTracked> = [:] var ref: Dictionary, LifetimeTracked> = [:] withEvery("i", in: 0 ..< fixture.count) { i in withHiddenCopies(if: isShared, of: &d) { d in @@ -1020,7 +1020,7 @@ class PersistentDictionaryTests: CollectionTestCase { context.withTrace("count: \(count), generator: \(generator)") { withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(0 ..< count, with: generator) + var (d, ref) = tracker.shareableDictionary(0 ..< count, with: generator) let key = tracker.instance(for: generator.key(for: -1)) withHiddenCopies(if: isShared, of: &d) { d in mutate(&d[key]) { value in @@ -1039,7 +1039,7 @@ class PersistentDictionaryTests: CollectionTestCase { } func test_defaulted_subscript_basics() { - var d: PersistentDictionary = [:] + var d: ShareableDictionary = [:] expectEqual(d[1, default: 0], 0) @@ -1063,7 +1063,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_defaulted_subscript_getter_fixtures() { withEachFixture { fixture in withLifetimeTracking { tracker in - let (d, ref) = tracker.persistentDictionary(for: fixture) + let (d, ref) = tracker.shareableDictionary(for: fixture) let def = tracker.instance(for: -1) for (k, v) in ref { expectEqual(d[k, default: def], v, "\(k)") @@ -1078,7 +1078,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("key", in: 0 ..< count) { key in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary( + var (d, ref) = tracker.shareableDictionary( 0 ..< count, with: generator) let key = tracker.instance(for: generator.key(for: key)) let value = tracker.instance(for: generator.value(for: -1)) @@ -1103,7 +1103,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("offset", in: 0 ..< fixture.count) { offset in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) let replacement = tracker.instance(for: -1000) let def = tracker.instance(for: -1) withHiddenCopies(if: isShared, of: &d) { d in @@ -1127,7 +1127,7 @@ class PersistentDictionaryTests: CollectionTestCase { for: (0 ..< count).map { generator.key(for: $0) }) let values = tracker.instances( for: (0 ..< count).map { generator.value(for: $0) }) - var d: PersistentDictionary, LifetimeTracked> = [:] + var d: ShareableDictionary, LifetimeTracked> = [:] var ref: Dictionary, LifetimeTracked> = [:] let def = tracker.instance(for: generator.value(for: -1000)) withEvery("offset", in: 0 ..< count) { offset in @@ -1151,7 +1151,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("seed", in: 0..<3) { seed in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var d: PersistentDictionary, LifetimeTracked> = [:] + var d: ShareableDictionary, LifetimeTracked> = [:] var ref: Dictionary, LifetimeTracked> = [:] let def = tracker.instance(for: -1000) withEvery("i", in: 0 ..< fixture.count) { i in @@ -1176,7 +1176,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("key", in: 0 ..< count) { key in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary( + var (d, ref) = tracker.shareableDictionary( 0 ..< count, with: generator) let key = tracker.instance(for: generator.key(for: key)) let replacement = tracker.instance(for: generator.value(for: -1)) @@ -1204,7 +1204,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("offset", in: 0 ..< fixture.count) { offset in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) let replacement = tracker.instance(for: -1000) let def = tracker.instance(for: -1) withHiddenCopies(if: isShared, of: &d) { d in @@ -1226,7 +1226,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withEvery("offset", in: 0 ..< fixture.count) { offset in withLifetimeTracking { tracker in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) let key = ref[offset].key mutate(&d[key, default: tracker.instance(for: -1)]) { value in expectNotNil(value) @@ -1247,7 +1247,7 @@ class PersistentDictionaryTests: CollectionTestCase { let values = tracker.instances( for: (0 ..< count).map { generator.value(for: $0) }) let def = tracker.instance(for: generator.value(for: -1000)) - var d: PersistentDictionary, LifetimeTracked> = [:] + var d: ShareableDictionary, LifetimeTracked> = [:] var ref: Dictionary, LifetimeTracked> = [:] withEvery("offset", in: 0 ..< count) { offset in withHiddenCopies(if: isShared, of: &d) { d in @@ -1274,7 +1274,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEvery("seed", in: 0..<3) { seed in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var d: PersistentDictionary, LifetimeTracked> = [:] + var d: ShareableDictionary, LifetimeTracked> = [:] var ref: Dictionary, LifetimeTracked> = [:] let def = tracker.instance(for: -1) withEvery("i", in: 0 ..< fixture.count) { i in @@ -1301,7 +1301,7 @@ class PersistentDictionaryTests: CollectionTestCase { func check(count: Int, generator: G) { context.withTrace("count: \(count), generator: \(generator)") { withLifetimeTracking { tracker in - let (d, ref) = tracker.persistentDictionary(0 ..< count, with: generator) + let (d, ref) = tracker.shareableDictionary(0 ..< count, with: generator) withEvery("key", in: ref.keys) { key in let index = d.index(forKey: key) expectNotNil(index) { index in @@ -1320,7 +1320,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_indexForKey_fixtures() { withEachFixture { fixture in withLifetimeTracking { tracker in - let (d, ref) = tracker.persistentDictionary(for: fixture) + let (d, ref) = tracker.shareableDictionary(for: fixture) withEvery("offset", in: ref.indices) { offset in let key = ref[offset].key let value = ref[offset].value @@ -1338,7 +1338,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withLifetimeTracking { tracker in withEvery("isShared", in: [false, true]) { isShared in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withEvery("i", in: ref.indices) { _ in let (key, value) = ref.removeFirst() let index = d.index(forKey: key) @@ -1358,7 +1358,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_mapValues_basics() { let items = (0 ..< 100).map { ($0, 100 * $0) } - let d = PersistentDictionary(uniqueKeysWithValues: items) + let d = ShareableDictionary(uniqueKeysWithValues: items) var c = 0 let d2 = d.mapValues { value -> String in @@ -1378,7 +1378,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withLifetimeTracking { tracker in withEvery("isShared", in: [false, true]) { isShared in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withHiddenCopies(if: isShared, of: &d) { d in let d2 = d.mapValues { tracker.instance(for: "\($0.payload)") } let ref2 = Dictionary(uniqueKeysWithValues: ref.lazy.map { @@ -1393,7 +1393,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_compactMapValues_basics() { let items = (0 ..< 100).map { ($0, 100 * $0) } - let d = PersistentDictionary(uniqueKeysWithValues: items) + let d = ShareableDictionary(uniqueKeysWithValues: items) var c = 0 let d2 = d.compactMapValues { value -> String? in @@ -1423,7 +1423,7 @@ class PersistentDictionaryTests: CollectionTestCase { } withEvery("isShared", in: [false, true]) { isShared in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withHiddenCopies(if: isShared, of: &d) { d in let d2 = d.compactMapValues(transform) let r: [(Key, Value2)] = ref.compactMap { @@ -1440,7 +1440,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_filter_basics() { let items = (0 ..< 100).map { ($0, 100 * $0) } - let d = PersistentDictionary(uniqueKeysWithValues: items) + let d = ShareableDictionary(uniqueKeysWithValues: items) var c = 0 let d2 = d.filter { item in @@ -1463,7 +1463,7 @@ class PersistentDictionaryTests: CollectionTestCase { withEachFixture { fixture in withLifetimeTracking { tracker in withEvery("isShared", in: [false, true]) { isShared in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withHiddenCopies(if: isShared, of: &d) { d in func predicate(_ item: (key: Key, value: Value)) -> Bool { expectEqual(item.value.payload, 1000 + item.key.payload.identity) @@ -1487,7 +1487,7 @@ class PersistentDictionaryTests: CollectionTestCase { withLifetimeTracking { tracker in withEvery("isShared", in: [false, true]) { isShared in withEvery("i", in: 0 ..< fixture.count) { i in - var (d, ref) = tracker.persistentDictionary(for: fixture) + var (d, ref) = tracker.shareableDictionary(for: fixture) withHiddenCopies(if: isShared, of: &d) { d in func predicate(_ item: (key: Key, value: Value)) -> Bool { expectEqual(item.value.payload, 1000 + item.key.payload.identity) @@ -1506,7 +1506,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_filter_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentDictionary( + let x = ShareableDictionary( uniqueKeysWithValues: a.lazy.map { ($0, $0.identity + 100) }) @@ -1520,6 +1520,27 @@ class PersistentDictionaryTests: CollectionTestCase { } } + func test_removeAll_where_exhaustive() { + withEvery("isShared", in: [false, true]) { isShared in + withEverySubset("a", of: testItems) { a in + withEverySubset("b", of: a) { b in + var x = ShareableDictionary( + uniqueKeysWithValues: a.lazy.map { + ($0, $0.identity + 100) + }) + let y = Dictionary( + uniqueKeysWithValues: b.lazy.map { + ($0, $0.identity + 100) + }) + withHiddenCopies(if: isShared, of: &x) { x in + x.removeAll { y[$0.key] == nil } + expectEqualDictionaries(x, y) + } + } + } + } + } + func test_merge_exhaustive() { withEverySubset("a", of: testItems) { a in withEverySubset("b", of: testItems) { b in @@ -1536,9 +1557,9 @@ class PersistentDictionaryTests: CollectionTestCase { let expected2 = tracker.dictionary( for: b, by: { $0.identity + 200 }) - var actual1 = tracker.persistentDictionary( + var actual1 = tracker.shareableDictionary( for: a, by: { $0.identity + 100 }) - let actual2 = tracker.persistentDictionary( + let actual2 = tracker.shareableDictionary( for: b, by: { $0.identity + 200 }) expected1.merge(expected2, uniquingKeysWith: combine) @@ -1563,7 +1584,7 @@ class PersistentDictionaryTests: CollectionTestCase { // "two": 2, // "three": 3, // ] - // let d = PersistentDictionary(uniqueKeysWithValues: items) + // let d = ShareableDictionary(uniqueKeysWithValues: items) // expectEqualElements(d.sorted(by: <), items.sorted(by: <)) // } @@ -1574,7 +1595,7 @@ class PersistentDictionaryTests: CollectionTestCase { // "two": 2, // "three": 3, // ] - // let d = PersistentDictionary(uniqueKeysWithValues: items) + // let d = ShareableDictionary(uniqueKeysWithValues: items) // expectEqualElements(d.sorted(by: <), items.sorted(by: <)) // } @@ -1585,7 +1606,7 @@ class PersistentDictionaryTests: CollectionTestCase { ("two", 2), ("three", 3), ] - let d = PersistentDictionary(uniqueKeysWithValues: items) + let d = ShareableDictionary(uniqueKeysWithValues: items) expectEqualElements(d.sorted(by: <), items.sorted(by: <)) } @@ -1599,7 +1620,7 @@ class PersistentDictionaryTests: CollectionTestCase { // "b": 1, // "d": 3, // ] - // let d = PersistentDictionary(items, uniquingKeysWith: +) + // let d = ShareableDictionary(items, uniquingKeysWith: +) // expectEqualElements(d, [ // (key: "a", value: 5), // (key: "b", value: 2), @@ -1618,7 +1639,7 @@ class PersistentDictionaryTests: CollectionTestCase { // ("b", 1), // ("d", 3), // ] - // let d = PersistentDictionary(items, uniquingKeysWith: +) + // let d = ShareableDictionary(items, uniquingKeysWith: +) // expectEqualElements(d, [ // (key: "a", value: 5), // (key: "b", value: 2), @@ -1632,7 +1653,7 @@ class PersistentDictionaryTests: CollectionTestCase { // "one", "two", "three", "four", "five", // "six", "seven", "eight", "nine", "ten" // ] - // let d = PersistentDictionary( + // let d = ShareableDictionary( // grouping: items, // by: { $0.count }) // expectEqualElements(d, [ @@ -1649,7 +1670,7 @@ class PersistentDictionaryTests: CollectionTestCase { // "two": 2, // "three": 3, // ] - // let d = PersistentDictionary(uniqueKeysWithValues: items) + // let d = ShareableDictionary(uniqueKeysWithValues: items) // expectEqualElements(d, items) // } @@ -1660,15 +1681,15 @@ class PersistentDictionaryTests: CollectionTestCase { // ("two", 2), // ("three", 3), // ] - // let d = PersistentDictionary(uniqueKeysWithValues: items) + // let d = ShareableDictionary(uniqueKeysWithValues: items) // expectEqualElements(d, items) // } func test_ExpressibleByDictionaryLiteral() { - let d0: PersistentDictionary = [:] + let d0: ShareableDictionary = [:] expectTrue(d0.isEmpty) - let d1: PersistentDictionary = [ + let d1: ShareableDictionary = [ "1~one": 1, "2~two": 2, "3~three": 3, @@ -1683,7 +1704,7 @@ class PersistentDictionaryTests: CollectionTestCase { } // func test_keys() { - // let d: PersistentDictionary = [ + // let d: ShareableDictionary = [ // "one": 1, // "two": 2, // "three": 3, @@ -1695,7 +1716,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_counts() { withEvery("count", in: 0 ..< 30) { count in withLifetimeTracking { tracker in - let (d, _, _) = tracker.persistentDictionary(keys: 0 ..< count) + let (d, _, _) = tracker.shareableDictionary(keys: 0 ..< count) expectEqual(d.isEmpty, count == 0) expectEqual(d.count, count) expectEqual(d.underestimatedCount, count) @@ -1709,7 +1730,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_index_forKey() { withEvery("count", in: 0 ..< 30) { count in withLifetimeTracking { tracker in - let (d, _, _) = tracker.persistentDictionary(keys: 0 ..< count) + let (d, _, _) = tracker.shareableDictionary(keys: 0 ..< count) withEvery("offset", in: 0 ..< count) { offset in expectEqual( // NOTE: uses the actual order `d.keys` @@ -1729,9 +1750,9 @@ class PersistentDictionaryTests: CollectionTestCase { func test_subscript_offset() { withEvery("count", in: 0 ..< 30) { count in withLifetimeTracking { tracker in - let (d, _, _) = tracker.persistentDictionary(keys: 0 ..< count) + let (d, _, _) = tracker.shareableDictionary(keys: 0 ..< count) withEvery("offset", in: 0 ..< count) { offset in - let item = d[PersistentDictionaryIndex(value: offset)] + let item = d[ShareableDictionaryIndex(value: offset)] // NOTE: uses the actual order `d.keys` expectEqual(item.key, d.keys[offset]) // NOTE: uses the actual order `d.values` @@ -1745,7 +1766,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_subscript_getter() { withEvery("count", in: 0 ..< 30) { count in withLifetimeTracking { tracker in - let (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + let (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) withEvery("offset", in: 0 ..< count) { offset in expectEqual(d[keys[offset]], values[offset]) } @@ -1760,7 +1781,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in -// var (d, keys, values) = tracker.persistentDictionary( +// var (d, keys, values) = tracker.shareableDictionary( // keys: 0 ..< count) // let replacement = tracker.instance(for: -1) // withHiddenCopies(if: isShared, of: &d) { d in @@ -1783,7 +1804,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in -// var (d, keys, values) = tracker.persistentDictionary( +// var (d, keys, values) = tracker.shareableDictionary( // keys: 0 ..< count) // withHiddenCopies(if: isShared, of: &d) { d in // d[keys[offset]] = nil @@ -1807,7 +1828,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withLifetimeTracking { tracker in // let keys = tracker.instances(for: 0 ..< count) // let values = tracker.instances(for: (0 ..< count).map { 100 + $0 }) -// var d: PersistentDictionary, LifetimeTracked> = [:] +// var d: ShareableDictionary, LifetimeTracked> = [:] // withEvery("offset", in: 0 ..< count) { offset in // withHiddenCopies(if: isShared, of: &d) { d in // d[keys[offset]] = values[offset] @@ -1827,7 +1848,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("count", in: 0 ..< 30) { count in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in -// var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) +// var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // let key = tracker.instance(for: -1) // withHiddenCopies(if: isShared, of: &d) { d in // d[key] = nil @@ -1847,7 +1868,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // let replacement = tracker.instance(for: -1) // withHiddenCopies(if: isShared, of: &d) { d in // mutate(&d[keys[offset]]) { $0 = replacement } @@ -1869,7 +1890,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // withHiddenCopies(if: isShared, of: &d) { d in // let key = keys[offset] // mutate(&d[key]) { v in @@ -1896,7 +1917,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withLifetimeTracking { tracker in // let keys = tracker.instances(for: 0 ..< count) // let values = tracker.instances(for: (0 ..< count).map { 100 + $0 }) - // var d: PersistentDictionary, LifetimeTracked> = [:] + // var d: ShareableDictionary, LifetimeTracked> = [:] // withEvery("offset", in: 0 ..< count) { offset in // withHiddenCopies(if: isShared, of: &d) { d in // mutate(&d[keys[offset]]) { v in @@ -1920,7 +1941,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("count", in: 0 ..< 30) { count in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // let key = tracker.instance(for: -1) // withHiddenCopies(if: isShared, of: &d) { d in // mutate(&d[key]) { v in @@ -1942,7 +1963,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("count", in: 0 ..< 30) { count in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // let (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // let (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // let fallback = tracker.instance(for: -1) // withEvery("offset", in: 0 ..< count) { offset in // let key = keys[offset] @@ -1964,7 +1985,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // let replacement = tracker.instance(for: -1) // let fallback = tracker.instance(for: -1) // withHiddenCopies(if: isShared, of: &d) { d in @@ -1992,7 +2013,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withLifetimeTracking { tracker in // let keys = tracker.instances(for: 0 ..< count) // let values = tracker.instances(for: (0 ..< count).map { 100 + $0 }) - // var d: PersistentDictionary, LifetimeTracked> = [:] + // var d: ShareableDictionary, LifetimeTracked> = [:] // let fallback = tracker.instance(for: -1) // withEvery("offset", in: 0 ..< count) { offset in // withHiddenCopies(if: isShared, of: &d) { d in @@ -2019,7 +2040,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // let replacement = tracker.instance(for: -1) // withHiddenCopies(if: isShared, of: &d) { d in // let key = keys[offset] @@ -2044,7 +2065,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withLifetimeTracking { tracker in // let keys = tracker.instances(for: 0 ..< count) // let values = tracker.instances(for: (0 ..< count).map { 100 + $0 }) - // var d: PersistentDictionary, LifetimeTracked> = [:] + // var d: ShareableDictionary, LifetimeTracked> = [:] // withEvery("offset", in: 0 ..< count) { offset in // withHiddenCopies(if: isShared, of: &d) { d in // let key = keys[offset] @@ -2068,7 +2089,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // let replacement = tracker.instance(for: -1) // withHiddenCopies(if: isShared, of: &d) { d in // let key = keys[offset] @@ -2095,7 +2116,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withLifetimeTracking { tracker in // let keys = tracker.instances(for: 0 ..< count) // let values = tracker.instances(for: (0 ..< count).map { 100 + $0 }) - // var d: PersistentDictionary, LifetimeTracked> = [:] + // var d: ShareableDictionary, LifetimeTracked> = [:] // withEvery("offset", in: 0 ..< count) { offset in // withHiddenCopies(if: isShared, of: &d) { d in // let key = keys[count - 1 - offset] @@ -2122,7 +2143,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // let replacement = tracker.instance(for: -1) // let fallback = tracker.instance(for: -2) // withHiddenCopies(if: isShared, of: &d) { d in @@ -2150,7 +2171,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withLifetimeTracking { tracker in // let keys = tracker.instances(for: 0 ..< count) // let values = tracker.instances(for: (0 ..< count).map { 100 + $0 }) - // var d: PersistentDictionary, LifetimeTracked> = [:] + // var d: ShareableDictionary, LifetimeTracked> = [:] // let fallback = tracker.instance(for: -2) // withEvery("offset", in: 0 ..< count) { offset in // withHiddenCopies(if: isShared, of: &d) { d in @@ -2177,7 +2198,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // let replacement = tracker.instance(for: -1) // let fallback = tracker.instance(for: -2) // withHiddenCopies(if: isShared, of: &d) { d in @@ -2206,7 +2227,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withLifetimeTracking { tracker in // let keys = tracker.instances(for: 0 ..< count) // let values = tracker.instances(for: (0 ..< count).map { 100 + $0 }) - // var d: PersistentDictionary, LifetimeTracked> = [:] + // var d: ShareableDictionary, LifetimeTracked> = [:] // let fallback = tracker.instance(for: -2) // withEvery("offset", in: 0 ..< count) { offset in // withHiddenCopies(if: isShared, of: &d) { d in @@ -2234,7 +2255,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // withHiddenCopies(if: isShared, of: &d) { d in // let key = keys.remove(at: offset) // let expected = values.remove(at: offset) @@ -2256,7 +2277,7 @@ class PersistentDictionaryTests: CollectionTestCase { // } // func test_merge_labeled_tuple() { - // var d: PersistentDictionary = [ + // var d: ShareableDictionary = [ // "one": 1, // "two": 1, // "three": 1, @@ -2281,7 +2302,7 @@ class PersistentDictionaryTests: CollectionTestCase { // } // func test_merge_unlabeled_tuple() { - // var d: PersistentDictionary = [ + // var d: ShareableDictionary = [ // "one": 1, // "two": 1, // "three": 1, @@ -2306,7 +2327,7 @@ class PersistentDictionaryTests: CollectionTestCase { // } // func test_merging_labeled_tuple() { - // let d: PersistentDictionary = [ + // let d: ShareableDictionary = [ // "one": 1, // "two": 1, // "three": 1, @@ -2337,7 +2358,7 @@ class PersistentDictionaryTests: CollectionTestCase { // } // func test_merging_unlabeled_tuple() { - // let d: PersistentDictionary = [ + // let d: ShareableDictionary = [ // "one": 1, // "two": 1, // "three": 1, @@ -2369,7 +2390,7 @@ class PersistentDictionaryTests: CollectionTestCase { // func test_filter() { // let items = (0 ..< 100).map { ($0, 100 * $0) } - // let d = PersistentDictionary(uniqueKeysWithValues: items) + // let d = ShareableDictionary(uniqueKeysWithValues: items) // // var c = 0 // let d2 = d.filter { item in @@ -2387,7 +2408,7 @@ class PersistentDictionaryTests: CollectionTestCase { // func test_mapValues() { // let items = (0 ..< 100).map { ($0, 100 * $0) } - // let d = PersistentDictionary(uniqueKeysWithValues: items) + // let d = ShareableDictionary(uniqueKeysWithValues: items) // // var c = 0 // let d2 = d.mapValues { value -> String in @@ -2405,7 +2426,7 @@ class PersistentDictionaryTests: CollectionTestCase { // func test_compactMapValue() { // let items = (0 ..< 100).map { ($0, 100 * $0) } - // let d = PersistentDictionary(uniqueKeysWithValues: items) + // let d = ShareableDictionary(uniqueKeysWithValues: items) // // var c = 0 // let d2 = d.compactMapValues { value -> String? in @@ -2426,7 +2447,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("count", in: 0 ..< 30) { count in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, _, _) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, _, _) = tracker.shareableDictionary(keys: 0 ..< count) // withHiddenCopies(if: isShared, of: &d) { d in // d.removeAll() // expectEqual(d.keys.__unstable.scale, 0) @@ -2442,7 +2463,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("offset", in: 0 ..< count) { offset in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // withHiddenCopies(if: isShared, of: &d) { d in // let actual = d.remove(at: offset) // let expectedKey = keys.remove(at: offset) @@ -2464,7 +2485,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEveryRange("range", in: 0 ..< count) { range in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // withHiddenCopies(if: isShared, of: &d) { d in // d.removeSubrange(range) // keys.removeSubrange(range) @@ -2480,7 +2501,7 @@ class PersistentDictionaryTests: CollectionTestCase { // } // func test_removeSubrange_rangeExpression() { - // let d = PersistentDictionary(uniqueKeys: 0 ..< 30, values: 100 ..< 130) + // let d = ShareableDictionary(uniqueKeys: 0 ..< 30, values: 100 ..< 130) // let item = (0 ..< 30).map { (key: $0, value: 100 + $0) } // // var d1 = d @@ -2499,7 +2520,7 @@ class PersistentDictionaryTests: CollectionTestCase { // func test_removeLast() { // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< 30) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< 30) // withEvery("i", in: 0 ..< d.count) { i in // withHiddenCopies(if: isShared, of: &d) { d in // let actual = d.removeLast() @@ -2519,7 +2540,7 @@ class PersistentDictionaryTests: CollectionTestCase { // func test_removeFirst() { // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< 30) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< 30) // withEvery("i", in: 0 ..< d.count) { i in // withHiddenCopies(if: isShared, of: &d) { d in // let actual = d.removeFirst() @@ -2541,7 +2562,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("suffix", in: 0 ..< count) { suffix in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // withHiddenCopies(if: isShared, of: &d) { d in // d.removeLast(suffix) // keys.removeLast(suffix) @@ -2561,7 +2582,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("prefix", in: 0 ..< count) { prefix in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // withHiddenCopies(if: isShared, of: &d) { d in // d.removeFirst(prefix) // keys.removeFirst(prefix) @@ -2581,7 +2602,7 @@ class PersistentDictionaryTests: CollectionTestCase { // withEvery("n", in: [2, 3, 4]) { n in // withEvery("isShared", in: [false, true]) { isShared in // withLifetimeTracking { tracker in - // var (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + // var (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) // var items = zip(keys, values).map { (key: $0.0, value: $0.1) } // withHiddenCopies(if: isShared, of: &d) { d in // d.removeAll(where: { !$0.key.payload.isMultiple(of: n) }) @@ -2597,7 +2618,7 @@ class PersistentDictionaryTests: CollectionTestCase { func test_Sequence() { withEvery("count", in: 0 ..< 30) { count in withLifetimeTracking { tracker in - let (d, keys, values) = tracker.persistentDictionary(keys: 0 ..< count) + let (d, keys, values) = tracker.shareableDictionary(keys: 0 ..< count) let items = zip(keys, values).map { (key: $0.0, value: $0.1) } checkSequence( { d.sorted(by: <) }, diff --git a/Tests/PersistentCollectionsTests/PersistentDictionary.Keys Tests.swift b/Tests/ShareableHashedCollectionsTests/ShareableDictionary.Keys Tests.swift similarity index 80% rename from Tests/PersistentCollectionsTests/PersistentDictionary.Keys Tests.swift rename to Tests/ShareableHashedCollectionsTests/ShareableDictionary.Keys Tests.swift index 39e4f28f..f5a4c2ee 100644 --- a/Tests/PersistentCollectionsTests/PersistentDictionary.Keys Tests.swift +++ b/Tests/ShareableHashedCollectionsTests/ShareableDictionary.Keys Tests.swift @@ -11,13 +11,13 @@ import XCTest import _CollectionsTestSupport -import PersistentCollections +import ShareableHashedCollections -class PersistentDictionaryKeysTests: CollectionTestCase { +class ShareableDictionaryKeysTests: CollectionTestCase { func test_BidirectionalCollection_fixtures() { withEachFixture { fixture in withLifetimeTracking { tracker in - let (d, ref) = tracker.persistentDictionary(for: fixture) + let (d, ref) = tracker.shareableDictionary(for: fixture) let k = ref.map { $0.key } checkCollection(d.keys, expectedContents: k, by: ==) _checkBidirectionalCollection_indexOffsetBy( @@ -27,7 +27,7 @@ class PersistentDictionaryKeysTests: CollectionTestCase { } func test_descriptions() { - let d: PersistentDictionary = [ + let d: ShareableDictionary = [ "a": 1, "b": 2 ] @@ -36,18 +36,18 @@ class PersistentDictionaryKeysTests: CollectionTestCase { expectEqual(d.keys.description, "[a, b]") expectEqual( d.keys.debugDescription, - "PersistentDictionary.Keys([\"a\", \"b\"])") + "ShareableDictionary.Keys([\"a\", \"b\"])") } else { expectEqual(d.keys.description, "[b, a]") expectEqual( d.keys.debugDescription, - "PersistentDictionary.Keys([\"b\", \"a\"])") + "ShareableDictionary.Keys([\"b\", \"a\"])") } } func test_contains() { withEverySubset("a", of: testItems) { a in - let x = PersistentDictionary( + let x = ShareableDictionary( uniqueKeysWithValues: a.lazy.map { ($0, 2 * $0.identity) }) let u = Set(a) @@ -68,15 +68,15 @@ class PersistentDictionaryKeysTests: CollectionTestCase { func test_intersection_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentDictionary( + let x = ShareableDictionary( uniqueKeysWithValues: a.lazy.map { ($0, 2 * $0.identity) }) let u = Set(a) expectEqualSets(x.keys.intersection(x.keys), u) withEverySubset("b", of: testItems) { b in - let y = PersistentDictionary( + let y = ShareableDictionary( uniqueKeysWithValues: b.lazy.map { ($0, -$0.identity - 1) }) let v = Set(b) - let z = PersistentSet(b) + let z = ShareableSet(b) let reference = u.intersection(v) @@ -88,15 +88,15 @@ class PersistentDictionaryKeysTests: CollectionTestCase { func test_subtracting_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentDictionary( + let x = ShareableDictionary( uniqueKeysWithValues: a.lazy.map { ($0, 2 * $0.identity) }) let u = Set(a) expectEqualSets(x.keys.subtracting(x.keys), []) withEverySubset("b", of: testItems) { b in - let y = PersistentDictionary( + let y = ShareableDictionary( uniqueKeysWithValues: b.lazy.map { ($0, -$0.identity - 1) }) let v = Set(b) - let z = PersistentSet(b) + let z = ShareableSet(b) let reference = u.subtracting(v) diff --git a/Tests/PersistentCollectionsTests/PersistentDictionary.Values Tests.swift b/Tests/ShareableHashedCollectionsTests/ShareableDictionary.Values Tests.swift similarity index 84% rename from Tests/PersistentCollectionsTests/PersistentDictionary.Values Tests.swift rename to Tests/ShareableHashedCollectionsTests/ShareableDictionary.Values Tests.swift index e3d93368..47609c0d 100644 --- a/Tests/PersistentCollectionsTests/PersistentDictionary.Values Tests.swift +++ b/Tests/ShareableHashedCollectionsTests/ShareableDictionary.Values Tests.swift @@ -11,13 +11,13 @@ import XCTest import _CollectionsTestSupport -import PersistentCollections +import ShareableHashedCollections -class PersistentDictionaryValuesTests: CollectionTestCase { +class ShareableDictionaryValuesTests: CollectionTestCase { func test_BidirectionalCollection_fixtures() { withEachFixture { fixture in withLifetimeTracking { tracker in - let (d, ref) = tracker.persistentDictionary(for: fixture) + let (d, ref) = tracker.shareableDictionary(for: fixture) let v = ref.map { $0.value } checkCollection(d.values, expectedContents: v, by: ==) _checkBidirectionalCollection_indexOffsetBy( @@ -27,7 +27,7 @@ class PersistentDictionaryValuesTests: CollectionTestCase { } func test_descriptions() { - let d: PersistentDictionary = [ + let d: ShareableDictionary = [ "a": 1, "b": 2 ] diff --git a/Tests/PersistentCollectionsTests/PersistentCollections Fixtures.swift b/Tests/ShareableHashedCollectionsTests/ShareableHashedCollections Fixtures.swift similarity index 89% rename from Tests/PersistentCollectionsTests/PersistentCollections Fixtures.swift rename to Tests/ShareableHashedCollectionsTests/ShareableHashedCollections Fixtures.swift index 8920eef7..6c260abb 100644 --- a/Tests/PersistentCollectionsTests/PersistentCollections Fixtures.swift +++ b/Tests/ShareableHashedCollectionsTests/ShareableHashedCollections Fixtures.swift @@ -10,7 +10,7 @@ //===----------------------------------------------------------------------===// import _CollectionsTestSupport -import PersistentCollections +import ShareableHashedCollections /// A set of items whose subsets will produce a bunch of interesting test /// cases. @@ -33,24 +33,24 @@ let testItems = [ ] extension LifetimeTracker { - func persistentDictionary( + func shareableDictionary( for items: C, keyTransform: (C.Element) -> Key, valueTransform: (C.Element) -> Value - ) -> PersistentDictionary, LifetimeTracked> { + ) -> ShareableDictionary, LifetimeTracked> { let keys = instances(for: items, by: keyTransform) let values = instances(for: items, by: valueTransform) - return PersistentDictionary(uniqueKeysWithValues: zip(keys, values)) + return ShareableDictionary(uniqueKeysWithValues: zip(keys, values)) } - func persistentDictionary( + func shareableDictionary( for keys: C, by valueTransform: (C.Element) -> Value - ) -> PersistentDictionary, LifetimeTracked> + ) -> ShareableDictionary, LifetimeTracked> where C.Element: Hashable { let k = instances(for: keys) let v = instances(for: keys, by: valueTransform) - return PersistentDictionary(uniqueKeysWithValues: zip(k, v)) + return ShareableDictionary(uniqueKeysWithValues: zip(k, v)) } func dictionary( @@ -266,7 +266,7 @@ struct Fixture { init(title: String, contents: [String]) { self.title = title - let maxDepth = PersistentDictionary._maxDepth + let maxDepth = ShareableDictionary._maxDepth func normalized(_ path: String) -> String { precondition(path.unicodeScalars.count < maxDepth) @@ -357,11 +357,11 @@ func withEachFixture( } extension LifetimeTracker { - func persistentSet( + func shareableSet( for fixture: Fixture, with transform: (RawCollider) -> Element ) -> ( - map: PersistentSet>, + map: ShareableSet>, ref: [LifetimeTracked] ) { let ref = fixture.itemsInIterationOrder.map { key in @@ -370,24 +370,24 @@ extension LifetimeTracker { let ref2 = fixture.itemsInInsertionOrder.map { key in self.instance(for: transform(key)) } - return (PersistentSet(ref2), ref) + return (ShareableSet(ref2), ref) } - func persistentSet( + func shareableSet( for fixture: Fixture ) -> ( - map: PersistentSet>, + map: ShareableSet>, ref: [LifetimeTracked] ) { - persistentSet(for: fixture) { key in key } + shareableSet(for: fixture) { key in key } } - func persistentDictionary( + func shareableDictionary( for fixture: Fixture, keyTransform: (RawCollider) -> Key, valueTransform: (RawCollider) -> Value ) -> ( - map: PersistentDictionary, LifetimeTracked>, + map: ShareableDictionary, LifetimeTracked>, ref: [(key: LifetimeTracked, value: LifetimeTracked)] ) { typealias K = LifetimeTracked @@ -403,28 +403,28 @@ extension LifetimeTracker { let value = valueTransform(item) return (key: self.instance(for: key), value: self.instance(for: value)) } - return (PersistentDictionary(uniqueKeysWithValues: ref2), ref) + return (ShareableDictionary(uniqueKeysWithValues: ref2), ref) } - func persistentDictionary( + func shareableDictionary( for fixture: Fixture, valueTransform: (Int) -> Value ) -> ( - map: PersistentDictionary, LifetimeTracked>, + map: ShareableDictionary, LifetimeTracked>, ref: [(key: LifetimeTracked, value: LifetimeTracked)] ) { - persistentDictionary( + shareableDictionary( for: fixture, keyTransform: { $0 }, valueTransform: { valueTransform($0.identity) }) } - func persistentDictionary( + func shareableDictionary( for fixture: Fixture ) -> ( - map: PersistentDictionary, LifetimeTracked>, + map: ShareableDictionary, LifetimeTracked>, ref: [(key: LifetimeTracked, value: LifetimeTracked)] ) { - persistentDictionary(for: fixture) { $0 + 1000 } + shareableDictionary(for: fixture) { $0 + 1000 } } } diff --git a/Tests/PersistentCollectionsTests/PersistentSet Tests.swift b/Tests/ShareableHashedCollectionsTests/ShareableSet Tests.swift similarity index 81% rename from Tests/PersistentCollectionsTests/PersistentSet Tests.swift rename to Tests/ShareableHashedCollectionsTests/ShareableSet Tests.swift index 68930a36..b9e7cc4d 100644 --- a/Tests/PersistentCollectionsTests/PersistentSet Tests.swift +++ b/Tests/ShareableHashedCollectionsTests/ShareableSet Tests.swift @@ -10,13 +10,13 @@ //===----------------------------------------------------------------------===// import _CollectionsTestSupport -import PersistentCollections +import ShareableHashedCollections -extension PersistentSet: SetAPIExtras {} +extension ShareableSet: SetAPIExtras {} -class PersistentSetTests: CollectionTestCase { +class ShareableSetTests: CollectionTestCase { func test_init_empty() { - let set = PersistentSet() + let set = ShareableSet() expectEqual(set.count, 0) expectTrue(set.isEmpty) expectEqualElements(set, []) @@ -25,7 +25,7 @@ class PersistentSetTests: CollectionTestCase { func test_BidirectionalCollection_fixtures() { withEachFixture { fixture in withLifetimeTracking { tracker in - let (set, ref) = tracker.persistentSet(for: fixture) + let (set, ref) = tracker.shareableSet(for: fixture) checkCollection(set, expectedContents: ref, by: ==) _checkBidirectionalCollection_indexOffsetBy( set, expectedContents: ref, by: ==) @@ -34,7 +34,7 @@ class PersistentSetTests: CollectionTestCase { } func test_BidirectionalCollection_random100() { - let s = PersistentSet(0 ..< 100) + let s = ShareableSet(0 ..< 100) let ref = Array(s) checkCollection(s, expectedContents: ref) _checkBidirectionalCollection_indexOffsetBy( @@ -42,7 +42,7 @@ class PersistentSetTests: CollectionTestCase { } func test_basics() { - var set: PersistentSet> = [] + var set: ShareableSet> = [] let a1 = HashableBox(1) let a2 = HashableBox(1) @@ -81,17 +81,17 @@ class PersistentSetTests: CollectionTestCase { } func test_descriptions() { - let empty: PersistentSet = [] + let empty: ShareableSet = [] expectEqual(empty.description, "[]") - expectEqual(empty.debugDescription, "PersistentSet([])") + expectEqual(empty.debugDescription, "ShareableSet([])") - let a: PersistentSet = ["a"] + let a: ShareableSet = ["a"] expectEqual(a.description, "[a]") - expectEqual(a.debugDescription, "PersistentSet([\"a\"])") + expectEqual(a.debugDescription, "ShareableSet([\"a\"])") } func test_index_descriptions() { - let a: PersistentSet = [ + let a: ShareableSet = [ RawCollider(1, "1"), RawCollider(2, "21"), RawCollider(3, "22"), @@ -114,7 +114,7 @@ class PersistentSetTests: CollectionTestCase { } func test_index_hashing() { - let s = PersistentSet(0 ..< 100) + let s = ShareableSet(0 ..< 100) checkHashable(s.indices, equalityOracle: ==) } @@ -122,7 +122,7 @@ class PersistentSetTests: CollectionTestCase { withEachFixture { fixture in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var s: PersistentSet> = [] + var s: ShareableSet> = [] var ref: Set> = [] withEvery("i", in: 0 ..< fixture.count) { i in withHiddenCopies(if: isShared, of: &s) { s in @@ -147,7 +147,7 @@ class PersistentSetTests: CollectionTestCase { withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in withEvery("offset", in: 0 ..< fixture.count) { offset in - let f = tracker.persistentSet(for: fixture) + let f = tracker.shareableSet(for: fixture) var s = f.map var ref = Set(f.ref) withHiddenCopies(if: isShared, of: &s) { s in @@ -167,9 +167,9 @@ class PersistentSetTests: CollectionTestCase { let b = RawCollider(2, "B") let c = RawCollider(3, "C") - let s0: PersistentSet = [] - let s1: PersistentSet = [a, b] - let s2: PersistentSet = [a, c] + let s0: ShareableSet = [] + let s1: ShareableSet = [a, b] + let s2: ShareableSet = [a, c] expectEqualSets(s0.intersection(s0), []) expectEqualSets(s1.intersection(s0), []) @@ -181,8 +181,8 @@ class PersistentSetTests: CollectionTestCase { let ab = RawCollider(4, "AB") let ac = RawCollider(5, "AC") - let s3: PersistentSet = [ab, ac] - let s4: PersistentSet = [a, ab] + let s3: ShareableSet = [ab, ac] + let s4: ShareableSet = [a, ab] expectEqualSets(s1.intersection(s3), []) expectEqualSets(s2.intersection(s3), []) expectEqualSets(s1.intersection(s4), [a]) @@ -194,7 +194,7 @@ class PersistentSetTests: CollectionTestCase { let ad = RawCollider(6, "AD") let ae = RawCollider(7, "AE") - let s5: PersistentSet = [a, ab, ad, ae] + let s5: ShareableSet = [a, ab, ad, ae] expectEqualSets(s1.intersection(s5), [a]) expectEqualSets(s2.intersection(s5), [a]) expectEqualSets(s3.intersection(s5), [ab]) @@ -207,7 +207,7 @@ class PersistentSetTests: CollectionTestCase { let af1 = RawCollider(8, "AF") let af2 = RawCollider(9, "AF") - let s6: PersistentSet = [af1, af2] + let s6: ShareableSet = [af1, af2] expectEqualSets(s1.intersection(s6), []) expectEqualSets(s2.intersection(s6), []) expectEqualSets(s3.intersection(s6), []) @@ -221,7 +221,7 @@ class PersistentSetTests: CollectionTestCase { expectEqualSets(s6.intersection(s5), []) let af3 = RawCollider(10, "AF") - let s7: PersistentSet = [af1, af3] + let s7: ShareableSet = [af1, af3] expectEqualSets(s1.intersection(s7), []) expectEqualSets(s2.intersection(s7), []) expectEqualSets(s3.intersection(s7), []) @@ -236,7 +236,7 @@ class PersistentSetTests: CollectionTestCase { expectEqualSets(s7.intersection(s5), []) expectEqualSets(s7.intersection(s6), [af1]) - let s8: PersistentSet = [a, af1] + let s8: ShareableSet = [a, af1] expectEqualSets(s1.intersection(s8), [a]) expectEqualSets(s2.intersection(s8), [a]) expectEqualSets(s3.intersection(s8), []) @@ -255,25 +255,25 @@ class PersistentSetTests: CollectionTestCase { let afa1 = RawCollider(11, "AFA") let afa2 = RawCollider(12, "AFA") - let s9: PersistentSet = [afa1, afa2] + let s9: ShareableSet = [afa1, afa2] expectEqualSets(s9.intersection(s6), []) expectEqualSets(s6.intersection(s9), []) } func test_isEqual_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectTrue(x.isEqualSet(to: x)) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = (u == v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S ) -> Bool where S.Element == RawCollider { @@ -292,18 +292,18 @@ class PersistentSetTests: CollectionTestCase { func test_isSubset_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectTrue(x.isSubset(of: x)) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = u.isSubset(of: v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S ) -> Bool where S.Element == RawCollider { @@ -322,18 +322,18 @@ class PersistentSetTests: CollectionTestCase { func test_isSuperset_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectTrue(x.isSuperset(of: x)) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = u.isSuperset(of: v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S ) -> Bool where S.Element == RawCollider { @@ -352,18 +352,18 @@ class PersistentSetTests: CollectionTestCase { func test_isStrictSubset_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectFalse(x.isStrictSubset(of: x)) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = u.isStrictSubset(of: v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S ) -> Bool where S.Element == RawCollider { @@ -382,18 +382,18 @@ class PersistentSetTests: CollectionTestCase { func test_isStrictSuperset_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectFalse(x.isStrictSuperset(of: x)) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = u.isStrictSuperset(of: v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S ) -> Bool where S.Element == RawCollider { @@ -412,17 +412,17 @@ class PersistentSetTests: CollectionTestCase { func test_isDisjoint_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectEqual(x.isDisjoint(with: x), x.isEmpty) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = u.isDisjoint(with: v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S ) -> Bool where S.Element == RawCollider { @@ -441,20 +441,20 @@ class PersistentSetTests: CollectionTestCase { func test_intersection_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectEqualSets(x.intersection(x), u) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = u.intersection(v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S - ) -> PersistentSet + ) -> ShareableSet where S.Element == RawCollider { a.intersection(b) } @@ -471,20 +471,20 @@ class PersistentSetTests: CollectionTestCase { func test_subtracting_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectEqualSets(x.subtracting(x), []) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = u.subtracting(v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S - ) -> PersistentSet + ) -> ShareableSet where S.Element == RawCollider { a.subtracting(b) } @@ -501,7 +501,7 @@ class PersistentSetTests: CollectionTestCase { func test_filter_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) withEverySubset("b", of: a) { b in let v = Set(b) expectEqualSets(x.filter { v.contains($0) }, v) @@ -509,22 +509,37 @@ class PersistentSetTests: CollectionTestCase { } } + func test_removeAll_where_exhaustive() { + withEvery("isShared", in: [false, true]) { isShared in + withEverySubset("a", of: testItems) { a in + withEverySubset("b", of: a) { b in + var x = ShareableSet(a) + let v = Set(b) + withHiddenCopies(if: isShared, of: &x) { x in + x.removeAll { !v.contains($0) } + expectEqualSets(x, v) + } + } + } + } + } + func test_union_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectEqualSets(x.union(x), u) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = u.union(v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S - ) -> PersistentSet + ) -> ShareableSet where S.Element == RawCollider { a.union(b) } @@ -541,20 +556,20 @@ class PersistentSetTests: CollectionTestCase { func test_symmetricDifference_exhaustive() { withEverySubset("a", of: testItems) { a in - let x = PersistentSet(a) + let x = ShareableSet(a) let u = Set(a) expectEqualSets(x.symmetricDifference(x), []) withEverySubset("b", of: testItems) { b in - let y = PersistentSet(b) + let y = ShareableSet(b) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) let reference = u.symmetricDifference(v) func checkSequence( - _ a: PersistentSet, + _ a: ShareableSet, _ b: S - ) -> PersistentSet + ) -> ShareableSet where S.Element == RawCollider { a.symmetricDifference(b) } @@ -573,15 +588,15 @@ class PersistentSetTests: CollectionTestCase { let a = [1, 2, 3, 4] let b = [0, 2, 4, 6] - let x = PersistentSet(a) - let y = PersistentSet(b) + let x = ShareableSet(a) + let y = ShareableSet(b) let u = Set(a) let v = Set(b) - let z = PersistentDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) + let z = ShareableDictionary(uniqueKeysWithValues: b.map { ($0, $0) }) func check( _ reference: Set, - _ body: (inout PersistentSet) -> Void, + _ body: (inout ShareableSet) -> Void, file: StaticString = #file, line: UInt = #line ) { @@ -628,7 +643,7 @@ class PersistentSetTests: CollectionTestCase { withEvery("offset", in: 0 ..< a.count) { offset in withEvery("isShared", in: [false, true]) { isShared in withLifetimeTracking { tracker in - var x = PersistentSet(tracker.instances(for: a)) + var x = ShareableSet(tracker.instances(for: a)) let i = x.firstIndex { $0.payload == a[offset] }! let replacement = tracker.instance(for: a[offset]) withHiddenCopies(if: isShared, of: &x) { x in @@ -643,7 +658,7 @@ class PersistentSetTests: CollectionTestCase { } func test_Hashable() { - let classes: [[PersistentSet]] = [ + let classes: [[ShareableSet]] = [ [ [] ], @@ -683,43 +698,43 @@ class PersistentSetTests: CollectionTestCase { } func test_Codable() throws { - let s1: PersistentSet = [] + let s1: ShareableSet = [] let v1: MinimalEncoder.Value = .array([]) expectEqual(try MinimalEncoder.encode(s1), v1) - let s2: PersistentSet = [3] + let s2: ShareableSet = [3] let v2: MinimalEncoder.Value = .array([.int(3)]) expectEqual(try MinimalEncoder.encode(s2), v2) - let s3: PersistentSet = [0, 1, 2, 3] + let s3: ShareableSet = [0, 1, 2, 3] let v3: MinimalEncoder.Value = .array(s3.map { .int($0) }) expectEqual(try MinimalEncoder.encode(s3), v3) - let s4 = PersistentSet(0 ..< 100) + let s4 = ShareableSet(0 ..< 100) let v4: MinimalEncoder.Value = .array(s4.map { .int($0) }) expectEqual(try MinimalEncoder.encode(s4), v4) } func test_Decodable() throws { - let s1: PersistentSet = [] + let s1: ShareableSet = [] let v1: MinimalEncoder.Value = .array([]) - expectEqual(try MinimalDecoder.decode(v1, as: PersistentSet.self), s1) + expectEqual(try MinimalDecoder.decode(v1, as: ShareableSet.self), s1) - let s2: PersistentSet = [3] + let s2: ShareableSet = [3] let v2: MinimalEncoder.Value = .array([.int(3)]) - expectEqual(try MinimalDecoder.decode(v2, as: PersistentSet.self), s2) + expectEqual(try MinimalDecoder.decode(v2, as: ShareableSet.self), s2) - let s3: PersistentSet = [0, 1, 2, 3] + let s3: ShareableSet = [0, 1, 2, 3] let v3: MinimalEncoder.Value = .array([.int(0), .int(1), .int(2), .int(3)]) - expectEqual(try MinimalDecoder.decode(v3, as: PersistentSet.self), s3) + expectEqual(try MinimalDecoder.decode(v3, as: ShareableSet.self), s3) - let s4 = PersistentSet(0 ..< 100) + let s4 = ShareableSet(0 ..< 100) let v4: MinimalEncoder.Value = .array((0 ..< 100).map { .int($0) }) - expectEqual(try MinimalDecoder.decode(v4, as: PersistentSet.self), s4) + expectEqual(try MinimalDecoder.decode(v4, as: ShareableSet.self), s4) let v5: MinimalEncoder.Value = .array([.int(0), .int(1), .int(0)]) expectThrows( - try MinimalDecoder.decode(v5, as: PersistentSet.self) + try MinimalDecoder.decode(v5, as: ShareableSet.self) ) { error in expectNotNil(error as? DecodingError) { error in guard case .dataCorrupted(let context) = error else { @@ -733,7 +748,7 @@ class PersistentSetTests: CollectionTestCase { let v6: MinimalEncoder.Value = .array([.int16(42)]) expectThrows( - try MinimalDecoder.decode(v6, as: PersistentSet.self) + try MinimalDecoder.decode(v6, as: ShareableSet.self) ) { error in expectNotNil(error as? DecodingError) { error in guard case .typeMismatch(_, _) = error else { @@ -745,7 +760,7 @@ class PersistentSetTests: CollectionTestCase { } func test_CustomReflectable() { - let s: PersistentSet = [0, 1, 2, 3] + let s: ShareableSet = [0, 1, 2, 3] let mirror = Mirror(reflecting: s) expectEqual(mirror.displayStyle, .set) expectNil(mirror.superclassMirror) diff --git a/Tests/PersistentCollectionsTests/Utilities.swift b/Tests/ShareableHashedCollectionsTests/Utilities.swift similarity index 88% rename from Tests/PersistentCollectionsTests/Utilities.swift rename to Tests/ShareableHashedCollectionsTests/Utilities.swift index 8184f643..296b8187 100644 --- a/Tests/PersistentCollectionsTests/Utilities.swift +++ b/Tests/ShareableHashedCollectionsTests/Utilities.swift @@ -10,13 +10,13 @@ //===----------------------------------------------------------------------===// import _CollectionsTestSupport -import PersistentCollections +import ShareableHashedCollections extension LifetimeTracker { - func persistentDictionary( + func shareableDictionary( keys: Keys ) -> ( - dictionary: PersistentDictionary, LifetimeTracked>, + dictionary: ShareableDictionary, LifetimeTracked>, keys: [LifetimeTracked], values: [LifetimeTracked] ) @@ -25,7 +25,7 @@ extension LifetimeTracker { let k = Array(keys) let keys = self.instances(for: k) let values = self.instances(for: k.map { $0 + 100 }) - let dictionary = PersistentDictionary( + let dictionary = ShareableDictionary( uniqueKeysWithValues: zip(keys, values)) return (dictionary, keys, values) } @@ -80,11 +80,11 @@ struct ColliderDataGenerator: DataGenerator { } extension LifetimeTracker { - func persistentDictionary( + func shareableDictionary( _ payloads: Payloads, with generator: G ) -> ( - map: PersistentDictionary, LifetimeTracked>, + map: ShareableDictionary, LifetimeTracked>, expected: [LifetimeTracked: LifetimeTracked] ) where Payloads.Element == Int @@ -97,20 +97,20 @@ extension LifetimeTracker { instance(for: generator.value(for: $0))) } } - let map = PersistentDictionary(uniqueKeysWithValues: gen()) + let map = ShareableDictionary(uniqueKeysWithValues: gen()) let expected = Dictionary(uniqueKeysWithValues: gen()) return (map, expected) } - func persistentDictionary( + func shareableDictionary( keys: Keys ) -> ( - map: PersistentDictionary, LifetimeTracked>, + map: ShareableDictionary, LifetimeTracked>, expected: [LifetimeTracked: LifetimeTracked] ) where Keys.Element == Int { - persistentDictionary(keys, with: IntDataGenerator(valueOffset: 100)) + shareableDictionary(keys, with: IntDataGenerator(valueOffset: 100)) } } @@ -131,7 +131,7 @@ func _expectFailure( } func expectEqualSets( - _ set: PersistentSet, + _ set: ShareableSet, _ ref: [Element], _ message: @autoclosure () -> String = "", trapping: Bool = false, @@ -184,7 +184,7 @@ func expectEqualSets( func expectEqualDictionaries( - _ map: PersistentDictionary, + _ map: ShareableDictionary, _ ref: [(key: Key, value: Value)], _ message: @autoclosure () -> String = "", trapping: Bool = false, @@ -199,7 +199,7 @@ func expectEqualDictionaries( } func expectEqualDictionaries( - _ map: PersistentDictionary, + _ map: ShareableDictionary, _ dict: Dictionary, _ message: @autoclosure () -> String = "", trapping: Bool = false, diff --git a/Utils/generate-docs.sh b/Utils/generate-docs.sh index 448e5cfa..0f8bd669 100755 --- a/Utils/generate-docs.sh +++ b/Utils/generate-docs.sh @@ -31,7 +31,7 @@ rm -rf "$output_dir_base" components="\ BitCollections DequeModule HeapModule OrderedCollections \ - PersistentCollections" + ShareableHashedCollections" if [ $# -eq 0 ]; then targets="Collections $components" diff --git a/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/Collections.xcscheme b/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/Collections.xcscheme index 4177043a..49df7e5c 100644 --- a/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/Collections.xcscheme +++ b/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/Collections.xcscheme @@ -98,9 +98,9 @@ buildForAnalyzing = "YES"> @@ -157,9 +157,9 @@ skipped = "NO"> diff --git a/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/PersistentCollections.xcscheme b/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/ShareableHashedCollections.xcscheme similarity index 78% rename from Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/PersistentCollections.xcscheme rename to Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/ShareableHashedCollections.xcscheme index 7b0b2a8b..df107a2c 100644 --- a/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/PersistentCollections.xcscheme +++ b/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/ShareableHashedCollections.xcscheme @@ -14,9 +14,9 @@ buildForAnalyzing = "YES"> @@ -28,9 +28,9 @@ buildForAnalyzing = "NO"> @@ -48,9 +48,9 @@ skipped = "NO"> @@ -76,9 +76,9 @@ diff --git a/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/swift-collections-Package.xcscheme b/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/swift-collections-Package.xcscheme index 622aab38..6e50ef75 100644 --- a/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/swift-collections-Package.xcscheme +++ b/Utils/swift-collections.xcworkspace/xcshareddata/xcschemes/swift-collections-Package.xcscheme @@ -84,9 +84,9 @@ buildForAnalyzing = "YES"> @@ -182,9 +182,9 @@ buildForAnalyzing = "YES"> @@ -241,9 +241,9 @@ skipped = "NO">