mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
Merge pull request #237 from lorentey/ShareableHashedCollections
Apply changes from in-progress review thread
This commit is contained in:
125 files changed
+2498
-2096
No files matched your search
@@ -1,754 +0,0 @@
|
||||
{
|
||||
"kind": "group",
|
||||
"title": "PersistentSet Benchmarks",
|
||||
"directory": "Results",
|
||||
"contents": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "operations",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> init from range",
|
||||
"PersistentSet<Int> init from unsafe buffer",
|
||||
"PersistentSet<Int> sequential iteration",
|
||||
"PersistentSet<Int> successful contains",
|
||||
"PersistentSet<Int> unsuccessful contains",
|
||||
"PersistentSet<Int> insert",
|
||||
"PersistentSet<Int> remove"
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "initializers",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> init from range",
|
||||
"PersistentSet<Int> init from unsafe buffer",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union with Self",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> union with Self (0% overlap)",
|
||||
"PersistentSet<Int> union with Self (25% overlap)",
|
||||
"PersistentSet<Int> union with Self (50% overlap)",
|
||||
"PersistentSet<Int> union with Self (75% overlap)",
|
||||
"PersistentSet<Int> union with Self (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union with Array",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> union with Array (0% overlap)",
|
||||
"PersistentSet<Int> union with Array (25% overlap)",
|
||||
"PersistentSet<Int> union with Array (50% overlap)",
|
||||
"PersistentSet<Int> union with Array (75% overlap)",
|
||||
"PersistentSet<Int> union with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion with Self",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> formUnion with Self (0% overlap)",
|
||||
"PersistentSet<Int> formUnion with Self (25% overlap)",
|
||||
"PersistentSet<Int> formUnion with Self (50% overlap)",
|
||||
"PersistentSet<Int> formUnion with Self (75% overlap)",
|
||||
"PersistentSet<Int> formUnion with Self (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion with Array",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> formUnion with Array (0% overlap)",
|
||||
"PersistentSet<Int> formUnion with Array (25% overlap)",
|
||||
"PersistentSet<Int> formUnion with Array (50% overlap)",
|
||||
"PersistentSet<Int> formUnion with Array (75% overlap)",
|
||||
"PersistentSet<Int> formUnion with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection with Self",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> intersection with Self (0% overlap)",
|
||||
"PersistentSet<Int> intersection with Self (25% overlap)",
|
||||
"PersistentSet<Int> intersection with Self (50% overlap)",
|
||||
"PersistentSet<Int> intersection with Self (75% overlap)",
|
||||
"PersistentSet<Int> intersection with Self (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection with Array",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> intersection with Array (0% overlap)",
|
||||
"PersistentSet<Int> intersection with Array (25% overlap)",
|
||||
"PersistentSet<Int> intersection with Array (50% overlap)",
|
||||
"PersistentSet<Int> intersection with Array (75% overlap)",
|
||||
"PersistentSet<Int> intersection with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection with Self",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> formIntersection with Self (0% overlap)",
|
||||
"PersistentSet<Int> formIntersection with Self (25% overlap)",
|
||||
"PersistentSet<Int> formIntersection with Self (50% overlap)",
|
||||
"PersistentSet<Int> formIntersection with Self (75% overlap)",
|
||||
"PersistentSet<Int> formIntersection with Self (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection with Array",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> formIntersection with Array (0% overlap)",
|
||||
"PersistentSet<Int> formIntersection with Array (25% overlap)",
|
||||
"PersistentSet<Int> formIntersection with Array (50% overlap)",
|
||||
"PersistentSet<Int> formIntersection with Array (75% overlap)",
|
||||
"PersistentSet<Int> formIntersection with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference with Self",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> symmetricDifference with Self (0% overlap)",
|
||||
"PersistentSet<Int> symmetricDifference with Self (25% overlap)",
|
||||
"PersistentSet<Int> symmetricDifference with Self (50% overlap)",
|
||||
"PersistentSet<Int> symmetricDifference with Self (75% overlap)",
|
||||
"PersistentSet<Int> symmetricDifference with Self (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference with Array",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> symmetricDifference with Array (0% overlap)",
|
||||
"PersistentSet<Int> symmetricDifference with Array (25% overlap)",
|
||||
"PersistentSet<Int> symmetricDifference with Array (50% overlap)",
|
||||
"PersistentSet<Int> symmetricDifference with Array (75% overlap)",
|
||||
"PersistentSet<Int> symmetricDifference with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference with Self",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> formSymmetricDifference with Self (0% overlap)",
|
||||
"PersistentSet<Int> formSymmetricDifference with Self (25% overlap)",
|
||||
"PersistentSet<Int> formSymmetricDifference with Self (50% overlap)",
|
||||
"PersistentSet<Int> formSymmetricDifference with Self (75% overlap)",
|
||||
"PersistentSet<Int> formSymmetricDifference with Self (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference with Array",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> formSymmetricDifference with Array (0% overlap)",
|
||||
"PersistentSet<Int> formSymmetricDifference with Array (25% overlap)",
|
||||
"PersistentSet<Int> formSymmetricDifference with Array (50% overlap)",
|
||||
"PersistentSet<Int> formSymmetricDifference with Array (75% overlap)",
|
||||
"PersistentSet<Int> formSymmetricDifference with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting Self",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> subtracting Self (0% overlap)",
|
||||
"PersistentSet<Int> subtracting Self (25% overlap)",
|
||||
"PersistentSet<Int> subtracting Self (50% overlap)",
|
||||
"PersistentSet<Int> subtracting Self (75% overlap)",
|
||||
"PersistentSet<Int> subtracting Self (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting Array",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> subtracting Array (0% overlap)",
|
||||
"PersistentSet<Int> subtracting Array (25% overlap)",
|
||||
"PersistentSet<Int> subtracting Array (50% overlap)",
|
||||
"PersistentSet<Int> subtracting Array (75% overlap)",
|
||||
"PersistentSet<Int> subtracting Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract Self",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> subtract Self (0% overlap)",
|
||||
"PersistentSet<Int> subtract Self (25% overlap)",
|
||||
"PersistentSet<Int> subtract Self (50% overlap)",
|
||||
"PersistentSet<Int> subtract Self (75% overlap)",
|
||||
"PersistentSet<Int> subtract Self (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract with Array",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> subtract Array (0% overlap)",
|
||||
"PersistentSet<Int> subtract Array (25% overlap)",
|
||||
"PersistentSet<Int> subtract Array (50% overlap)",
|
||||
"PersistentSet<Int> subtract Array (75% overlap)",
|
||||
"PersistentSet<Int> subtract Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "group",
|
||||
"title": "Reference comparisons",
|
||||
"directory": "versus",
|
||||
"contents": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "init from buffer of integers",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> init from unsafe buffer",
|
||||
"Set<Int> init from unsafe buffer",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "init from range of integers",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> init from range",
|
||||
"Set<Int> init from range",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "sequential iteration",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> sequential iteration",
|
||||
"Set<Int> sequential iteration",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "sequential iteration using indices",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> sequential iteration, indices",
|
||||
"Set<Int> sequential iteration, indices",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "successful random lookups",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> successful contains",
|
||||
"Set<Int> successful contains",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "unsuccessful random lookups",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> unsuccessful contains",
|
||||
"Set<Int> unsuccessful contains",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "insert",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> insert",
|
||||
"Set<Int> insert",
|
||||
"Set<Int> insert, reserving capacity",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "insert-shared",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> insert, shared",
|
||||
"Set<Int> insert, shared",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "diffing",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> insert one + subtract, shared",
|
||||
"Set<Int> insert one + subtract, shared",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "remove",
|
||||
"tasks": [
|
||||
"PersistentSet<Int> remove",
|
||||
"PersistentSet<Int> remove, shared",
|
||||
"Set<Int> remove",
|
||||
"Set<Int> remove, shared",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (0% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> union with Self (0% overlap)",
|
||||
"OrderedSet<Int> union with Array (0% overlap)",
|
||||
"Set<Int> union with Self (0% overlap)",
|
||||
"Set<Int> union with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (25% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> union with Self (25% overlap)",
|
||||
"OrderedSet<Int> union with Array (25% overlap)",
|
||||
"Set<Int> union with Self (25% overlap)",
|
||||
"Set<Int> union with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (50% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> union with Self (50% overlap)",
|
||||
"OrderedSet<Int> union with Array (50% overlap)",
|
||||
"Set<Int> union with Self (50% overlap)",
|
||||
"Set<Int> union with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (75% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> union with Self (75% overlap)",
|
||||
"OrderedSet<Int> union with Array (75% overlap)",
|
||||
"Set<Int> union with Self (75% overlap)",
|
||||
"Set<Int> union with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (100% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> union with Self (100% overlap)",
|
||||
"OrderedSet<Int> union with Array (100% overlap)",
|
||||
"Set<Int> union with Self (100% overlap)",
|
||||
"Set<Int> union with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (0% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formUnion with Self (0% overlap)",
|
||||
"OrderedSet<Int> formUnion with Array (0% overlap)",
|
||||
"Set<Int> formUnion with Self (0% overlap)",
|
||||
"Set<Int> formUnion with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (25% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formUnion with Self (25% overlap)",
|
||||
"OrderedSet<Int> formUnion with Array (25% overlap)",
|
||||
"Set<Int> formUnion with Self (25% overlap)",
|
||||
"Set<Int> formUnion with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (50% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formUnion with Self (50% overlap)",
|
||||
"OrderedSet<Int> formUnion with Array (50% overlap)",
|
||||
"Set<Int> formUnion with Self (50% overlap)",
|
||||
"Set<Int> formUnion with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (75% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formUnion with Self (75% overlap)",
|
||||
"OrderedSet<Int> formUnion with Array (75% overlap)",
|
||||
"Set<Int> formUnion with Self (75% overlap)",
|
||||
"Set<Int> formUnion with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (100% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formUnion with Self (100% overlap)",
|
||||
"OrderedSet<Int> formUnion with Array (100% overlap)",
|
||||
"Set<Int> formUnion with Self (100% overlap)",
|
||||
"Set<Int> formUnion with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (0% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> intersection with Self (0% overlap)",
|
||||
"OrderedSet<Int> intersection with Array (0% overlap)",
|
||||
"Set<Int> intersection with Self (0% overlap)",
|
||||
"Set<Int> intersection with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (25% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> intersection with Self (25% overlap)",
|
||||
"OrderedSet<Int> intersection with Array (25% overlap)",
|
||||
"Set<Int> intersection with Self (25% overlap)",
|
||||
"Set<Int> intersection with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (50% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> intersection with Self (50% overlap)",
|
||||
"OrderedSet<Int> intersection with Array (50% overlap)",
|
||||
"Set<Int> intersection with Self (50% overlap)",
|
||||
"Set<Int> intersection with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (75% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> intersection with Self (75% overlap)",
|
||||
"OrderedSet<Int> intersection with Array (75% overlap)",
|
||||
"Set<Int> intersection with Self (75% overlap)",
|
||||
"Set<Int> intersection with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (100% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> intersection with Self (100% overlap)",
|
||||
"OrderedSet<Int> intersection with Array (100% overlap)",
|
||||
"Set<Int> intersection with Self (100% overlap)",
|
||||
"Set<Int> intersection with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (0% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formIntersection with Self (0% overlap)",
|
||||
"OrderedSet<Int> formIntersection with Array (0% overlap)",
|
||||
"Set<Int> formIntersection with Self (0% overlap)",
|
||||
"Set<Int> formIntersection with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (25% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formIntersection with Self (25% overlap)",
|
||||
"OrderedSet<Int> formIntersection with Array (25% overlap)",
|
||||
"Set<Int> formIntersection with Self (25% overlap)",
|
||||
"Set<Int> formIntersection with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (50% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formIntersection with Self (50% overlap)",
|
||||
"OrderedSet<Int> formIntersection with Array (50% overlap)",
|
||||
"Set<Int> formIntersection with Self (50% overlap)",
|
||||
"Set<Int> formIntersection with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (75% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formIntersection with Self (75% overlap)",
|
||||
"OrderedSet<Int> formIntersection with Array (75% overlap)",
|
||||
"Set<Int> formIntersection with Self (75% overlap)",
|
||||
"Set<Int> formIntersection with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (100% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formIntersection with Self (100% overlap)",
|
||||
"OrderedSet<Int> formIntersection with Array (100% overlap)",
|
||||
"Set<Int> formIntersection with Self (100% overlap)",
|
||||
"Set<Int> formIntersection with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (0% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> symmetricDifference with Self (0% overlap)",
|
||||
"OrderedSet<Int> symmetricDifference with Array (0% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (0% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (25% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> symmetricDifference with Self (25% overlap)",
|
||||
"OrderedSet<Int> symmetricDifference with Array (25% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (25% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (50% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> symmetricDifference with Self (50% overlap)",
|
||||
"OrderedSet<Int> symmetricDifference with Array (50% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (50% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (75% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> symmetricDifference with Self (75% overlap)",
|
||||
"OrderedSet<Int> symmetricDifference with Array (75% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (75% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (100% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> symmetricDifference with Self (100% overlap)",
|
||||
"OrderedSet<Int> symmetricDifference with Array (100% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (100% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (0% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formSymmetricDifference with Self (0% overlap)",
|
||||
"OrderedSet<Int> formSymmetricDifference with Array (0% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (0% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (25% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formSymmetricDifference with Self (25% overlap)",
|
||||
"OrderedSet<Int> formSymmetricDifference with Array (25% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (25% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (50% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formSymmetricDifference with Self (50% overlap)",
|
||||
"OrderedSet<Int> formSymmetricDifference with Array (50% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (50% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (75% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formSymmetricDifference with Self (75% overlap)",
|
||||
"OrderedSet<Int> formSymmetricDifference with Array (75% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (75% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (100% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> formSymmetricDifference with Self (100% overlap)",
|
||||
"OrderedSet<Int> formSymmetricDifference with Array (100% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (100% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (0% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtracting Self (0% overlap)",
|
||||
"OrderedSet<Int> subtracting Array (0% overlap)",
|
||||
"Set<Int> subtracting Self (0% overlap)",
|
||||
"Set<Int> subtracting Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (25% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtracting Self (25% overlap)",
|
||||
"OrderedSet<Int> subtracting Array (25% overlap)",
|
||||
"Set<Int> subtracting Self (25% overlap)",
|
||||
"Set<Int> subtracting Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (50% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtracting Self (50% overlap)",
|
||||
"OrderedSet<Int> subtracting Array (50% overlap)",
|
||||
"Set<Int> subtracting Self (50% overlap)",
|
||||
"Set<Int> subtracting Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (75% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtracting Self (75% overlap)",
|
||||
"OrderedSet<Int> subtracting Array (75% overlap)",
|
||||
"Set<Int> subtracting Self (75% overlap)",
|
||||
"Set<Int> subtracting Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (100% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtracting Self (100% overlap)",
|
||||
"OrderedSet<Int> subtracting Array (100% overlap)",
|
||||
"Set<Int> subtracting Self (100% overlap)",
|
||||
"Set<Int> subtracting Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (0% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtract Self (0% overlap)",
|
||||
"OrderedSet<Int> subtract Array (0% overlap)",
|
||||
"Set<Int> subtract Self (0% overlap)",
|
||||
"Set<Int> subtract Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (25% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtract Self (25% overlap)",
|
||||
"OrderedSet<Int> subtract Array (25% overlap)",
|
||||
"Set<Int> subtract Self (25% overlap)",
|
||||
"Set<Int> subtract Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (50% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtract Self (50% overlap)",
|
||||
"OrderedSet<Int> subtract Array (50% overlap)",
|
||||
"Set<Int> subtract Self (50% overlap)",
|
||||
"Set<Int> subtract Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (75% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtract Self (75% overlap)",
|
||||
"OrderedSet<Int> subtract Array (75% overlap)",
|
||||
"Set<Int> subtract Self (75% overlap)",
|
||||
"Set<Int> subtract Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (100% overlap)",
|
||||
"tasks": [
|
||||
"OrderedSet<Int> subtract Self (100% overlap)",
|
||||
"OrderedSet<Int> subtract Array (100% overlap)",
|
||||
"Set<Int> subtract Self (100% overlap)",
|
||||
"Set<Int> subtract Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
+46
-46
@@ -1,42 +1,42 @@
|
||||
{
|
||||
"kind": "group",
|
||||
"title": "PersistentDictionary Benchmarks",
|
||||
"title": "ShareableDictionary Benchmarks",
|
||||
"directory": "Results",
|
||||
"contents": [
|
||||
{
|
||||
"kind": "group",
|
||||
"title": "PersistentDictionary Operations",
|
||||
"title": "ShareableDictionary Operations",
|
||||
"contents": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "all",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> init(uniqueKeysWithValues:)",
|
||||
"PersistentDictionary<Int, Int> sequential iteration",
|
||||
"PersistentDictionary<Int, Int> sequential iteration, indices",
|
||||
"PersistentDictionary<Int, Int>.Keys sequential iteration",
|
||||
"PersistentDictionary<Int, Int>.Values sequential iteration",
|
||||
"PersistentDictionary<Int, Int> indexing subscript",
|
||||
"PersistentDictionary<Int, Int> subscript, successful lookups",
|
||||
"PersistentDictionary<Int, Int> subscript, unsuccessful lookups",
|
||||
"PersistentDictionary<Int, Int> subscript, noop setter",
|
||||
"PersistentDictionary<Int, Int> subscript, set existing",
|
||||
"PersistentDictionary<Int, Int> subscript, _modify",
|
||||
"PersistentDictionary<Int, Int> subscript, insert, unique",
|
||||
"PersistentDictionary<Int, Int> subscript, insert, shared",
|
||||
"PersistentDictionary<Int, Int> subscript, remove existing, unique",
|
||||
"PersistentDictionary<Int, Int> subscript, remove existing, shared",
|
||||
"PersistentDictionary<Int, Int> subscript, remove missing",
|
||||
"PersistentDictionary<Int, Int> defaulted subscript, successful lookups",
|
||||
"PersistentDictionary<Int, Int> defaulted subscript, unsuccessful lookups",
|
||||
"PersistentDictionary<Int, Int> defaulted subscript, _modify existing",
|
||||
"PersistentDictionary<Int, Int> defaulted subscript, _modify missing",
|
||||
"PersistentDictionary<Int, Int> successful index(forKey:)",
|
||||
"PersistentDictionary<Int, Int> unsuccessful index(forKey:)",
|
||||
"PersistentDictionary<Int, Int> updateValue(_:forKey:), existing",
|
||||
"PersistentDictionary<Int, Int> updateValue(_:forKey:), insert",
|
||||
"PersistentDictionary<Int, Int> random removals (existing keys)",
|
||||
"PersistentDictionary<Int, Int> random removals (missing keys)",
|
||||
"ShareableDictionary<Int, Int> init(uniqueKeysWithValues:)",
|
||||
"ShareableDictionary<Int, Int> sequential iteration",
|
||||
"ShareableDictionary<Int, Int> sequential iteration, indices",
|
||||
"ShareableDictionary<Int, Int>.Keys sequential iteration",
|
||||
"ShareableDictionary<Int, Int>.Values sequential iteration",
|
||||
"ShareableDictionary<Int, Int> indexing subscript",
|
||||
"ShareableDictionary<Int, Int> subscript, successful lookups",
|
||||
"ShareableDictionary<Int, Int> subscript, unsuccessful lookups",
|
||||
"ShareableDictionary<Int, Int> subscript, noop setter",
|
||||
"ShareableDictionary<Int, Int> subscript, set existing",
|
||||
"ShareableDictionary<Int, Int> subscript, _modify",
|
||||
"ShareableDictionary<Int, Int> subscript, insert, unique",
|
||||
"ShareableDictionary<Int, Int> subscript, insert, shared",
|
||||
"ShareableDictionary<Int, Int> subscript, remove existing, unique",
|
||||
"ShareableDictionary<Int, Int> subscript, remove existing, shared",
|
||||
"ShareableDictionary<Int, Int> subscript, remove missing",
|
||||
"ShareableDictionary<Int, Int> defaulted subscript, successful lookups",
|
||||
"ShareableDictionary<Int, Int> defaulted subscript, unsuccessful lookups",
|
||||
"ShareableDictionary<Int, Int> defaulted subscript, _modify existing",
|
||||
"ShareableDictionary<Int, Int> defaulted subscript, _modify missing",
|
||||
"ShareableDictionary<Int, Int> successful index(forKey:)",
|
||||
"ShareableDictionary<Int, Int> unsuccessful index(forKey:)",
|
||||
"ShareableDictionary<Int, Int> updateValue(_:forKey:), existing",
|
||||
"ShareableDictionary<Int, Int> updateValue(_:forKey:), insert",
|
||||
"ShareableDictionary<Int, Int> random removals (existing keys)",
|
||||
"ShareableDictionary<Int, Int> random removals (missing keys)",
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -50,7 +50,7 @@
|
||||
"kind": "chart",
|
||||
"title": "init(uniqueKeysWithValues:)",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> init(uniqueKeysWithValues:)",
|
||||
"ShareableDictionary<Int, Int> init(uniqueKeysWithValues:)",
|
||||
"Dictionary<Int, Int> init(uniqueKeysWithValues:)",
|
||||
"OrderedDictionary<Int, Int> init(uniqueKeysWithValues:)",
|
||||
]
|
||||
@@ -59,7 +59,7 @@
|
||||
"kind": "chart",
|
||||
"title": "sequential iteration",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> sequential iteration",
|
||||
"ShareableDictionary<Int, Int> sequential iteration",
|
||||
"Dictionary<Int, Int> sequential iteration",
|
||||
"OrderedDictionary<Int, Int> sequential iteration",
|
||||
]
|
||||
@@ -68,7 +68,7 @@
|
||||
"kind": "chart",
|
||||
"title": "sequential iteration [Keys]",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int>.Keys sequential iteration",
|
||||
"ShareableDictionary<Int, Int>.Keys sequential iteration",
|
||||
"Dictionary<Int, Int>.Keys sequential iteration",
|
||||
"OrderedDictionary<Int, Int>.Keys sequential iteration",
|
||||
]
|
||||
@@ -77,7 +77,7 @@
|
||||
"kind": "chart",
|
||||
"title": "sequential iteration [Values]",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int>.Values sequential iteration",
|
||||
"ShareableDictionary<Int, Int>.Values sequential iteration",
|
||||
"Dictionary<Int, Int>.Values sequential iteration",
|
||||
"OrderedDictionary<Int, Int>.Values sequential iteration",
|
||||
]
|
||||
@@ -86,7 +86,7 @@
|
||||
"kind": "chart",
|
||||
"title": "sequential iteration using indices",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> sequential iteration, indices",
|
||||
"ShareableDictionary<Int, Int> sequential iteration, indices",
|
||||
"Dictionary<Int, Int> sequential iteration, indices",
|
||||
"OrderedDictionary<Int, Int> sequential iteration, indices",
|
||||
]
|
||||
@@ -95,7 +95,7 @@
|
||||
"kind": "chart",
|
||||
"title": "indexing subscript",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> indexing subscript",
|
||||
"ShareableDictionary<Int, Int> indexing subscript",
|
||||
"Dictionary<Int, Int> indexing subscript",
|
||||
"OrderedDictionary<Int, Int> indexing subscript",
|
||||
]
|
||||
@@ -104,7 +104,7 @@
|
||||
"kind": "chart",
|
||||
"title": "subscript, successful lookups",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> subscript, successful lookups",
|
||||
"ShareableDictionary<Int, Int> subscript, successful lookups",
|
||||
"Dictionary<Int, Int> subscript, successful lookups",
|
||||
"OrderedDictionary<Int, Int> subscript, successful lookups",
|
||||
]
|
||||
@@ -113,7 +113,7 @@
|
||||
"kind": "chart",
|
||||
"title": "subscript, unsuccessful lookups",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> subscript, unsuccessful lookups",
|
||||
"ShareableDictionary<Int, Int> subscript, unsuccessful lookups",
|
||||
"Dictionary<Int, Int> subscript, unsuccessful lookups",
|
||||
"OrderedDictionary<Int, Int> subscript, unsuccessful lookups",
|
||||
]
|
||||
@@ -122,7 +122,7 @@
|
||||
"kind": "chart",
|
||||
"title": "subscript, insert into unique collection",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> subscript, insert, unique",
|
||||
"ShareableDictionary<Int, Int> subscript, insert, unique",
|
||||
"Dictionary<Int, Int> subscript, insert, unique",
|
||||
"Dictionary<Int, Int> subscript, insert, reserving capacity",
|
||||
"OrderedDictionary<Int, Int> subscript, append, unique",
|
||||
@@ -133,7 +133,7 @@
|
||||
"kind": "chart",
|
||||
"title": "subscript, insert into shared collection",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> subscript, insert, shared",
|
||||
"ShareableDictionary<Int, Int> subscript, insert, shared",
|
||||
"Dictionary<Int, Int> subscript, insert, shared",
|
||||
"OrderedDictionary<Int, Int> subscript, append, shared",
|
||||
]
|
||||
@@ -142,7 +142,7 @@
|
||||
"kind": "chart",
|
||||
"title": "subscript, remove existing from unique collection",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> subscript, remove existing, unique",
|
||||
"ShareableDictionary<Int, Int> subscript, remove existing, unique",
|
||||
"Dictionary<Int, Int> subscript, remove existing, unique",
|
||||
"OrderedDictionary<Int, Int> subscript, remove existing, unique",
|
||||
]
|
||||
@@ -151,7 +151,7 @@
|
||||
"kind": "chart",
|
||||
"title": "subscript, remove existing from shared collection",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> subscript, remove existing, shared",
|
||||
"ShareableDictionary<Int, Int> subscript, remove existing, shared",
|
||||
"Dictionary<Int, Int> subscript, remove existing, shared",
|
||||
"OrderedDictionary<Int, Int> subscript, remove existing, shared",
|
||||
]
|
||||
@@ -160,8 +160,8 @@
|
||||
"kind": "chart",
|
||||
"title": "subscript, _modify existing",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> subscript, _modify",
|
||||
"PersistentDictionary<Int, Int> defaulted subscript, _modify existing",
|
||||
"ShareableDictionary<Int, Int> subscript, _modify",
|
||||
"ShareableDictionary<Int, Int> defaulted subscript, _modify existing",
|
||||
"Dictionary<Int, Int> subscript, _modify",
|
||||
"Dictionary<Int, Int> defaulted subscript, _modify existing",
|
||||
"OrderedDictionary<Int, Int> subscript, _modify",
|
||||
@@ -173,7 +173,7 @@
|
||||
"kind": "chart",
|
||||
"title": "index(forKey:), successful index(forKey:)",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> successful index(forKey:)",
|
||||
"ShareableDictionary<Int, Int> successful index(forKey:)",
|
||||
"Dictionary<Int, Int> successful index(forKey:)",
|
||||
"OrderedDictionary<Int, Int> successful index(forKey:)",
|
||||
]
|
||||
@@ -182,7 +182,7 @@
|
||||
"kind": "chart",
|
||||
"title": "index(forKey:), unsuccessful index(forKey:)",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> unsuccessful index(forKey:)",
|
||||
"ShareableDictionary<Int, Int> unsuccessful index(forKey:)",
|
||||
"Dictionary<Int, Int> unsuccessful index(forKey:)",
|
||||
"OrderedDictionary<Int, Int> unsuccessful index(forKey:)",
|
||||
]
|
||||
@@ -191,7 +191,7 @@
|
||||
"kind": "chart",
|
||||
"title": "updateValue(_:forKey:), existing",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> updateValue(_:forKey:), existing",
|
||||
"ShareableDictionary<Int, Int> updateValue(_:forKey:), existing",
|
||||
"Dictionary<Int, Int> updateValue(_:forKey:), existing",
|
||||
"OrderedDictionary<Int, Int> updateValue(_:forKey:), existing"
|
||||
]
|
||||
@@ -200,7 +200,7 @@
|
||||
"kind": "chart",
|
||||
"title": "updateValue(_:forKey:), insert",
|
||||
"tasks": [
|
||||
"PersistentDictionary<Int, Int> updateValue(_:forKey:), insert",
|
||||
"ShareableDictionary<Int, Int> updateValue(_:forKey:), insert",
|
||||
"Dictionary<Int, Int> updateValue(_:forKey:), insert",
|
||||
"OrderedDictionary<Int, Int> updateValue(_:forKey:), append"
|
||||
]
|
||||
@@ -0,0 +1,882 @@
|
||||
{
|
||||
"kind": "group",
|
||||
"title": "ShareableSet Benchmarks",
|
||||
"directory": "Results",
|
||||
"contents": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "operations",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> init from range",
|
||||
"ShareableSet<Int> init from unsafe buffer",
|
||||
"ShareableSet<Int> sequential iteration",
|
||||
"ShareableSet<Int> successful contains",
|
||||
"ShareableSet<Int> unsuccessful contains",
|
||||
"ShareableSet<Int> insert",
|
||||
"ShareableSet<Int> remove"
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "initializers",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> init from range",
|
||||
"ShareableSet<Int> init from unsafe buffer",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union with Self, distinct",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> union with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> union with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> union with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> union with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> union with Self (100% overlap, distinct)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union with Self, shared",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> union with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> union with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> union with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> union with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> union with Self (100% overlap, shared)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union with Array",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> union with Array (0% overlap)",
|
||||
"ShareableSet<Int> union with Array (25% overlap)",
|
||||
"ShareableSet<Int> union with Array (50% overlap)",
|
||||
"ShareableSet<Int> union with Array (75% overlap)",
|
||||
"ShareableSet<Int> union with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion with Self, distinct",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formUnion with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> formUnion with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> formUnion with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> formUnion with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> formUnion with Self (100% overlap, distinct)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion with Self, shared",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formUnion with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> formUnion with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> formUnion with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> formUnion with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> formUnion with Self (100% overlap, shared)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion with Array",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formUnion with Array (0% overlap)",
|
||||
"ShareableSet<Int> formUnion with Array (25% overlap)",
|
||||
"ShareableSet<Int> formUnion with Array (50% overlap)",
|
||||
"ShareableSet<Int> formUnion with Array (75% overlap)",
|
||||
"ShareableSet<Int> formUnion with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection with Self, distinct",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> intersection with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> intersection with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> intersection with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> intersection with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> intersection with Self (100% overlap, distinct)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection with Self, shared",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> intersection with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> intersection with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> intersection with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> intersection with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> intersection with Self (100% overlap, shared)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection with Array",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> intersection with Array (0% overlap)",
|
||||
"ShareableSet<Int> intersection with Array (25% overlap)",
|
||||
"ShareableSet<Int> intersection with Array (50% overlap)",
|
||||
"ShareableSet<Int> intersection with Array (75% overlap)",
|
||||
"ShareableSet<Int> intersection with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection with Self, distinct",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formIntersection with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> formIntersection with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> formIntersection with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> formIntersection with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> formIntersection with Self (100% overlap, distinct)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection with Self, shared",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formIntersection with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> formIntersection with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> formIntersection with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> formIntersection with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> formIntersection with Self (100% overlap, shared)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection with Array",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formIntersection with Array (0% overlap)",
|
||||
"ShareableSet<Int> formIntersection with Array (25% overlap)",
|
||||
"ShareableSet<Int> formIntersection with Array (50% overlap)",
|
||||
"ShareableSet<Int> formIntersection with Array (75% overlap)",
|
||||
"ShareableSet<Int> formIntersection with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference with Self, distinct",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> symmetricDifference with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (100% overlap, distinct)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference with Self, shared",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> symmetricDifference with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (100% overlap, shared)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference with Array",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> symmetricDifference with Array (0% overlap)",
|
||||
"ShareableSet<Int> symmetricDifference with Array (25% overlap)",
|
||||
"ShareableSet<Int> symmetricDifference with Array (50% overlap)",
|
||||
"ShareableSet<Int> symmetricDifference with Array (75% overlap)",
|
||||
"ShareableSet<Int> symmetricDifference with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference with Self, distinct",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (100% overlap, distinct)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference with Self, shared",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (100% overlap, shared)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference with Array",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (0% overlap)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (25% overlap)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (50% overlap)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (75% overlap)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting Self, distinct",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtracting Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> subtracting Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> subtracting Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> subtracting Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> subtracting Self (100% overlap, distinct)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting Self, shared",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtracting Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> subtracting Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> subtracting Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> subtracting Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> subtracting Self (100% overlap, shared)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting Array",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtracting Array (0% overlap)",
|
||||
"ShareableSet<Int> subtracting Array (25% overlap)",
|
||||
"ShareableSet<Int> subtracting Array (50% overlap)",
|
||||
"ShareableSet<Int> subtracting Array (75% overlap)",
|
||||
"ShareableSet<Int> subtracting Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract Self, distinct",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtract Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> subtract Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> subtract Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> subtract Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> subtract Self (100% overlap, distinct)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract Self, shared",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtract Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> subtract Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> subtract Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> subtract Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> subtract Self (100% overlap, shared)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract with Array",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtract Array (0% overlap)",
|
||||
"ShareableSet<Int> subtract Array (25% overlap)",
|
||||
"ShareableSet<Int> subtract Array (50% overlap)",
|
||||
"ShareableSet<Int> subtract Array (75% overlap)",
|
||||
"ShareableSet<Int> subtract Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "group",
|
||||
"title": "Reference comparisons",
|
||||
"directory": "versus",
|
||||
"contents": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "init from buffer of integers",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> init from unsafe buffer",
|
||||
"Set<Int> init from unsafe buffer",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "init from range of integers",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> init from range",
|
||||
"Set<Int> init from range",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "sequential iteration",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> sequential iteration",
|
||||
"Set<Int> sequential iteration",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "sequential iteration using indices",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> sequential iteration, indices",
|
||||
"Set<Int> sequential iteration, indices",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "successful random lookups",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> successful contains",
|
||||
"Set<Int> successful contains",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "unsuccessful random lookups",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> unsuccessful contains",
|
||||
"Set<Int> unsuccessful contains",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "insert",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> insert",
|
||||
"Set<Int> insert",
|
||||
"Set<Int> insert, reserving capacity",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "insert-shared",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> insert, shared",
|
||||
"Set<Int> insert, shared",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "model building with constant diffing",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> model diffing",
|
||||
"Set<Int> model diffing",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "remove",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> remove",
|
||||
"ShareableSet<Int> remove, shared",
|
||||
"Set<Int> remove",
|
||||
"Set<Int> remove, shared",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (0% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> union with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> union with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> union with Array (0% overlap)",
|
||||
"Set<Int> union with Self (0% overlap)",
|
||||
"Set<Int> union with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (25% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> union with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> union with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> union with Array (25% overlap)",
|
||||
"Set<Int> union with Self (25% overlap)",
|
||||
"Set<Int> union with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (50% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> union with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> union with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> union with Array (50% overlap)",
|
||||
"Set<Int> union with Self (50% overlap)",
|
||||
"Set<Int> union with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (75% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> union with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> union with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> union with Array (75% overlap)",
|
||||
"Set<Int> union with Self (75% overlap)",
|
||||
"Set<Int> union with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "union (100% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> union with Self (100% overlap, distinct)",
|
||||
"ShareableSet<Int> union with Self (100% overlap, shared)",
|
||||
"ShareableSet<Int> union with Array (100% overlap)",
|
||||
"Set<Int> union with Self (100% overlap)",
|
||||
"Set<Int> union with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (0% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formUnion with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> formUnion with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> formUnion with Array (0% overlap)",
|
||||
"Set<Int> formUnion with Self (0% overlap)",
|
||||
"Set<Int> formUnion with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (25% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formUnion with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> formUnion with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> formUnion with Array (25% overlap)",
|
||||
"Set<Int> formUnion with Self (25% overlap)",
|
||||
"Set<Int> formUnion with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (50% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formUnion with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> formUnion with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> formUnion with Array (50% overlap)",
|
||||
"Set<Int> formUnion with Self (50% overlap)",
|
||||
"Set<Int> formUnion with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (75% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formUnion with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> formUnion with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> formUnion with Array (75% overlap)",
|
||||
"Set<Int> formUnion with Self (75% overlap)",
|
||||
"Set<Int> formUnion with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formUnion (100% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formUnion with Self (100% overlap, distinct)",
|
||||
"ShareableSet<Int> formUnion with Self (100% overlap, shared)",
|
||||
"ShareableSet<Int> formUnion with Array (100% overlap)",
|
||||
"Set<Int> formUnion with Self (100% overlap)",
|
||||
"Set<Int> formUnion with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (0% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> intersection with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> intersection with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> intersection with Array (0% overlap)",
|
||||
"Set<Int> intersection with Self (0% overlap)",
|
||||
"Set<Int> intersection with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (25% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> intersection with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> intersection with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> intersection with Array (25% overlap)",
|
||||
"Set<Int> intersection with Self (25% overlap)",
|
||||
"Set<Int> intersection with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (50% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> intersection with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> intersection with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> intersection with Array (50% overlap)",
|
||||
"Set<Int> intersection with Self (50% overlap)",
|
||||
"Set<Int> intersection with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (75% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> intersection with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> intersection with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> intersection with Array (75% overlap)",
|
||||
"Set<Int> intersection with Self (75% overlap)",
|
||||
"Set<Int> intersection with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "intersection (100% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> intersection with Self (100% overlap, distinct)",
|
||||
"ShareableSet<Int> intersection with Self (100% overlap, shared)",
|
||||
"ShareableSet<Int> intersection with Array (100% overlap)",
|
||||
"Set<Int> intersection with Self (100% overlap)",
|
||||
"Set<Int> intersection with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (0% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formIntersection with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> formIntersection with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> formIntersection with Array (0% overlap)",
|
||||
"Set<Int> formIntersection with Self (0% overlap)",
|
||||
"Set<Int> formIntersection with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (25% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formIntersection with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> formIntersection with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> formIntersection with Array (25% overlap)",
|
||||
"Set<Int> formIntersection with Self (25% overlap)",
|
||||
"Set<Int> formIntersection with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (50% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formIntersection with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> formIntersection with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> formIntersection with Array (50% overlap)",
|
||||
"Set<Int> formIntersection with Self (50% overlap)",
|
||||
"Set<Int> formIntersection with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (75% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formIntersection with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> formIntersection with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> formIntersection with Array (75% overlap)",
|
||||
"Set<Int> formIntersection with Self (75% overlap)",
|
||||
"Set<Int> formIntersection with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formIntersection (100% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formIntersection with Self (100% overlap, distinct)",
|
||||
"ShareableSet<Int> formIntersection with Self (100% overlap, shared)",
|
||||
"ShareableSet<Int> formIntersection with Array (100% overlap)",
|
||||
"Set<Int> formIntersection with Self (100% overlap)",
|
||||
"Set<Int> formIntersection with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (0% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> symmetricDifference with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> symmetricDifference with Array (0% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (0% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (25% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> symmetricDifference with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> symmetricDifference with Array (25% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (25% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (50% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> symmetricDifference with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> symmetricDifference with Array (50% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (50% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (75% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> symmetricDifference with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> symmetricDifference with Array (75% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (75% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "symmetricDifference (100% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> symmetricDifference with Self (100% overlap, distinct)",
|
||||
"ShareableSet<Int> symmetricDifference with Self (100% overlap, shared)",
|
||||
"ShareableSet<Int> symmetricDifference with Array (100% overlap)",
|
||||
"Set<Int> symmetricDifference with Self (100% overlap)",
|
||||
"Set<Int> symmetricDifference with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (0% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (0% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (0% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (25% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (25% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (25% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (50% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (50% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (50% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (75% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (75% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (75% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "formSymmetricDifference (100% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (100% overlap, distinct)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Self (100% overlap, shared)",
|
||||
"ShareableSet<Int> formSymmetricDifference with Array (100% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Self (100% overlap)",
|
||||
"Set<Int> formSymmetricDifference with Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (0% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtracting Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> subtracting Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> subtracting Array (0% overlap)",
|
||||
"Set<Int> subtracting Self (0% overlap)",
|
||||
"Set<Int> subtracting Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (25% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtracting Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> subtracting Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> subtracting Array (25% overlap)",
|
||||
"Set<Int> subtracting Self (25% overlap)",
|
||||
"Set<Int> subtracting Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (50% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtracting Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> subtracting Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> subtracting Array (50% overlap)",
|
||||
"Set<Int> subtracting Self (50% overlap)",
|
||||
"Set<Int> subtracting Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (75% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtracting Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> subtracting Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> subtracting Array (75% overlap)",
|
||||
"Set<Int> subtracting Self (75% overlap)",
|
||||
"Set<Int> subtracting Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtracting (100% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtracting Self (100% overlap, distinct)",
|
||||
"ShareableSet<Int> subtracting Self (100% overlap, shared)",
|
||||
"ShareableSet<Int> subtracting Array (100% overlap)",
|
||||
"Set<Int> subtracting Self (100% overlap)",
|
||||
"Set<Int> subtracting Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "variants",
|
||||
"charts": [
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (0% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtract Self (0% overlap, distinct)",
|
||||
"ShareableSet<Int> subtract Self (0% overlap, shared)",
|
||||
"ShareableSet<Int> subtract Array (0% overlap)",
|
||||
"Set<Int> subtract Self (0% overlap)",
|
||||
"Set<Int> subtract Array (0% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (25% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtract Self (25% overlap, distinct)",
|
||||
"ShareableSet<Int> subtract Self (25% overlap, shared)",
|
||||
"ShareableSet<Int> subtract Array (25% overlap)",
|
||||
"Set<Int> subtract Self (25% overlap)",
|
||||
"Set<Int> subtract Array (25% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (50% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtract Self (50% overlap, distinct)",
|
||||
"ShareableSet<Int> subtract Self (50% overlap, shared)",
|
||||
"ShareableSet<Int> subtract Array (50% overlap)",
|
||||
"Set<Int> subtract Self (50% overlap)",
|
||||
"Set<Int> subtract Array (50% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (75% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtract Self (75% overlap, distinct)",
|
||||
"ShareableSet<Int> subtract Self (75% overlap, shared)",
|
||||
"ShareableSet<Int> subtract Array (75% overlap)",
|
||||
"Set<Int> subtract Self (75% overlap)",
|
||||
"Set<Int> subtract Array (75% overlap)",
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "chart",
|
||||
"title": "subtract (100% overlap)",
|
||||
"tasks": [
|
||||
"ShareableSet<Int> subtract Self (100% overlap, distinct)",
|
||||
"ShareableSet<Int> subtract Self (100% overlap, shared)",
|
||||
"ShareableSet<Int> subtract Array (100% overlap)",
|
||||
"Set<Int> subtract Self (100% overlap)",
|
||||
"Set<Int> subtract Array (100% overlap)",
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
+64
-64
@@ -10,25 +10,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import CollectionsBenchmark
|
||||
import PersistentCollections
|
||||
import ShareableHashedCollections
|
||||
|
||||
extension Benchmark {
|
||||
public mutating func addPersistentDictionaryBenchmarks() {
|
||||
public mutating func addShareableDictionaryBenchmarks() {
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> init(uniqueKeysWithValues:)",
|
||||
title: "ShareableDictionary<Int, Int> init(uniqueKeysWithValues:)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let keysAndValues = input.map { ($0, 2 * $0) }
|
||||
return { timer in
|
||||
blackHole(PersistentDictionary(uniqueKeysWithValues: keysAndValues))
|
||||
blackHole(ShareableDictionary(uniqueKeysWithValues: keysAndValues))
|
||||
}
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> sequential iteration",
|
||||
title: "ShareableDictionary<Int, Int> sequential iteration",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
return { timer in
|
||||
for item in d {
|
||||
blackHole(item)
|
||||
@@ -37,10 +37,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int>.Keys sequential iteration",
|
||||
title: "ShareableDictionary<Int, Int>.Keys sequential iteration",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
return { timer in
|
||||
for item in d.keys {
|
||||
blackHole(item)
|
||||
@@ -49,10 +49,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int>.Values sequential iteration",
|
||||
title: "ShareableDictionary<Int, Int>.Values sequential iteration",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
return { timer in
|
||||
for item in d.values {
|
||||
blackHole(item)
|
||||
@@ -61,10 +61,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> sequential iteration, indices",
|
||||
title: "ShareableDictionary<Int, Int> sequential iteration, indices",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
return { timer in
|
||||
for i in d.indices {
|
||||
blackHole(d[i])
|
||||
@@ -73,10 +73,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> striding, 10 steps",
|
||||
title: "ShareableDictionary<Int, Int> striding, 10 steps",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let d = PersistentDictionary(
|
||||
let d = ShareableDictionary(
|
||||
uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let steps = stride(from: 0, through: 10 * d.count, by: d.count)
|
||||
.map { $0 / 10 }
|
||||
@@ -92,10 +92,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> indexing subscript",
|
||||
title: "ShareableDictionary<Int, Int> indexing subscript",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let indices = lookups.map { d.index(forKey: $0)! }
|
||||
return { timer in
|
||||
for i in indices {
|
||||
@@ -105,10 +105,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> subscript, successful lookups",
|
||||
title: "ShareableDictionary<Int, Int> subscript, successful lookups",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
return { timer in
|
||||
for i in lookups {
|
||||
precondition(d[i] == 2 * i)
|
||||
@@ -117,10 +117,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> subscript, unsuccessful lookups",
|
||||
title: "ShareableDictionary<Int, Int> subscript, unsuccessful lookups",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let c = input.count
|
||||
return { timer in
|
||||
for i in lookups {
|
||||
@@ -130,11 +130,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> subscript, noop setter",
|
||||
title: "ShareableDictionary<Int, Int> subscript, noop setter",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let c = input.count
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
@@ -147,11 +147,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> subscript, set existing",
|
||||
title: "ShareableDictionary<Int, Int> subscript, set existing",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
d[i] = 0
|
||||
@@ -163,11 +163,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> subscript, _modify",
|
||||
title: "ShareableDictionary<Int, Int> subscript, _modify",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
d[i]! *= 2
|
||||
@@ -179,10 +179,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.addSimple(
|
||||
title: "PersistentDictionary<Int, Int> subscript, insert, unique",
|
||||
title: "ShareableDictionary<Int, Int> subscript, insert, unique",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
var d: PersistentDictionary<Int, Int> = [:]
|
||||
var d: ShareableDictionary<Int, Int> = [:]
|
||||
for i in input {
|
||||
d[i] = 2 * i
|
||||
}
|
||||
@@ -191,10 +191,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.addSimple(
|
||||
title: "PersistentDictionary<Int, Int> subscript, insert, shared",
|
||||
title: "ShareableDictionary<Int, Int> subscript, insert, shared",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
var d: PersistentDictionary<Int, Int> = [:]
|
||||
var d: ShareableDictionary<Int, Int> = [:]
|
||||
for i in input {
|
||||
let copy = d
|
||||
d[i] = 2 * i
|
||||
@@ -205,11 +205,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> subscript, remove existing, unique",
|
||||
title: "ShareableDictionary<Int, Int> subscript, remove existing, unique",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
d[i] = nil
|
||||
@@ -221,11 +221,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> subscript, remove existing, shared",
|
||||
title: "ShareableDictionary<Int, Int> subscript, remove existing, shared",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
let copy = d
|
||||
@@ -239,11 +239,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> subscript, remove missing",
|
||||
title: "ShareableDictionary<Int, Int> subscript, remove missing",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let c = input.count
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
@@ -256,10 +256,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> defaulted subscript, successful lookups",
|
||||
title: "ShareableDictionary<Int, Int> defaulted subscript, successful lookups",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
return { timer in
|
||||
for i in lookups {
|
||||
precondition(d[i, default: -1] != -1)
|
||||
@@ -268,10 +268,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> defaulted subscript, unsuccessful lookups",
|
||||
title: "ShareableDictionary<Int, Int> defaulted subscript, unsuccessful lookups",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
return { timer in
|
||||
let c = d.count
|
||||
for i in lookups {
|
||||
@@ -281,11 +281,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> defaulted subscript, _modify existing",
|
||||
title: "ShareableDictionary<Int, Int> defaulted subscript, _modify existing",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
timer.measure {
|
||||
for i in input {
|
||||
d[i, default: -1] *= 2
|
||||
@@ -297,11 +297,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> defaulted subscript, _modify missing",
|
||||
title: "ShareableDictionary<Int, Int> defaulted subscript, _modify missing",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let c = input.count
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
@@ -314,10 +314,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> successful index(forKey:)",
|
||||
title: "ShareableDictionary<Int, Int> successful index(forKey:)",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
return { timer in
|
||||
for i in lookups {
|
||||
precondition(d.index(forKey: i) != nil)
|
||||
@@ -326,10 +326,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> unsuccessful index(forKey:)",
|
||||
title: "ShareableDictionary<Int, Int> unsuccessful index(forKey:)",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
let d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
let d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
return { timer in
|
||||
for i in lookups {
|
||||
precondition(d.index(forKey: lookups.count + i) == nil)
|
||||
@@ -338,11 +338,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> updateValue(_:forKey:), existing",
|
||||
title: "ShareableDictionary<Int, Int> updateValue(_:forKey:), existing",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
d.updateValue(0, forKey: i)
|
||||
@@ -354,11 +354,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> updateValue(_:forKey:), insert",
|
||||
title: "ShareableDictionary<Int, Int> updateValue(_:forKey:), insert",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
d.updateValue(0, forKey: input.count + i)
|
||||
@@ -370,11 +370,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> random removals (existing keys)",
|
||||
title: "ShareableDictionary<Int, Int> random removals (existing keys)",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { ($0, 2 * $0) })
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
precondition(d.removeValue(forKey: i) != nil)
|
||||
@@ -386,12 +386,12 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Int, Int> random removals (missing keys)",
|
||||
title: "ShareableDictionary<Int, Int> random removals (missing keys)",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
let c = input.count
|
||||
var d = PersistentDictionary(uniqueKeysWithValues: input.lazy.map { (c + $0, 2 * $0) })
|
||||
var d = ShareableDictionary(uniqueKeysWithValues: input.lazy.map { (c + $0, 2 * $0) })
|
||||
timer.measure {
|
||||
for i in lookups {
|
||||
precondition(d.removeValue(forKey: i) == nil)
|
||||
@@ -403,11 +403,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Large, Large> subscript, insert, unique",
|
||||
title: "ShareableDictionary<Large, Large> subscript, insert, unique",
|
||||
input: [Large].self
|
||||
) { input in
|
||||
return { timer in
|
||||
var d: PersistentDictionary<Large, Large> = [:]
|
||||
var d: ShareableDictionary<Large, Large> = [:]
|
||||
timer.measure {
|
||||
for value in input {
|
||||
d[value] = value
|
||||
@@ -419,11 +419,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Large, Large> subscript, insert, shared",
|
||||
title: "ShareableDictionary<Large, Large> subscript, insert, shared",
|
||||
input: [Large].self
|
||||
) { input in
|
||||
return { timer in
|
||||
var d: PersistentDictionary<Large, Large> = [:]
|
||||
var d: ShareableDictionary<Large, Large> = [:]
|
||||
timer.measure {
|
||||
for value in input {
|
||||
let copy = d
|
||||
@@ -437,11 +437,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Large, Large> subscript, remove existing, unique",
|
||||
title: "ShareableDictionary<Large, Large> subscript, remove existing, unique",
|
||||
input: ([Large], [Large]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(
|
||||
var d = ShareableDictionary(
|
||||
uniqueKeysWithValues: input.lazy.map { ($0, $0) })
|
||||
timer.measure {
|
||||
for key in lookups {
|
||||
@@ -454,11 +454,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentDictionary<Large, Large> subscript, remove existing, shared",
|
||||
title: "ShareableDictionary<Large, Large> subscript, remove existing, shared",
|
||||
input: ([Large], [Large]).self
|
||||
) { input, lookups in
|
||||
return { timer in
|
||||
var d = PersistentDictionary(
|
||||
var d = ShareableDictionary(
|
||||
uniqueKeysWithValues: input.lazy.map { ($0, $0) })
|
||||
timer.measure {
|
||||
for key in lookups {
|
||||
+160
-155
@@ -10,31 +10,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import CollectionsBenchmark
|
||||
import PersistentCollections
|
||||
import ShareableHashedCollections
|
||||
|
||||
extension Benchmark {
|
||||
public mutating func addPersistentSetBenchmarks() {
|
||||
public mutating func addShareableSetBenchmarks() {
|
||||
self.addSimple(
|
||||
title: "PersistentSet<Int> init from range",
|
||||
title: "ShareableSet<Int> init from range",
|
||||
input: Int.self
|
||||
) { size in
|
||||
blackHole(PersistentSet(0 ..< size))
|
||||
blackHole(ShareableSet(0 ..< size))
|
||||
}
|
||||
|
||||
self.addSimple(
|
||||
title: "PersistentSet<Int> init from unsafe buffer",
|
||||
title: "ShareableSet<Int> init from unsafe buffer",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
input.withUnsafeBufferPointer { buffer in
|
||||
blackHole(PersistentSet(buffer))
|
||||
blackHole(ShareableSet(buffer))
|
||||
}
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentSet<Int> sequential iteration",
|
||||
title: "ShareableSet<Int> sequential iteration",
|
||||
input: Int.self
|
||||
) { size in
|
||||
let set = PersistentSet(0 ..< size)
|
||||
let set = ShareableSet(0 ..< size)
|
||||
return { timer in
|
||||
for i in set {
|
||||
blackHole(i)
|
||||
@@ -43,10 +43,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentSet<Int> sequential iteration, indices",
|
||||
title: "ShareableSet<Int> sequential iteration, indices",
|
||||
input: Int.self
|
||||
) { size in
|
||||
let set = PersistentSet(0 ..< size)
|
||||
let set = ShareableSet(0 ..< size)
|
||||
return { timer in
|
||||
for i in set.indices {
|
||||
blackHole(set[i])
|
||||
@@ -55,10 +55,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentSet<Int> successful contains",
|
||||
title: "ShareableSet<Int> successful contains",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
let set = PersistentSet(input)
|
||||
let set = ShareableSet(input)
|
||||
return { timer in
|
||||
for i in lookups {
|
||||
precondition(set.contains(i))
|
||||
@@ -67,10 +67,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentSet<Int> unsuccessful contains",
|
||||
title: "ShareableSet<Int> unsuccessful contains",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, lookups in
|
||||
let set = PersistentSet(input)
|
||||
let set = ShareableSet(input)
|
||||
let lookups = lookups.map { $0 + input.count }
|
||||
return { timer in
|
||||
for i in lookups {
|
||||
@@ -80,10 +80,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.addSimple(
|
||||
title: "PersistentSet<Int> insert",
|
||||
title: "ShareableSet<Int> insert",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
var set: PersistentSet<Int> = []
|
||||
var set: ShareableSet<Int> = []
|
||||
for i in input {
|
||||
set.insert(i)
|
||||
}
|
||||
@@ -92,10 +92,10 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.addSimple(
|
||||
title: "PersistentSet<Int> insert, shared",
|
||||
title: "ShareableSet<Int> insert, shared",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
var set: PersistentSet<Int> = []
|
||||
var set: ShareableSet<Int> = []
|
||||
for i in input {
|
||||
let copy = set
|
||||
set.insert(i)
|
||||
@@ -105,26 +105,11 @@ extension Benchmark {
|
||||
blackHole(set)
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentSet<Int> 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<Int> model diffing",
|
||||
title: "ShareableSet<Int> model diffing",
|
||||
input: Int.self
|
||||
) { input in
|
||||
typealias Model = PersistentSet<Int>
|
||||
typealias Model = ShareableSet<Int>
|
||||
|
||||
var _state: Model = [] // Private
|
||||
func updateState(
|
||||
@@ -145,11 +130,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentSet<Int> remove",
|
||||
title: "ShareableSet<Int> remove",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, removals in
|
||||
return { timer in
|
||||
var set = PersistentSet(input)
|
||||
var set = ShareableSet(input)
|
||||
for i in removals {
|
||||
set.remove(i)
|
||||
}
|
||||
@@ -159,11 +144,11 @@ extension Benchmark {
|
||||
}
|
||||
|
||||
self.add(
|
||||
title: "PersistentSet<Int> remove, shared",
|
||||
title: "ShareableSet<Int> remove, shared",
|
||||
input: ([Int], [Int]).self
|
||||
) { input, removals in
|
||||
return { timer in
|
||||
var set = PersistentSet(input)
|
||||
var set = ShareableSet(input)
|
||||
for i in removals {
|
||||
let copy = set
|
||||
set.remove(i)
|
||||
@@ -184,58 +169,68 @@ extension Benchmark {
|
||||
|
||||
// SetAlgebra operations with Self
|
||||
do {
|
||||
for (percentage, start) in overlaps {
|
||||
self.add(
|
||||
title: "PersistentSet<Int> union with Self (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let a = PersistentSet(input)
|
||||
let b = PersistentSet(start ..< start + input.count)
|
||||
return { timer in
|
||||
blackHole(a.union(identity(b)))
|
||||
}
|
||||
func makeB(
|
||||
_ a: ShareableSet<Int>, _ range: Range<Int>, shared: Bool
|
||||
) -> ShareableSet<Int> {
|
||||
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<Int> intersection with Self (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let a = PersistentSet(input)
|
||||
let b = PersistentSet(start ..< start + input.count)
|
||||
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<Int> symmetricDifference with Self (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let a = PersistentSet(input)
|
||||
let b = PersistentSet(start ..< start + input.count)
|
||||
return { timer in
|
||||
blackHole(a.symmetricDifference(identity(b)))
|
||||
self.add(
|
||||
title: "ShareableSet<Int> 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<Int> subtracting Self (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let a = PersistentSet(input)
|
||||
let b = PersistentSet(start ..< start + input.count)
|
||||
return { timer in
|
||||
blackHole(a.subtracting(identity(b)))
|
||||
self.add(
|
||||
title: "ShareableSet<Int> 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<Int> 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<Int> 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<Int> union with Array (\(percentage) overlap)",
|
||||
title: "ShareableSet<Int> union with Array (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let a = PersistentSet(input)
|
||||
let a = ShareableSet(input)
|
||||
let b = Array(start ..< start + input.count)
|
||||
return { timer in
|
||||
blackHole(a.union(identity(b)))
|
||||
@@ -259,11 +254,11 @@ extension Benchmark {
|
||||
|
||||
for (percentage, start) in overlaps {
|
||||
self.add(
|
||||
title: "PersistentSet<Int> intersection with Array (\(percentage) overlap)",
|
||||
title: "ShareableSet<Int> intersection with Array (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let a = PersistentSet(input)
|
||||
let a = ShareableSet(input)
|
||||
let b = Array(start ..< start + input.count)
|
||||
return { timer in
|
||||
blackHole(a.intersection(identity(b)))
|
||||
@@ -273,11 +268,11 @@ extension Benchmark {
|
||||
|
||||
for (percentage, start) in overlaps {
|
||||
self.add(
|
||||
title: "PersistentSet<Int> symmetricDifference with Array (\(percentage) overlap)",
|
||||
title: "ShareableSet<Int> symmetricDifference with Array (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let a = PersistentSet(input)
|
||||
let a = ShareableSet(input)
|
||||
let b = Array(start ..< start + input.count)
|
||||
return { timer in
|
||||
blackHole(a.symmetricDifference(identity(b)))
|
||||
@@ -287,11 +282,11 @@ extension Benchmark {
|
||||
|
||||
for (percentage, start) in overlaps {
|
||||
self.add(
|
||||
title: "PersistentSet<Int> subtracting Array (\(percentage) overlap)",
|
||||
title: "ShareableSet<Int> subtracting Array (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let a = PersistentSet(input)
|
||||
let a = ShareableSet(input)
|
||||
let b = Array(start ..< start + input.count)
|
||||
return { timer in
|
||||
blackHole(a.subtracting(identity(b)))
|
||||
@@ -302,70 +297,80 @@ extension Benchmark {
|
||||
|
||||
// SetAlgebra mutations with Self
|
||||
do {
|
||||
for (percentage, start) in overlaps {
|
||||
self.add(
|
||||
title: "PersistentSet<Int> 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<Int>, _ range: Range<Int>, shared: Bool
|
||||
) -> ShareableSet<Int> {
|
||||
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<Int> 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<Int> 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<Int> 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<Int> 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<Int> 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<Int> 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<Int> 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<Int> formUnion with Array (\(percentage) overlap)",
|
||||
title: "ShareableSet<Int> formUnion with Array (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let b = Array(start ..< start + input.count)
|
||||
return { timer in
|
||||
var a = PersistentSet(input)
|
||||
var a = ShareableSet(input)
|
||||
timer.measure {
|
||||
a.formUnion(identity(b))
|
||||
}
|
||||
@@ -392,13 +397,13 @@ extension Benchmark {
|
||||
|
||||
for (percentage, start) in overlaps {
|
||||
self.add(
|
||||
title: "PersistentSet<Int> formIntersection with Array (\(percentage) overlap)",
|
||||
title: "ShareableSet<Int> formIntersection with Array (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let b = Array(start ..< start + input.count)
|
||||
return { timer in
|
||||
var a = PersistentSet(input)
|
||||
var a = ShareableSet(input)
|
||||
timer.measure {
|
||||
a.formIntersection(identity(b))
|
||||
}
|
||||
@@ -409,13 +414,13 @@ extension Benchmark {
|
||||
|
||||
for (percentage, start) in overlaps {
|
||||
self.add(
|
||||
title: "PersistentSet<Int> formSymmetricDifference with Array (\(percentage) overlap)",
|
||||
title: "ShareableSet<Int> formSymmetricDifference with Array (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let b = Array(start ..< start + input.count)
|
||||
return { timer in
|
||||
var a = PersistentSet(input)
|
||||
var a = ShareableSet(input)
|
||||
timer.measure {
|
||||
a.formSymmetricDifference(identity(b))
|
||||
}
|
||||
@@ -426,13 +431,13 @@ extension Benchmark {
|
||||
|
||||
for (percentage, start) in overlaps {
|
||||
self.add(
|
||||
title: "PersistentSet<Int> subtract Array (\(percentage) overlap)",
|
||||
title: "ShareableSet<Int> subtract Array (\(percentage) overlap)",
|
||||
input: [Int].self
|
||||
) { input in
|
||||
let start = start(input.count)
|
||||
let b = Array(start ..< start + input.count)
|
||||
return { timer in
|
||||
var a = PersistentSet(input)
|
||||
var a = ShareableSet(input)
|
||||
timer.measure {
|
||||
a.subtract(identity(b))
|
||||
}
|
||||
@@ -29,13 +29,13 @@ benchmark.registerCustomGenerators()
|
||||
benchmark.addArrayBenchmarks()
|
||||
benchmark.addSetBenchmarks()
|
||||
benchmark.addDictionaryBenchmarks()
|
||||
benchmark.addPersistentDictionaryBenchmarks()
|
||||
benchmark.addShareableDictionaryBenchmarks()
|
||||
benchmark.addDequeBenchmarks()
|
||||
benchmark.addOrderedSetBenchmarks()
|
||||
benchmark.addOrderedDictionaryBenchmarks()
|
||||
benchmark.addHeapBenchmarks()
|
||||
benchmark.addBitSetBenchmarks()
|
||||
benchmark.addPersistentSetBenchmarks()
|
||||
benchmark.addShareableSetBenchmarks()
|
||||
benchmark.addCppBenchmarks()
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
||||
benchmark.addFoundationBenchmarks()
|
||||
|
||||
@@ -30,11 +30,11 @@ struct MemoryBenchmarks: ParsableCommand {
|
||||
var i = 0
|
||||
|
||||
var d: Dictionary<String, String> = [:]
|
||||
var pd: PersistentDictionary<String, String> = [:]
|
||||
var pd: ShareableDictionary<String, String> = [:]
|
||||
|
||||
print("""
|
||||
Size,"Dictionary<String, String>",\
|
||||
"PersistentDictionary<String, String>",\
|
||||
"ShareableDictionary<String, String>",\
|
||||
"average node size",\
|
||||
"average item depth"
|
||||
""")
|
||||
@@ -67,9 +67,9 @@ struct MemoryBenchmarks: ParsableCommand {
|
||||
complain("""
|
||||
Averages:
|
||||
Dictionary: \(sumd / Double(sizes.count))
|
||||
PersistentDictionary: \(sump / Double(sizes.count))
|
||||
ShareableDictionary: \(sump / Double(sizes.count))
|
||||
|
||||
PersistentDictionary at 1M items:
|
||||
ShareableDictionary at 1M items:
|
||||
average node size: \(pstats.averageNodeSize)
|
||||
average item depth: \(pstats.averageItemDepth)
|
||||
average lookup chain length: \(pstats.averageLookupChainLength)
|
||||
|
||||
+349
@@ -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<Int>
|
||||
|
||||
var _state: Model // Private
|
||||
func updateState(
|
||||
with model: Model
|
||||
) -> (insertions: Set<Int>, removals: Set<Int>) {
|
||||
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<Int>` to `ShareableSet<Int>` leads to an algorithmic improvement to running time:
|
||||
|
||||
```swift
|
||||
typealias Model = ShareableSet<Int>
|
||||
|
||||
... // 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:
|
||||
|
||||

|
||||
|
||||
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:
|
||||
|
||||

|
||||
|
||||
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.
|
||||
|
||||

|
||||
|
||||
(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<Element: Hashable>
|
||||
: 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: Sequence>(S)
|
||||
init(`Self`)
|
||||
init<Value>(ShareableDictionary<Element, Value>.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<Element>
|
||||
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<Element>
|
||||
func intersection<Value>(ShareableDictionary<Element, Value>.Keys) -> ShareableSet<Element>
|
||||
func intersection<S>(S) -> ShareableSet<Element>
|
||||
|
||||
func union(`Self`) -> ShareableSet<Element>
|
||||
func union<Value>(ShareableDictionary<Element, Value>.Keys) -> ShareableSet<Element>
|
||||
func union<S>(S) -> ShareableSet<Element>
|
||||
|
||||
func subtracting(`Self`) -> ShareableSet<Element>
|
||||
func subtracting<V>(ShareableDictionary<Element, V>.Keys) -> ShareableSet<Element>
|
||||
func subtracting<S>(S) -> ShareableSet<Element>
|
||||
|
||||
func symmetricDifference(`Self`) -> ShareableSet<Element>
|
||||
func symmetricDifference<Value>(ShareableDictionary<Element, Value>.Keys) -> ShareableSet<Element>
|
||||
func symmetricDifference<S>(S) -> ShareableSet<Element>
|
||||
|
||||
func formIntersection(`Self`)
|
||||
func formIntersection<Value>(ShareableDictionary<Element, Value>.Keys)
|
||||
func formIntersection<S>(S)
|
||||
|
||||
func formUnion(`Self`)
|
||||
func formUnion<Value>(ShareableDictionary<Element, Value>.Keys)
|
||||
func formUnion<S>(S)
|
||||
|
||||
func subtract(`Self`)
|
||||
func subtract<Value>(ShareableDictionary<Element, Value>.Keys)
|
||||
func subtract<S>(S)
|
||||
|
||||
func formSymmetricDifference(`Self`)
|
||||
func formSymmetricDifference<Value>(ShareableDictionary<Element, Value>.Keys)
|
||||
func formSymmetricDifference<S>(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<Value>(to: ShareableDictionary<Element, Value>.Keys) -> Bool
|
||||
func isEqualSet<S>(to: S) -> Bool
|
||||
|
||||
func isSubset(of: `Self`) -> Bool
|
||||
func isSubset<Value>(of: ShareableDictionary<Element, Value>.Keys) -> Bool
|
||||
func isSubset<S>(of: S) -> Bool
|
||||
|
||||
func isSuperset(of: `Self`) -> Bool
|
||||
func isSuperset<Value>(of: ShareableDictionary<Element, Value>.Keys) -> Bool
|
||||
func isSuperset<S>(of: S) -> Bool
|
||||
|
||||
func isStrictSubset(of: `Self`) -> Bool
|
||||
func isStrictSubset<Value>(of: ShareableDictionary<Element, Value>.Keys) -> Bool
|
||||
func isStrictSubset<S>(of: S) -> Bool
|
||||
|
||||
func isStrictSuperset(of: `Self`) -> Bool
|
||||
func isStrictSuperset<Value>(of: ShareableDictionary<Element, Value>.Keys) -> Bool
|
||||
func isStrictSuperset<S>(of: S) -> Bool
|
||||
|
||||
func isDisjoint(with: `Self`) -> Bool
|
||||
func isDisjoint<Value>(with: ShareableDictionary<Element, Value>.Keys) -> Bool
|
||||
func isDisjoint<S>(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<Key: Hashable, Value>
|
||||
: 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<Key>) -> Self
|
||||
func intersection<Value2>(ShareableDictionary<Key, Value2>.Keys) -> Self
|
||||
|
||||
func subtracting(ShareableSet<Key>) -> Self
|
||||
func subtracting<Value2>(ShareableDictionary<Key, Value2>.Keys) -> Self
|
||||
}
|
||||
```
|
||||
|
||||
#### Creating a Dictionary
|
||||
|
||||
```swift
|
||||
init()
|
||||
init(ShareableDictionary<Key, Value>)
|
||||
init(Dictionary<Key, Value>)
|
||||
init<S>(uniqueKeysWithValues: S)
|
||||
init<S>(S, uniquingKeysWith: (Value, Value) throws -> Value) rethrows
|
||||
init<S>(grouping: S, by: (S.Element) throws -> Key) rethrows
|
||||
init(keys: ShareableSet<Key>, 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<R>(forKey: Key, with: (inout Value?) throws -> R) rethrows -> R
|
||||
func updateValue<R>(forKey: Key, default: () -> Value, with: (inout Value) throws -> R) rethrows -> R
|
||||
|
||||
func merge(`Self`, uniquingKeysWith: (Value, Value) throws -> Value) rethrows
|
||||
func merge<S>(S, uniquingKeysWith: (Value, Value) throws -> Value) rethrows
|
||||
|
||||
func merging(`Self`, uniquingKeysWith: (Value, Value) throws -> Value) rethrows -> ShareableDictionary<Key, Value>
|
||||
func merging<S>(S, uniquingKeysWith: (Value, Value) throws -> Value) rethrows -> ShareableDictionary<Key, Value>
|
||||
```
|
||||
|
||||
#### Removing Keys and Values
|
||||
|
||||
```swift
|
||||
func removeValue(forKey: Key) -> Value?
|
||||
func remove(at: Index) -> Element
|
||||
func filter((Element) throws -> Bool) rethrows -> ShareableDictionary<Key, Value>
|
||||
mutating func removeAll(where shouldBeRemoved: (Element) throws -> Bool) rethrows
|
||||
```
|
||||
|
||||
#### Comparing Dictionaries
|
||||
|
||||
```swift
|
||||
static func == (`Self`, `Self`) -> Bool
|
||||
```
|
||||
|
||||
#### Transforming a Dictionary
|
||||
|
||||
```swift
|
||||
func mapValues<T>((Value) throws -> T) rethrows -> ShareableDictionary<Key, T>
|
||||
func compactMapValues<T>((Value) throws -> T?) rethrows -> ShareableDictionary<Key, T>
|
||||
```
|
||||
|
||||
## 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.
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 615 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 319 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 344 KiB |
+6
-6
@@ -52,7 +52,7 @@ let package = Package(
|
||||
.library(name: "DequeModule", targets: ["DequeModule"]),
|
||||
.library(name: "HeapModule", targets: ["HeapModule"]),
|
||||
.library(name: "OrderedCollections", targets: ["OrderedCollections"]),
|
||||
.library(name: "PersistentCollections", targets: ["PersistentCollections"]),
|
||||
.library(name: "ShareableHashedCollections", targets: ["ShareableHashedCollections"]),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
@@ -62,7 +62,7 @@ let package = Package(
|
||||
"DequeModule",
|
||||
"HeapModule",
|
||||
"OrderedCollections",
|
||||
"PersistentCollections",
|
||||
"ShareableHashedCollections",
|
||||
],
|
||||
exclude: ["CMakeLists.txt"],
|
||||
swiftSettings: settings),
|
||||
@@ -134,15 +134,15 @@ let package = Package(
|
||||
dependencies: ["OrderedCollections", "_CollectionsTestSupport"],
|
||||
swiftSettings: settings),
|
||||
|
||||
// PersistentSet<Element>, PersistentDictionary<Key, Value>
|
||||
// ShareableSet<Element>, ShareableDictionary<Key, Value>
|
||||
.target(
|
||||
name: "PersistentCollections",
|
||||
name: "ShareableHashedCollections",
|
||||
dependencies: ["_CollectionsUtilities"],
|
||||
exclude: ["CMakeLists.txt"],
|
||||
swiftSettings: settings),
|
||||
.testTarget(
|
||||
name: "PersistentCollectionsTests",
|
||||
dependencies: ["PersistentCollections", "_CollectionsTestSupport"],
|
||||
name: "ShareableHashedCollectionsTests",
|
||||
dependencies: ["ShareableHashedCollections", "_CollectionsTestSupport"],
|
||||
swiftSettings: settings),
|
||||
]
|
||||
)
|
||||
@@ -20,7 +20,7 @@ The package currently provides the following implementations:
|
||||
|
||||
- [`OrderedDictionary<Key, Value>`][OrderedDictionary], an ordered variant of the standard `Dictionary`, providing similar benefits.
|
||||
|
||||
- [`PersistentSet`][PersistentSet] and [`PersistentDictionary`][PersistentDictionary], persistent hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). These work similar to the standard `Set` and `Dictionary`, but they excel at use cases that mutate shared copies, offering dramatic memory savings and radical time improvements.
|
||||
- [`ShareableSet`][ShareableSet] and [`ShareableDictionary`][ShareableDictionary], persistent hashed collections implementing Compressed Hash-Array Mapped Prefix Trees (CHAMP). These work similar to the standard `Set` and `Dictionary`, but they excel at use cases that mutate shared copies, offering dramatic memory savings and radical time improvements.
|
||||
|
||||
[BitSet]: Documentation/BitSet.md
|
||||
[BitArray]: Documentation/BitArray.md
|
||||
@@ -28,8 +28,8 @@ The package currently provides the following implementations:
|
||||
[Heap]: Documentation/Heap.md
|
||||
[OrderedSet]: Documentation/OrderedSet.md
|
||||
[OrderedDictionary]: Documentation/OrderedDictionary.md
|
||||
[PersistentSet]: Documentation/PersistentSet.md
|
||||
[PersistentDictionary]: Documentation/PersistentDictionary.md
|
||||
[ShareableSet]: Documentation/ShareableSet.md
|
||||
[ShareableDictionary]: Documentation/ShareableDictionary.md
|
||||
|
||||
The following data structures are currently being worked on but they aren't ready for inclusion in a tagged release:
|
||||
|
||||
@@ -55,7 +55,7 @@ The Swift Collections package is source stable. The version numbers follow [Sema
|
||||
|
||||
[semver]: https://semver.org
|
||||
|
||||
The public API of version 1.1 of the `swift-collections` package consists of non-underscored declarations that are marked `public` in the `Collections`, `BitCollections`, `DequeModule`, `HeapModule`, `OrderedCollections` and `PersistentCollections` modules.
|
||||
The public API of version 1.1 of the `swift-collections` package consists of non-underscored declarations that are marked `public` in the `Collections`, `BitCollections`, `DequeModule`, `HeapModule`, `OrderedCollections` and `ShareableHashedCollections` modules.
|
||||
|
||||
Interfaces that aren't part of the public API may continue to change in any release, including patch releases.
|
||||
If you have a use case that requires using underscored APIs, please [submit a Feature Request][enhancement] describing it! We'd like the public interface to be as useful as possible -- although preferably without compromising safety or limiting future evolution.
|
||||
|
||||
@@ -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)
|
||||
@@ -14,7 +14,7 @@ target_link_libraries(Collections PRIVATE
|
||||
DequeModule
|
||||
HeapModule
|
||||
OrderedCollections
|
||||
PersistentCollections
|
||||
ShareableHashedCollections
|
||||
)
|
||||
set_target_properties(Collections PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
|
||||
|
||||
@@ -34,5 +34,5 @@
|
||||
|
||||
### Persistent Collections
|
||||
|
||||
- ``PersistentSet``
|
||||
- ``PersistentDictionary``
|
||||
- ``ShareableSet``
|
||||
- ``ShareableDictionary``
|
||||
+22
-27
@@ -1,4 +1,4 @@
|
||||
# ``Collections/PersistentDictionary``
|
||||
# ``Collections/ShareableDictionary``
|
||||
|
||||
<!-- DO NOT EDIT THIS FILE; IT'S AUTOMATICALLY GENERATED -->
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
### Collection Views
|
||||
|
||||
`PersistentDictionary` provides the customary dictionary views, `keys` and
|
||||
`ShareableDictionary` provides the customary dictionary views, `keys` and
|
||||
`values`. These are collection types that are projections of the dictionary
|
||||
itself, with elements that match only the keys or values of the dictionary,
|
||||
respectively. The `Keys` view is notable in that it provides operations for
|
||||
subtracting and intersecting the keys of two dictionaries, allowing for easy
|
||||
detection of inserted and removed items between two snapshots of the same
|
||||
dictionary. Because `PersistentDictionary` needs to invalidate indices on every
|
||||
dictionary. Because `ShareableDictionary` needs to invalidate indices on every
|
||||
mutation, its `Values` view is not a `MutableCollection`.
|
||||
|
||||
- ``Keys-swift.struct``
|
||||
@@ -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
|
||||
|
||||
- ``==(_:_:)``
|
||||
+55
-64
@@ -1,11 +1,11 @@
|
||||
# ``Collections/PersistentSet``
|
||||
# ``Collections/ShareableSet``
|
||||
|
||||
<!-- DO NOT EDIT THIS FILE; IT'S AUTOMATICALLY GENERATED -->
|
||||
|
||||
|
||||
### Implementation Details
|
||||
|
||||
`PersistentSet` and `PersistentDictionary` are based on a Swift adaptation
|
||||
`ShareableSet` and `ShareableDictionary` are based on a Swift adaptation
|
||||
of the *Compressed Hash-Array Mapped Prefix Tree* (CHAMP) data structure.
|
||||
|
||||
- Michael J Steindorfer and Jurgen J Vinju. Optimizing Hash-Array Mapped
|
||||
@@ -18,7 +18,7 @@ In this setup, the members of such a collection are organized into a tree
|
||||
data structure based on their hash values. For example, assuming 16 bit hash
|
||||
values sliced into 4-bit chunks, each node in the prefix tree would have
|
||||
sixteen slots (one for each digit), each of which may contain a member, a
|
||||
child node reference, or it may be empty. A `PersistentSet` containing the
|
||||
child node reference, or it may be empty. A `ShareableSet` containing the
|
||||
three items `Maximo`, `Julia` and `Don Pablo` (with hash values of `0x2B65`,
|
||||
`0xA69F` and `0xADA1`, respectively) may be organized into a prefix tree of
|
||||
two nodes:
|
||||
@@ -65,7 +65,7 @@ share the same hash. Looking up a member in one of these nodes requires a
|
||||
linear search, so it is crucial that such collisions do not happen often.
|
||||
|
||||
As long as `Element` properly implements `Hashable`, lookup operations in a
|
||||
`PersistentSet` are expected to be able to decide whether the set contains a
|
||||
`ShareableSet` are expected to be able to decide whether the set contains a
|
||||
particular item by looking at no more than a constant number of items on
|
||||
average -- typically they will need to compare against just one member.
|
||||
|
||||
@@ -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``
|
||||
@@ -13,4 +13,4 @@
|
||||
@_exported import DequeModule
|
||||
@_exported import HeapModule
|
||||
@_exported import OrderedCollections
|
||||
@_exported import PersistentCollections
|
||||
@_exported import ShareableHashedCollections
|
||||
@@ -1,105 +0,0 @@
|
||||
#[[
|
||||
This source file is part of the Swift Collections Open Source Project
|
||||
|
||||
Copyright (c) 2022 Apple Inc. and the Swift project authors
|
||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
|
||||
See https://swift.org/LICENSE.txt for license information
|
||||
#]]
|
||||
|
||||
add_library(PersistentCollections
|
||||
"Node/_AncestorSlots.swift"
|
||||
"Node/_Bitmap.swift"
|
||||
"Node/_Bucket.swift"
|
||||
"Node/_Hash.swift"
|
||||
"Node/_HashTreeIterator.swift"
|
||||
"Node/_HashTreeStatistics.swift"
|
||||
"Node/_Level.swift"
|
||||
"Node/_Node+Builder.swift"
|
||||
"Node/_Node+Debugging.swift"
|
||||
"Node/_Node+Initializers.swift"
|
||||
"Node/_Node+Invariants.swift"
|
||||
"Node/_Node+Lookups.swift"
|
||||
"Node/_Node+Primitive Insertions.swift"
|
||||
"Node/_Node+Primitive Removals.swift"
|
||||
"Node/_Node+Primitive Replacement.swift"
|
||||
"Node/_Node+Storage.swift"
|
||||
"Node/_Node+Structural compactMapValues.swift"
|
||||
"Node/_Node+Structural filter.swift"
|
||||
"Node/_Node+Structural intersection.swift"
|
||||
"Node/_Node+Structural isDisjoint.swift"
|
||||
"Node/_Node+Structural isEqualSet.swift"
|
||||
"Node/_Node+Structural isSubset.swift"
|
||||
"Node/_Node+Structural mapValues.swift"
|
||||
"Node/_Node+Structural merge.swift"
|
||||
"Node/_Node+Structural subtracting.swift"
|
||||
"Node/_Node+Structural symmetricDifference.swift"
|
||||
"Node/_Node+Structural union.swift"
|
||||
"Node/_Node+Subtree Insertions.swift"
|
||||
"Node/_Node+Subtree Modify.swift"
|
||||
"Node/_Node+Subtree Removals.swift"
|
||||
"Node/_Node+UnsafeHandle.swift"
|
||||
"Node/_Node.swift"
|
||||
"Node/_RawNode+UnsafeHandle.swift"
|
||||
"Node/_RawNode.swift"
|
||||
"Node/_Slot.swift"
|
||||
"Node/_Stack.swift"
|
||||
"Node/_StorageHeader.swift"
|
||||
"Node/_UnmanagedNode.swift"
|
||||
"Node/_UnsafePath.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Codable.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Collection.swift"
|
||||
"PersistentDictionary/PersistentDictionary+CustomReflectable.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Debugging.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Descriptions.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Equatable.swift"
|
||||
"PersistentDictionary/PersistentDictionary+ExpressibleByDictionaryLiteral.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Filter.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Fluent Operations.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Hashable.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Initializers.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Keys.swift"
|
||||
"PersistentDictionary/PersistentDictionary+MapValues.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Merge.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Sendable.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Sequence.swift"
|
||||
"PersistentDictionary/PersistentDictionary+Values.swift"
|
||||
"PersistentDictionary/PersistentDictionary.swift"
|
||||
"PersistentSet/PersistentSet+Codable.swift"
|
||||
"PersistentSet/PersistentSet+Collection.swift"
|
||||
"PersistentSet/PersistentSet+CustomReflectable.swift"
|
||||
"PersistentSet/PersistentSet+Debugging.swift"
|
||||
"PersistentSet/PersistentSet+Descriptions.swift"
|
||||
"PersistentSet/PersistentSet+Equatable.swift"
|
||||
"PersistentSet/PersistentSet+ExpressibleByArrayLiteral.swift"
|
||||
"PersistentSet/PersistentSet+Extras.swift"
|
||||
"PersistentSet/PersistentSet+Filter.swift"
|
||||
"PersistentSet/PersistentSet+Hashable.swift"
|
||||
"PersistentSet/PersistentSet+Sendable.swift"
|
||||
"PersistentSet/PersistentSet+Sequence.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra Initializers.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra basics.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra fluent basics.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra formIntersection.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra formSymmetricDifference.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra formUnion.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra intersection.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra isDisjoint.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra isEqualSet.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra isStrictSubset.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra isStrictSuperset.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra isSubset.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra isSuperset.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra subtract.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra subtracting.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra symmetricDifference.swift"
|
||||
"PersistentSet/PersistentSet+SetAlgebra union.swift"
|
||||
"PersistentSet/PersistentSet.swift"
|
||||
)
|
||||
target_link_libraries(PersistentCollections PRIVATE
|
||||
_CollectionsUtilities)
|
||||
set_target_properties(PersistentCollections PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
|
||||
|
||||
_install_target(PersistentCollections)
|
||||
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS PersistentCollections)
|
||||
-61
@@ -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))
|
||||
}
|
||||
}
|
||||
-77
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -10,7 +10,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A fixed-size array of just enough size to hold an ancestor path in a
|
||||
/// `PersistentDictionary`.
|
||||
/// `ShareableDictionary`.
|
||||
@usableFromInline
|
||||
@frozen
|
||||
internal struct _Stack<Element> {
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+3
-3
@@ -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.
|
||||
+13
-13
@@ -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.
|
||||
+1
-1
@@ -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)
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
|
||||
import _CollectionsUtilities
|
||||
|
||||
extension PersistentDictionary {
|
||||
extension ShareableDictionary {
|
||||
/// True if consistency checking is enabled in the implementation of this
|
||||
/// type, false otherwise.
|
||||
///
|
||||
+3
-3
@@ -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)>"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
+1
-1
@@ -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.
|
||||
+27
-2
@@ -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) }
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -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.
|
||||
///
|
||||
+10
-10
@@ -9,7 +9,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension PersistentDictionary {
|
||||
extension ShareableDictionary {
|
||||
/// Creates an empty dictionary.
|
||||
///
|
||||
/// This initializer is equivalent to initializing with an empty dictionary
|
||||
@@ -25,7 +25,7 @@ extension PersistentDictionary {
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
public init(_ other: PersistentDictionary<Key, Value>) {
|
||||
public init(_ other: ShareableDictionary<Key, Value>) {
|
||||
self = other
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ extension PersistentDictionary {
|
||||
/// - Complexity: O(`other.count`)
|
||||
@inlinable
|
||||
public init(
|
||||
keys: PersistentSet<Key>,
|
||||
keys: ShareableSet<Key>,
|
||||
valueGenerator valueTransform: (Key) throws -> Value
|
||||
) rethrows {
|
||||
// FIXME: This is a non-standard addition
|
||||
@@ -144,12 +144,12 @@ extension PersistentDictionary {
|
||||
///
|
||||
/// let pairsWithDuplicateKeys = [("a", 1), ("b", 2), ("a", 3), ("b", 4)]
|
||||
///
|
||||
/// let firstValues = PersistentDictionary(
|
||||
/// let firstValues = ShareableDictionary(
|
||||
/// pairsWithDuplicateKeys,
|
||||
/// uniquingKeysWith: { (first, _) in first })
|
||||
/// // ["a": 1, "b": 2]
|
||||
///
|
||||
/// let lastValues = PersistentDictionary(
|
||||
/// let lastValues = ShareableDictionary(
|
||||
/// pairsWithDuplicateKeys,
|
||||
/// uniquingKeysWith: { (_, last) in last })
|
||||
/// // ["a": 3, "b": 4]
|
||||
@@ -183,12 +183,12 @@ extension PersistentDictionary {
|
||||
///
|
||||
/// let pairsWithDuplicateKeys = [("a", 1), ("b", 2), ("a", 3), ("b", 4)]
|
||||
///
|
||||
/// let firstValues = PersistentDictionary(
|
||||
/// let firstValues = ShareableDictionary(
|
||||
/// pairsWithDuplicateKeys,
|
||||
/// uniquingKeysWith: { (first, _) in first })
|
||||
/// // ["a": 1, "b": 2]
|
||||
///
|
||||
/// let lastValues = PersistentDictionary(
|
||||
/// let lastValues = ShareableDictionary(
|
||||
/// pairsWithDuplicateKeys,
|
||||
/// uniquingKeysWith: { (_, last) in last })
|
||||
/// // ["a": 3, "b": 4]
|
||||
@@ -212,7 +212,7 @@ extension PersistentDictionary {
|
||||
}
|
||||
}
|
||||
|
||||
extension PersistentDictionary {
|
||||
extension ShareableDictionary {
|
||||
/// Creates a new dictionary whose keys are the groupings returned by the
|
||||
/// given closure and whose values are arrays of the elements that returned
|
||||
/// each key.
|
||||
@@ -225,7 +225,7 @@ extension PersistentDictionary {
|
||||
/// dictionary from that array by grouping the names by first letter:
|
||||
///
|
||||
/// let students = ["Kofi", "Abena", "Efua", "Kweku", "Akosua"]
|
||||
/// let studentsByLetter = PersistentDictionary(grouping: students, by: { $0.first! })
|
||||
/// let studentsByLetter = ShareableDictionary(grouping: students, by: { $0.first! })
|
||||
/// // ["K": ["Kofi", "Kweku"], "A": ["Abena", "Akosua"], "E": ["Efua"]]
|
||||
///
|
||||
/// The new `studentsByLetter` dictionary has three entries, with students'
|
||||
@@ -260,7 +260,7 @@ extension PersistentDictionary {
|
||||
/// dictionary from that array by grouping the names by first letter:
|
||||
///
|
||||
/// let students = ["Kofi", "Abena", "Efua", "Kweku", "Akosua"]
|
||||
/// let studentsByLetter = PersistentDictionary(grouping: students, by: { $0.first! })
|
||||
/// let studentsByLetter = ShareableDictionary(grouping: students, by: { $0.first! })
|
||||
/// // ["K": ["Kofi", "Kweku"], "A": ["Abena", "Akosua"], "E": ["Efua"]]
|
||||
///
|
||||
/// The new `studentsByLetter` dictionary has three entries, with students'
|
||||
+34
-34
@@ -11,18 +11,18 @@
|
||||
|
||||
import _CollectionsUtilities
|
||||
|
||||
extension PersistentDictionary {
|
||||
extension ShareableDictionary {
|
||||
/// A view of a persistent dictionary’s keys, as a standalone collection.
|
||||
@frozen
|
||||
public struct Keys {
|
||||
@usableFromInline
|
||||
internal typealias _Node = PersistentCollections._Node<Key, Value>
|
||||
internal typealias _Node = ShareableHashedCollections._Node<Key, Value>
|
||||
|
||||
@usableFromInline
|
||||
internal var _base: PersistentDictionary
|
||||
internal var _base: ShareableDictionary
|
||||
|
||||
@inlinable
|
||||
internal init(_base: PersistentDictionary) {
|
||||
internal init(_base: ShareableDictionary) {
|
||||
self._base = _base
|
||||
}
|
||||
}
|
||||
@@ -37,30 +37,30 @@ extension PersistentDictionary {
|
||||
}
|
||||
|
||||
#if swift(>=5.5)
|
||||
extension PersistentDictionary.Keys: Sendable
|
||||
extension ShareableDictionary.Keys: Sendable
|
||||
where Key: Sendable, Value: Sendable {}
|
||||
#endif
|
||||
|
||||
extension PersistentDictionary.Keys: _UniqueCollection {}
|
||||
extension ShareableDictionary.Keys: _UniqueCollection {}
|
||||
|
||||
extension PersistentDictionary.Keys: CustomStringConvertible {
|
||||
extension ShareableDictionary.Keys: CustomStringConvertible {
|
||||
// A textual representation of this instance.
|
||||
public var description: String {
|
||||
_arrayDescription(for: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension PersistentDictionary.Keys: CustomDebugStringConvertible {
|
||||
extension ShareableDictionary.Keys: CustomDebugStringConvertible {
|
||||
/// A textual representation of this instance, suitable for debugging.
|
||||
public var debugDescription: String {
|
||||
_arrayDescription(
|
||||
for: self,
|
||||
debug: true,
|
||||
typeName: "\(PersistentDictionary._debugTypeName()).Keys")
|
||||
typeName: "\(ShareableDictionary._debugTypeName()).Keys")
|
||||
}
|
||||
}
|
||||
|
||||
extension PersistentDictionary.Keys: Sequence {
|
||||
extension ShareableDictionary.Keys: Sequence {
|
||||
/// The element type of the collection.
|
||||
public typealias Element = Key
|
||||
|
||||
@@ -71,10 +71,10 @@ extension PersistentDictionary.Keys: Sequence {
|
||||
public typealias Element = Key
|
||||
|
||||
@usableFromInline
|
||||
internal var _base: PersistentDictionary.Iterator
|
||||
internal var _base: ShareableDictionary.Iterator
|
||||
|
||||
@inlinable
|
||||
internal init(_base: PersistentDictionary.Iterator) {
|
||||
internal init(_base: ShareableDictionary.Iterator) {
|
||||
self._base = _base
|
||||
}
|
||||
|
||||
@@ -113,12 +113,12 @@ extension PersistentDictionary.Keys: Sequence {
|
||||
}
|
||||
|
||||
#if swift(>=5.5)
|
||||
extension PersistentDictionary.Keys.Iterator: Sendable
|
||||
extension ShareableDictionary.Keys.Iterator: Sendable
|
||||
where Key: Sendable, Value: Sendable {}
|
||||
#endif
|
||||
|
||||
extension PersistentDictionary.Keys: Collection {
|
||||
public typealias Index = PersistentDictionary.Index
|
||||
extension ShareableDictionary.Keys: Collection {
|
||||
public typealias Index = ShareableDictionary.Index
|
||||
|
||||
@inlinable
|
||||
public var isEmpty: Bool { _base.isEmpty }
|
||||
@@ -166,10 +166,10 @@ extension PersistentDictionary.Keys: Collection {
|
||||
}
|
||||
|
||||
#if false
|
||||
extension PersistentDictionary.Keys: BidirectionalCollection {
|
||||
extension ShareableDictionary.Keys: BidirectionalCollection {
|
||||
// Note: Let's not do this. `BidirectionalCollection` would imply that
|
||||
// the ordering of elements would be meaningful, which isn't true for
|
||||
// `PersistentDictionary.Keys`.
|
||||
// `ShareableDictionary.Keys`.
|
||||
@inlinable
|
||||
public func formIndex(before i: inout Index) {
|
||||
_base.formIndex(before: &i)
|
||||
@@ -182,12 +182,12 @@ extension PersistentDictionary.Keys: BidirectionalCollection {
|
||||
}
|
||||
#endif
|
||||
|
||||
extension PersistentDictionary.Keys {
|
||||
extension ShareableDictionary.Keys {
|
||||
/// Returns a new keys view with the elements that are common to both this
|
||||
/// view and the provided other one.
|
||||
///
|
||||
/// var a: PersistentDictionary = ["a": 1, "b": 2, "c": 3]
|
||||
/// let b: PersistentDictionary = ["b": 4, "d": 5, "e": 6]
|
||||
/// var a: ShareableDictionary = ["a": 1, "b": 2, "c": 3]
|
||||
/// let b: ShareableDictionary = ["b": 4, "d": 5, "e": 6]
|
||||
/// let c = a.keys.intersection(b.keys)
|
||||
/// // `c` is `["b"]`
|
||||
///
|
||||
@@ -204,19 +204,19 @@ extension PersistentDictionary.Keys {
|
||||
/// hash tree structure to minimize work when possible, e.g. by linking
|
||||
/// parts of the input trees directly into the result.
|
||||
public func intersection<Value2>(
|
||||
_ other: PersistentDictionary<Key, Value2>.Keys
|
||||
_ other: ShareableDictionary<Key, Value2>.Keys
|
||||
) -> Self {
|
||||
guard let r = _base._root.intersection(.top, other._base._root) else {
|
||||
return self
|
||||
}
|
||||
return PersistentDictionary(_new: r).keys
|
||||
return ShareableDictionary(_new: r).keys
|
||||
}
|
||||
|
||||
/// Returns a new keys view with the elements that are common to both this
|
||||
/// view and the provided persistent set.
|
||||
///
|
||||
/// var a: PersistentDictionary = ["a": 1, "b": 2, "c": 3]
|
||||
/// let b: PersistentSet = ["b", "d", "e"]
|
||||
/// var a: ShareableDictionary = ["a": 1, "b": 2, "c": 3]
|
||||
/// let b: ShareableSet = ["b", "d", "e"]
|
||||
/// let c = a.keys.intersection(b)
|
||||
/// // `c` is `["b"]`
|
||||
///
|
||||
@@ -231,18 +231,18 @@ extension PersistentDictionary.Keys {
|
||||
/// However, the implementation is careful to make the best use of
|
||||
/// hash tree structure to minimize work when possible, e.g. by linking
|
||||
/// parts of the input trees directly into the result.
|
||||
public func intersection(_ other: PersistentSet<Key>) -> Self {
|
||||
public func intersection(_ other: ShareableSet<Key>) -> Self {
|
||||
guard let r = _base._root.intersection(.top, other._root) else {
|
||||
return self
|
||||
}
|
||||
return PersistentDictionary(_new: r).keys
|
||||
return ShareableDictionary(_new: r).keys
|
||||
}
|
||||
|
||||
/// Returns a new keys view containing the elements of `self` that do not
|
||||
/// occur in the provided other one.
|
||||
///
|
||||
/// var a: PersistentDictionary = ["a": 1, "b": 2, "c": 3]
|
||||
/// let b: PersistentDictionary = ["b": 4, "d": 5, "e": 6]
|
||||
/// var a: ShareableDictionary = ["a": 1, "b": 2, "c": 3]
|
||||
/// let b: ShareableDictionary = ["b": 4, "d": 5, "e": 6]
|
||||
/// let c = a.keys.subtracting(b.keys)
|
||||
/// // `c` is some permutation of `["a", "c"]`
|
||||
///
|
||||
@@ -255,19 +255,19 @@ extension PersistentDictionary.Keys {
|
||||
/// hash tree structure to minimize work when possible, e.g. by linking
|
||||
/// parts of the input trees directly into the result.
|
||||
public func subtracting<Value2>(
|
||||
_ other: PersistentDictionary<Key, Value2>.Keys
|
||||
_ other: ShareableDictionary<Key, Value2>.Keys
|
||||
) -> Self {
|
||||
guard let r = _base._root.subtracting(.top, other._base._root) else {
|
||||
return self
|
||||
}
|
||||
return PersistentDictionary(_new: r).keys
|
||||
return ShareableDictionary(_new: r).keys
|
||||
}
|
||||
|
||||
/// Returns a new keys view containing the elements of `self` that do not
|
||||
/// occur in the provided persistent set.
|
||||
///
|
||||
/// var a: PersistentDictionary = ["a": 1, "b": 2, "c": 3]
|
||||
/// let b: PersistentSet = ["b", "d", "e"]
|
||||
/// var a: ShareableDictionary = ["a": 1, "b": 2, "c": 3]
|
||||
/// let b: ShareableSet = ["b", "d", "e"]
|
||||
/// let c = a.keys.subtracting(b)
|
||||
/// // `c` is some permutation of `["a", "c"]`
|
||||
///
|
||||
@@ -278,10 +278,10 @@ extension PersistentDictionary.Keys {
|
||||
/// However, the implementation is careful to make the best use of
|
||||
/// hash tree structure to minimize work when possible, e.g. by linking
|
||||
/// parts of the input trees directly into the result.
|
||||
public func subtracting(_ other: PersistentSet<Key>) -> Self {
|
||||
public func subtracting(_ other: ShareableSet<Key>) -> Self {
|
||||
guard let r = _base._root.subtracting(.top, other._root) else {
|
||||
return self
|
||||
}
|
||||
return PersistentDictionary(_new: r).keys
|
||||
return ShareableDictionary(_new: r).keys
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -9,7 +9,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension PersistentDictionary {
|
||||
extension ShareableDictionary {
|
||||
/// Returns a new dictionary containing the keys of this dictionary with the
|
||||
/// values transformed by the given closure.
|
||||
///
|
||||
@@ -23,9 +23,9 @@ extension PersistentDictionary {
|
||||
@inlinable
|
||||
public func mapValues<T>(
|
||||
_ transform: (Value) throws -> T
|
||||
) rethrows -> PersistentDictionary<Key, T> {
|
||||
) rethrows -> ShareableDictionary<Key, T> {
|
||||
let transformed = try _root.mapValues { try transform($0.value) }
|
||||
return PersistentDictionary<Key, T>(_new: transformed)
|
||||
return ShareableDictionary<Key, T>(_new: transformed)
|
||||
}
|
||||
|
||||
/// Returns a new dictionary containing only the key-value pairs that have
|
||||
@@ -38,7 +38,7 @@ extension PersistentDictionary {
|
||||
/// and `compactMapValues` with a transformation that returns an optional
|
||||
/// `Int` value.
|
||||
///
|
||||
/// let data: PersistentDictionary = ["a": "1", "b": "three", "c": "///4///"]
|
||||
/// let data: ShareableDictionary = ["a": "1", "b": "three", "c": "///4///"]
|
||||
///
|
||||
/// let m: [String: Int?] = data.mapValues { str in Int(str) }
|
||||
/// // ["a": Optional(1), "b": nil, "c": nil]
|
||||
@@ -57,8 +57,8 @@ extension PersistentDictionary {
|
||||
@inlinable
|
||||
public func compactMapValues<T>(
|
||||
_ transform: (Value) throws -> T?
|
||||
) rethrows -> PersistentDictionary<Key, T> {
|
||||
) rethrows -> ShareableDictionary<Key, T> {
|
||||
let result = try _root.compactMapValues(.top, transform)
|
||||
return PersistentDictionary<Key, T>(_new: result.finalize(.top))
|
||||
return ShareableDictionary<Key, T>(_new: result.finalize(.top))
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -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 }
|
||||
+1
-1
@@ -10,6 +10,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.5)
|
||||
extension PersistentDictionary: @unchecked Sendable
|
||||
extension ShareableDictionary: @unchecked Sendable
|
||||
where Key: Sendable, Value: Sendable {}
|
||||
#endif
|
||||
+3
-3
@@ -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)
|
||||
+16
-16
@@ -11,21 +11,21 @@
|
||||
|
||||
import _CollectionsUtilities
|
||||
|
||||
extension PersistentDictionary {
|
||||
extension ShareableDictionary {
|
||||
/// A view of a dictionary’s values.
|
||||
@frozen
|
||||
public struct Values {
|
||||
@usableFromInline
|
||||
internal typealias _Node = PersistentCollections._Node<Key, Value>
|
||||
internal typealias _Node = ShareableHashedCollections._Node<Key, Value>
|
||||
|
||||
@usableFromInline
|
||||
internal typealias _UnsafeHandle = _Node.UnsafeHandle
|
||||
|
||||
@usableFromInline
|
||||
internal var _base: PersistentDictionary
|
||||
internal var _base: ShareableDictionary
|
||||
|
||||
@inlinable
|
||||
internal init(_base: PersistentDictionary) {
|
||||
internal init(_base: ShareableDictionary) {
|
||||
self._base = _base
|
||||
}
|
||||
}
|
||||
@@ -42,28 +42,28 @@ extension PersistentDictionary {
|
||||
}
|
||||
|
||||
#if swift(>=5.5)
|
||||
extension PersistentDictionary.Values: Sendable
|
||||
extension ShareableDictionary.Values: Sendable
|
||||
where Key: Sendable, Value: Sendable {}
|
||||
#endif
|
||||
|
||||
extension PersistentDictionary.Values: CustomStringConvertible {
|
||||
extension ShareableDictionary.Values: CustomStringConvertible {
|
||||
// A textual representation of this instance.
|
||||
public var description: String {
|
||||
_arrayDescription(for: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension PersistentDictionary.Values: CustomDebugStringConvertible {
|
||||
extension ShareableDictionary.Values: CustomDebugStringConvertible {
|
||||
/// A textual representation of this instance, suitable for debugging.
|
||||
public var debugDescription: String {
|
||||
_arrayDescription(
|
||||
for: self,
|
||||
debug: true,
|
||||
typeName: "\(PersistentDictionary._debugTypeName()).Values")
|
||||
typeName: "\(ShareableDictionary._debugTypeName()).Values")
|
||||
}
|
||||
}
|
||||
|
||||
extension PersistentDictionary.Values: Sequence {
|
||||
extension ShareableDictionary.Values: Sequence {
|
||||
public typealias Element = Value
|
||||
|
||||
@frozen
|
||||
@@ -71,10 +71,10 @@ extension PersistentDictionary.Values: Sequence {
|
||||
public typealias Element = Value
|
||||
|
||||
@usableFromInline
|
||||
internal var _base: PersistentDictionary.Iterator
|
||||
internal var _base: ShareableDictionary.Iterator
|
||||
|
||||
@inlinable
|
||||
internal init(_base: PersistentDictionary.Iterator) {
|
||||
internal init(_base: ShareableDictionary.Iterator) {
|
||||
self._base = _base
|
||||
}
|
||||
|
||||
@@ -91,14 +91,14 @@ extension PersistentDictionary.Values: Sequence {
|
||||
}
|
||||
|
||||
#if swift(>=5.5)
|
||||
extension PersistentDictionary.Values.Iterator: Sendable
|
||||
extension ShareableDictionary.Values.Iterator: Sendable
|
||||
where Key: Sendable, Value: Sendable {}
|
||||
#endif
|
||||
|
||||
// Note: This cannot be a MutableCollection because its subscript setter
|
||||
// needs to invalidate indices.
|
||||
extension PersistentDictionary.Values: Collection {
|
||||
public typealias Index = PersistentDictionary.Index
|
||||
extension ShareableDictionary.Values: Collection {
|
||||
public typealias Index = ShareableDictionary.Index
|
||||
|
||||
@inlinable
|
||||
public var isEmpty: Bool { _base.isEmpty }
|
||||
@@ -152,10 +152,10 @@ extension PersistentDictionary.Values: Collection {
|
||||
}
|
||||
|
||||
#if false
|
||||
extension PersistentDictionary.Values: BidirectionalCollection {
|
||||
extension ShareableDictionary.Values: BidirectionalCollection {
|
||||
// Note: Let's not do this. `BidirectionalCollection` would imply that
|
||||
// the ordering of elements would be meaningful, which isn't true for
|
||||
// `PersistentDictionary.Values`.
|
||||
// `ShareableDictionary.Values`.
|
||||
@inlinable
|
||||
public func formIndex(before i: inout Index) {
|
||||
_base.formIndex(before: &i)
|
||||
+17
-17
@@ -13,13 +13,13 @@
|
||||
/// mutating shared copies and comparing different snapshots of the same
|
||||
/// collection.
|
||||
///
|
||||
/// `PersistentDictionary` has the same functionality as a standard
|
||||
/// `ShareableDictionary` has the same functionality as a standard
|
||||
/// `Dictionary`, and it largely implements the same APIs: both are hashed
|
||||
/// collection types with convenient and efficient ways to look up the value
|
||||
/// associated with a particular key, and both types are unordered, meaning that
|
||||
/// neither type provides any guarantees about the ordering of their items.
|
||||
///
|
||||
/// However, `PersistentDictionary` is optimizing specifically for use cases
|
||||
/// However, `ShareableDictionary` is optimizing specifically for use cases
|
||||
/// that need to mutate shared copies or to compare a dictionary value to one of
|
||||
/// its older snapshots.
|
||||
///
|
||||
@@ -27,10 +27,10 @@
|
||||
/// and it implements value semantics with all-or-nothing copy-on-write
|
||||
/// behavior: every time a shared copy of a dictionary is mutated, the mutation
|
||||
/// needs to make a full copy of the dictionary's storage.
|
||||
/// `PersistentDictionary` takes a different approach: it organizes its members
|
||||
/// `ShareableDictionary` takes a different approach: it organizes its members
|
||||
/// into a tree structure, the nodes of which can be freely shared across
|
||||
/// collection values. When mutating a shared copy of a dictionary value,
|
||||
/// `PersistentDictionary` is able to simply link the unchanged parts of the
|
||||
/// `ShareableDictionary` is able to simply link the unchanged parts of the
|
||||
/// tree directly into the result, saving both time and memory.
|
||||
///
|
||||
/// This structural sharing also makes it more efficient to compare mutated
|
||||
@@ -39,7 +39,7 @@
|
||||
/// typically be handled in constant time, leading to a dramatic performance
|
||||
/// boost when the two inputs are still largely unchanged:
|
||||
///
|
||||
/// var d = PersistentDictionary(
|
||||
/// var d = ShareableDictionary(
|
||||
/// uniqueKeysWithValues: (0 ..< 10_000).map { ($0, 2 * $0) })
|
||||
/// let copy = d
|
||||
/// d[20_000] = 42 // Expected to be an O(log(n)) operation
|
||||
@@ -47,7 +47,7 @@
|
||||
/// // `diff` now holds the single item 20_000.
|
||||
///
|
||||
/// The tree structure also eliminates the need to reserve capacity in advance:
|
||||
/// `PersistentDictionary` creates, destroys and resizes individual nodes as
|
||||
/// `ShareableDictionary` creates, destroys and resizes individual nodes as
|
||||
/// needed, always consuming just enough memory to store its contents. As of
|
||||
/// Swift 5.7, the standard collection types never shrink their storage, so
|
||||
/// temporary storage spikes can linger as unused but still allocated memory
|
||||
@@ -55,16 +55,16 @@
|
||||
///
|
||||
/// Of course, switching to a tree structure comes with some trade offs. In
|
||||
/// particular, inserting new items, removing existing ones, and iterating over
|
||||
/// a `PersistentDictionary` is expected to be a constant factor slower than a
|
||||
/// a `ShareableDictionary` is expected to be a constant factor slower than a
|
||||
/// standard `Dictionary` -- allocating/deallocating nodes isn't free, and
|
||||
/// navigating the tree structure requires more pointer dereferences than
|
||||
/// accessing a flat hash table. However the algorithmic improvements above
|
||||
/// usually more than make up for this, as long as the use case can make use of
|
||||
/// them.
|
||||
@frozen // Not really -- this package is not at all ABI stable
|
||||
public struct PersistentDictionary<Key: Hashable, Value> {
|
||||
public struct ShareableDictionary<Key: Hashable, Value> {
|
||||
@usableFromInline
|
||||
internal typealias _Node = PersistentCollections._Node<Key, Value>
|
||||
internal typealias _Node = ShareableHashedCollections._Node<Key, Value>
|
||||
|
||||
@usableFromInline
|
||||
internal typealias _UnsafeHandle = _Node.UnsafeHandle
|
||||
@@ -90,7 +90,7 @@ public struct PersistentDictionary<Key: Hashable, Value> {
|
||||
}
|
||||
}
|
||||
|
||||
extension PersistentDictionary {
|
||||
extension ShareableDictionary {
|
||||
/// Accesses the value associated with the given key for reading and writing.
|
||||
///
|
||||
/// This *key-based* subscript returns the value for the given key if the key
|
||||
@@ -100,7 +100,7 @@ extension PersistentDictionary {
|
||||
/// key found in the dictionary (`"Coral"`) and a key not found in the
|
||||
/// dictionary (`"Cerise"`).
|
||||
///
|
||||
/// var hues: PersistentDictionary = ["Heliotrope": 296, "Coral": 16, "Aquamarine": 156]
|
||||
/// var hues: ShareableDictionary = ["Heliotrope": 296, "Coral": 16, "Aquamarine": 156]
|
||||
/// print(hues["Coral"])
|
||||
/// // Prints "Optional(16)"
|
||||
/// print(hues["Cerise"])
|
||||
@@ -186,7 +186,7 @@ extension PersistentDictionary {
|
||||
/// example uses the subscript with a message to use in case an HTTP response
|
||||
/// code isn't recognized:
|
||||
///
|
||||
/// var responseMessages: PersistentDictionary = [
|
||||
/// var responseMessages: ShareableDictionary = [
|
||||
/// 200: "OK",
|
||||
/// 403: "Access forbidden",
|
||||
/// 404: "File not found",
|
||||
@@ -207,7 +207,7 @@ extension PersistentDictionary {
|
||||
/// of each letter in a string:
|
||||
///
|
||||
/// let message = "Hello, Elle!"
|
||||
/// var letterCounts: PersistentDictionary<Character, Int> = [:]
|
||||
/// var letterCounts: ShareableDictionary<Character, Int> = [:]
|
||||
/// for letter in message {
|
||||
/// letterCounts[letter, default: 0] += 1
|
||||
/// }
|
||||
@@ -298,7 +298,7 @@ extension PersistentDictionary {
|
||||
/// value of an existing key is updated, `updateValue(_:forKey:)` returns
|
||||
/// the original value.
|
||||
///
|
||||
/// var hues: PersistentDictionary = [
|
||||
/// var hues: ShareableDictionary = [
|
||||
/// "Heliotrope": 296,
|
||||
/// "Coral": 16,
|
||||
/// "Aquamarine": 156]
|
||||
@@ -383,7 +383,7 @@ extension PersistentDictionary {
|
||||
/// in a string:
|
||||
///
|
||||
/// let message = "Hello, Elle!"
|
||||
/// var letterCounts: PersistentDictionary<Character, Int> = [:]
|
||||
/// var letterCounts: ShareableDictionary<Character, Int> = [:]
|
||||
/// for letter in message {
|
||||
/// letterCounts.updateValue(forKey: letter) { count in
|
||||
/// if count == nil {
|
||||
@@ -434,7 +434,7 @@ extension PersistentDictionary {
|
||||
/// in a string:
|
||||
///
|
||||
/// let message = "Hello, Elle!"
|
||||
/// var letterCounts: PersistentDictionary<Character, Int> = [:]
|
||||
/// var letterCounts: ShareableDictionary<Character, Int> = [:]
|
||||
/// for letter in message {
|
||||
/// letterCounts.updateValue(forKey: letter, default: 0) { count in
|
||||
/// count += 1
|
||||
@@ -483,7 +483,7 @@ extension PersistentDictionary {
|
||||
/// If the key is found in the dictionary, this method returns the key's
|
||||
/// associated value, and invalidates all previously returned indices.
|
||||
///
|
||||
/// var hues: PersistentDictionary = [
|
||||
/// var hues: ShareableDictionary = [
|
||||
/// "Heliotrope": 296,
|
||||
/// "Coral": 16,
|
||||
/// "Aquamarine": 156]
|
||||
+22
-27
@@ -1,4 +1,4 @@
|
||||
# ``PersistentCollections/PersistentDictionary``
|
||||
# ``ShareableHashedCollections/ShareableDictionary``
|
||||
|
||||
<!-- Summary -->
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
### Collection Views
|
||||
|
||||
`PersistentDictionary` provides the customary dictionary views, `keys` and
|
||||
`ShareableDictionary` provides the customary dictionary views, `keys` and
|
||||
`values`. These are collection types that are projections of the dictionary
|
||||
itself, with elements that match only the keys or values of the dictionary,
|
||||
respectively. The `Keys` view is notable in that it provides operations for
|
||||
subtracting and intersecting the keys of two dictionaries, allowing for easy
|
||||
detection of inserted and removed items between two snapshots of the same
|
||||
dictionary. Because `PersistentDictionary` needs to invalidate indices on every
|
||||
dictionary. Because `ShareableDictionary` needs to invalidate indices on every
|
||||
mutation, its `Values` view is not a `MutableCollection`.
|
||||
|
||||
- ``Keys-swift.struct``
|
||||
@@ -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
|
||||
|
||||
- ``==(_:_:)``
|
||||
+55
-64
@@ -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``
|
||||
+3
-3
@@ -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``
|
||||
+2
-2
@@ -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
|
||||
+13
-13
@@ -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.
|
||||
+1
-1
@@ -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)
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
|
||||
import _CollectionsUtilities
|
||||
|
||||
extension PersistentSet {
|
||||
extension ShareableSet {
|
||||
/// True if consistency checking is enabled in the implementation of this
|
||||
/// type, false otherwise.
|
||||
///
|
||||
+3
-3
@@ -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)>"
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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.
|
||||
///
|
||||
+1
-1
@@ -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
|
||||
+2
-2
@@ -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.
|
||||
+26
-2
@@ -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) }
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension PersistentSet: Hashable {
|
||||
extension ShareableSet: Hashable {
|
||||
/// Hashes the essential components of this value by feeding them into the
|
||||
/// given hasher.
|
||||
///
|
||||
+1
-1
@@ -10,5 +10,5 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if swift(>=5.5)
|
||||
extension PersistentSet: @unchecked Sendable where Element: Sendable {}
|
||||
extension ShareableSet: @unchecked Sendable where Element: Sendable {}
|
||||
#endif
|
||||
+3
-3
@@ -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
|
||||
+2
-2
@@ -9,7 +9,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension PersistentSet {
|
||||
extension ShareableSet {
|
||||
/// Creates an empty set.
|
||||
///
|
||||
/// This initializer is equivalent to initializing with an empty array
|
||||
@@ -62,7 +62,7 @@ extension PersistentSet {
|
||||
/// - Complexity: O(*items.count*)
|
||||
@inlinable
|
||||
public init<Value>(
|
||||
_ item: __owned PersistentDictionary<Element, Value>.Keys
|
||||
_ item: __owned ShareableDictionary<Element, Value>.Keys
|
||||
) {
|
||||
self.init(_new: item._base._root.mapValues { _ in () })
|
||||
}
|
||||
+1
-1
@@ -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.
|
||||
///
|
||||
+7
-5
@@ -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<Value>(
|
||||
_ other: PersistentDictionary<Element, Value>.Keys
|
||||
_ other: ShareableDictionary<Element, Value>.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]`
|
||||
+7
-7
@@ -9,12 +9,12 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension PersistentSet {
|
||||
extension ShareableSet {
|
||||
/// Replace this set with the elements contained in this set or the given
|
||||
/// set, but not both.
|
||||
///
|
||||
/// var a: PersistentSet = [1, 2, 3, 4]
|
||||
/// let b: PersistentSet = [0, 2, 4, 6]
|
||||
/// var a: ShareableSet = [1, 2, 3, 4]
|
||||
/// let b: ShareableSet = [0, 2, 4, 6]
|
||||
/// a.formSymmetricDifference(b)
|
||||
/// // `a` is now some permutation of `[0, 1, 3, 6]`
|
||||
///
|
||||
@@ -33,8 +33,8 @@ extension PersistentSet {
|
||||
/// Replace this set with the elements contained in this set or the given
|
||||
/// keys view of a persistent dictionary, but not both.
|
||||
///
|
||||
/// var a: PersistentSet = [1, 2, 3, 4]
|
||||
/// let b: PersistentDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
|
||||
/// var a: ShareableSet = [1, 2, 3, 4]
|
||||
/// let b: ShareableDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
|
||||
/// a.formSymmetricDifference(b.keys)
|
||||
/// // `a` is now some permutation of `[0, 1, 3, 6]`
|
||||
///
|
||||
@@ -47,7 +47,7 @@ extension PersistentSet {
|
||||
/// parts of the input trees directly into the result.
|
||||
@inlinable
|
||||
public mutating func formSymmetricDifference<Value>(
|
||||
_ other: __owned PersistentDictionary<Element, Value>.Keys
|
||||
_ other: __owned ShareableDictionary<Element, Value>.Keys
|
||||
) {
|
||||
self = symmetricDifference(other)
|
||||
}
|
||||
@@ -55,7 +55,7 @@ extension PersistentSet {
|
||||
/// Replace this set with the elements contained in this set or the given
|
||||
/// sequence, but not both.
|
||||
///
|
||||
/// var a: PersistentSet = [1, 2, 3, 4]
|
||||
/// var a: ShareableSet = [1, 2, 3, 4]
|
||||
/// let b = [0, 2, 4, 6, 2, 4, 6]
|
||||
/// a.formSymmetricDifference(b)
|
||||
/// // `a` is now some permutation of `[0, 1, 3, 6]`
|
||||
+7
-7
@@ -9,11 +9,11 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension PersistentSet {
|
||||
extension ShareableSet {
|
||||
/// Adds the elements of the given set to this set.
|
||||
///
|
||||
/// var a: PersistentSet = [1, 2, 3, 4]
|
||||
/// let b: PersistentSet = [0, 2, 4, 6]
|
||||
/// var a: ShareableSet = [1, 2, 3, 4]
|
||||
/// let b: ShareableSet = [0, 2, 4, 6]
|
||||
/// a.formUnion(b)
|
||||
/// // `a` is now some permutation of `[0, 1, 2, 3, 4, 6]`
|
||||
///
|
||||
@@ -37,8 +37,8 @@ extension PersistentSet {
|
||||
/// Adds the elements of the given keys view of a persistent dictionary
|
||||
/// to this set.
|
||||
///
|
||||
/// var a: PersistentSet = [1, 2, 3, 4]
|
||||
/// let b: PersistentDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
|
||||
/// var a: ShareableSet = [1, 2, 3, 4]
|
||||
/// let b: ShareableDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
|
||||
/// a.formUnion(b.keys)
|
||||
/// // `a` is now some permutation of `[0, 1, 2, 3, 4, 6]`
|
||||
///
|
||||
@@ -56,14 +56,14 @@ extension PersistentSet {
|
||||
/// parts of the input trees directly into the result.
|
||||
@inlinable
|
||||
public mutating func formUnion<Value>(
|
||||
_ other: __owned PersistentDictionary<Element, Value>.Keys
|
||||
_ other: __owned ShareableDictionary<Element, Value>.Keys
|
||||
) {
|
||||
self = union(other)
|
||||
}
|
||||
|
||||
/// Adds the elements of the given sequence to this set.
|
||||
///
|
||||
/// var a: PersistentSet = [1, 2, 3, 4]
|
||||
/// var a: ShareableSet = [1, 2, 3, 4]
|
||||
/// let b = [0, 2, 4, 6, 0, 2]
|
||||
/// a.formUnion(b)
|
||||
/// // `a` is now some permutation of `[0, 1, 2, 3, 4, 6]`
|
||||
+8
-8
@@ -9,12 +9,12 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension PersistentSet {
|
||||
extension ShareableSet {
|
||||
/// Returns a new set with the elements that are common to both this set and
|
||||
/// the provided other one.
|
||||
///
|
||||
/// var a: PersistentSet = [1, 2, 3, 4]
|
||||
/// let b: PersistentSet = [0, 2, 4, 6]
|
||||
/// var a: ShareableSet = [1, 2, 3, 4]
|
||||
/// let b: ShareableSet = [0, 2, 4, 6]
|
||||
/// let c = a.intersection(b)
|
||||
/// // `c` is some permutation of `[2, 4]`
|
||||
///
|
||||
@@ -37,8 +37,8 @@ extension PersistentSet {
|
||||
/// Returns a new set with the elements that are common to both this set and
|
||||
/// the provided keys view of a persistent dictionary.
|
||||
///
|
||||
/// var a: PersistentSet = [1, 2, 3, 4]
|
||||
/// let b: PersistentDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
|
||||
/// var a: ShareableSet = [1, 2, 3, 4]
|
||||
/// let b: ShareableDictionary = [0: "a", 2: "b", 4: "c", 6: "d"]
|
||||
/// let c = a.intersection(b.keys)
|
||||
/// // `c` is some permutation of `[2, 4]`
|
||||
///
|
||||
@@ -55,14 +55,14 @@ extension PersistentSet {
|
||||
/// parts of the input trees directly into the result.
|
||||
@inlinable @inline(__always)
|
||||
public func intersection<Value>(
|
||||
_ other: PersistentDictionary<Element, Value>.Keys
|
||||
_ other: ShareableDictionary<Element, Value>.Keys
|
||||
) -> Self {
|
||||
_intersection(other._base._root)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
internal func _intersection<V>(
|
||||
_ other: PersistentCollections._Node<Element, V>
|
||||
_ other: ShareableHashedCollections._Node<Element, V>
|
||||
) -> Self {
|
||||
guard let r = _root.intersection(.top, other) else { return self }
|
||||
return Self(_new: r)
|
||||
@@ -71,7 +71,7 @@ extension PersistentSet {
|
||||
/// Returns a new set with the elements that are common to both this set and
|
||||
/// the provided sequence.
|
||||
///
|
||||
/// var a: PersistentSet = [1, 2, 3, 4]
|
||||
/// var a: ShareableSet = [1, 2, 3, 4]
|
||||
/// let b = [0, 2, 4, 6]
|
||||
/// let c = a.intersection(b)
|
||||
/// // `c` is some permutation of `[2, 4]`
|
||||
Loaded 100 of 125 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user