diff --git a/Sources/Capsule/HashMap+Equatable.swift b/Sources/Capsule/HashMap+Equatable.swift index a88c19ae..77e88f84 100644 --- a/Sources/Capsule/HashMap+Equatable.swift +++ b/Sources/Capsule/HashMap+Equatable.swift @@ -13,7 +13,6 @@ extension HashMap: Equatable where Value: Equatable { public static func == (lhs: HashMap, rhs: HashMap) -> Bool { lhs.cachedSize == rhs.cachedSize && - lhs.cachedKeySetHashCode == rhs.cachedKeySetHashCode && (lhs.rootNode === rhs.rootNode || lhs.rootNode == rhs.rootNode) } } diff --git a/Sources/Capsule/HashMap+Hashable.swift b/Sources/Capsule/HashMap+Hashable.swift index ee34e098..670220e6 100644 --- a/Sources/Capsule/HashMap+Hashable.swift +++ b/Sources/Capsule/HashMap+Hashable.swift @@ -9,7 +9,6 @@ // //===----------------------------------------------------------------------===// -// TODO settle on (commutative) hash semantics that is reconcilable with `cachedKeySetHashCode` extension HashMap: Hashable where Value: Hashable { public func hash(into hasher: inout Hasher) { var commutativeHash = 0 diff --git a/Sources/Capsule/HashMap.swift b/Sources/Capsule/HashMap.swift index 16a11f20..660e04bc 100644 --- a/Sources/Capsule/HashMap.swift +++ b/Sources/Capsule/HashMap.swift @@ -11,21 +11,19 @@ public struct HashMap where Key: Hashable { var rootNode: BitmapIndexedMapNode - var cachedKeySetHashCode: Int var cachedSize: Int - fileprivate init(_ rootNode: BitmapIndexedMapNode, _ cachedKeySetHashCode: Int, _ cachedSize: Int) { + fileprivate init(_ rootNode: BitmapIndexedMapNode, _ cachedSize: Int) { self.rootNode = rootNode - self.cachedKeySetHashCode = cachedKeySetHashCode self.cachedSize = cachedSize } public init() { - self.init(BitmapIndexedMapNode(), 0, 0) + self.init(BitmapIndexedMapNode(), 0) } public init(_ map: HashMap) { - self.init(map.rootNode, map.cachedKeySetHashCode, map.cachedSize) + self.init(map.rootNode, map.cachedSize) } // TODO consider removing `unchecked` version, since it's only referenced from within the test suite @@ -131,11 +129,9 @@ public struct HashMap where Key: Hashable { if effect.modified { if effect.replacedValue { self.rootNode = newRootNode - // self.cachedKeySetHashCode = cachedKeySetHashCode // self.cachedSize = cachedSize } else { self.rootNode = newRootNode - self.cachedKeySetHashCode = cachedKeySetHashCode ^ keyHash self.cachedSize = cachedSize + 1 } } @@ -149,9 +145,9 @@ public struct HashMap where Key: Hashable { if effect.modified { if effect.replacedValue { - return Self(newRootNode, cachedKeySetHashCode, cachedSize) + return Self(newRootNode, cachedSize) } else { - return Self(newRootNode, cachedKeySetHashCode ^ keyHash, cachedSize + 1) + return Self(newRootNode, cachedSize + 1) } } else { return self } } @@ -177,7 +173,6 @@ public struct HashMap where Key: Hashable { if effect.modified { self.rootNode = newRootNode - self.cachedKeySetHashCode = cachedKeySetHashCode ^ keyHash self.cachedSize = cachedSize - 1 } } @@ -189,7 +184,7 @@ public struct HashMap where Key: Hashable { let newRootNode = rootNode.removeOrRemoving(false, key, keyHash, 0, &effect) if effect.modified { - return Self(newRootNode, cachedKeySetHashCode ^ keyHash, cachedSize - 1) + return Self(newRootNode, cachedSize - 1) } else { return self } }