Continue applying refactors and optimizations.

Key Changes:
 - _BTree.init() dynamically computes capacity from stride
 - _BTree.UnsafePath uses Unmanaged +0 references.

Minor Changes:
 - Fix _BTree.Iterator bug on single-leaf trees.
This commit is contained in:
Vihan Bhargava committed 2021-08-09 19:13:50 -07:00
1 parent 8de0b4ff7a
commit 98f278545d
25 files changed
+195 -179

No files matched your search

@@ -21,7 +21,7 @@ extension SortedDictionary {
self.init()
for (key, value) in keysAndValues {
self._root.setAnyValue(value, forKey: key)
self._root.updateAnyValue(value, forKey: key)
}
}
@@ -40,7 +40,7 @@ extension SortedDictionary {
// in debug v production v unchecked builds?
for (key, value) in keysAndValues {
self._root.setAnyValue(value, forKey: key)
self._root.updateAnyValue(value, forKey: key)
}
}
@@ -77,9 +77,9 @@ extension SortedDictionary {
// TODO: optimize to avoid CoW copying the array
if var group = self._root.findAnyValue(forKey: key) {
group.append(value)
self._root.setAnyValue(group, forKey: key)
self._root.updateAnyValue(group, forKey: key)
} else {
self._root.setAnyValue([value], forKey: key)
self._root.updateAnyValue([value], forKey: key)
}
}
}
@@ -33,7 +33,7 @@ extension SortedDictionary {
set {
if let newValue = newValue {
self._root.setAnyValue(newValue, forKey: key)
self._root.updateAnyValue(newValue, forKey: key)
} else {
self._root.removeAnyElement(forKey: key)
}
@@ -95,7 +95,7 @@ extension SortedDictionary {
@inlinable
@discardableResult
public mutating func updateValue(_ value: Value, forKey key: Key) -> Value? {
self._root.setAnyValue(value, forKey: key)?.value
self._root.updateAnyValue(value, forKey: key)?.value
}
}