@@ -100,6 +100,13 @@ Memory layout:
100
100
import Swift
101
101
import SwiftShims
102
102
103
+ // This prototype is only partially implemented, and it relies on specific hash
104
+ // values. To keep it working, define an alternative hashing interface emulating
105
+ // pre-SE-0206 Hashable.
106
+ protocol LegacyHashable: Equatable {
107
+ var legacyHashValue: Int { get }
108
+ }
109
+
103
110
//
104
111
// Standard library extras
105
112
//
@@ -252,7 +259,7 @@ struct _PVSparseVectorNodeLayoutParameters {
252
259
var keyCount: Int
253
260
}
254
261
255
- struct _PVSparseVectorNodePointer<Key : Hashable , Value>
262
+ struct _PVSparseVectorNodePointer<Key : LegacyHashable , Value>
256
263
: CustomReflectable {
257
264
typealias _Self = _PVSparseVectorNodePointer
258
265
@@ -917,7 +924,7 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
917
924
}
918
925
}
919
926
920
- struct _PVArrayNodePointer<Key : Hashable , Value>
927
+ struct _PVArrayNodePointer<Key : LegacyHashable , Value>
921
928
: CustomReflectable {
922
929
923
930
typealias _Self = _PVArrayNodePointer
@@ -1158,7 +1165,7 @@ struct _PVCollisionNodePointerLayoutParameters {
1158
1165
var keyCount: Int
1159
1166
}
1160
1167
1161
- struct _PVCollisionNodePointer<Key : Hashable , Value>
1168
+ struct _PVCollisionNodePointer<Key : LegacyHashable , Value>
1162
1169
: CustomReflectable {
1163
1170
1164
1171
typealias _Self = _PVCollisionNodePointer
@@ -1461,7 +1468,7 @@ struct _PVCollisionNodePointer<Key : Hashable, Value>
1461
1468
}
1462
1469
}
1463
1470
1464
- struct _PVAnyNodePointer<Key : Hashable , Value>
1471
+ struct _PVAnyNodePointer<Key : LegacyHashable , Value>
1465
1472
: CustomReflectable, Equatable {
1466
1473
1467
1474
let taggedPointer: UnsafeMutableRawPointer
@@ -1654,7 +1661,8 @@ func == <Key, Value> (
1654
1661
return lhs.taggedPointer == rhs.taggedPointer
1655
1662
}
1656
1663
1657
- final internal class _NativePVDictionaryStorageRef<Key : Hashable, Value> {
1664
+ final internal
1665
+ class _NativePVDictionaryStorageRef<Key : LegacyHashable, Value> {
1658
1666
1659
1667
var _rootNode: _PVAnyNodePointer<Key, Value>?
1660
1668
var _count: Int
@@ -1675,7 +1683,7 @@ final internal class _NativePVDictionaryStorageRef<Key : Hashable, Value> {
1675
1683
}
1676
1684
}
1677
1685
1678
- struct _NativePVDictionaryStorage<Key : Hashable , Value> {
1686
+ struct _NativePVDictionaryStorage<Key : LegacyHashable , Value> {
1679
1687
var _storageRef: _NativePVDictionaryStorageRef<Key, Value>
1680
1688
1681
1689
var _rootNode: _PVAnyNodePointer<Key, Value>? {
@@ -1715,13 +1723,13 @@ struct _NativePVDictionaryStorage<Key : Hashable, Value> {
1715
1723
1716
1724
func assertingGet(key: Key) -> Value {
1717
1725
let valuePointer = _rootNode!.unsafeMaybeGet(
1718
- key: key, hashValue: key.hashValue , depth: 0)
1726
+ key: key, hashValue: key.legacyHashValue , depth: 0)
1719
1727
return valuePointer!.pointee
1720
1728
}
1721
1729
1722
1730
func maybeGet(key: Key) -> Value? {
1723
1731
let valuePointer = _rootNode?.unsafeMaybeGet(
1724
- key: key, hashValue: key.hashValue , depth: 0)
1732
+ key: key, hashValue: key.legacyHashValue , depth: 0)
1725
1733
return valuePointer.map { $0.pointee }
1726
1734
}
1727
1735
@@ -1748,7 +1756,7 @@ struct _NativePVDictionaryStorage<Key : Hashable, Value> {
1748
1756
}
1749
1757
1750
1758
mutating func updateValue(_ value: Value, forKey key: Key) -> Value? {
1751
- let hashValue = key.hashValue
1759
+ let hashValue = key.legacyHashValue
1752
1760
guard let oldRootNode = _rootNode else {
1753
1761
let layout = _PVSparseVectorNodeLayoutParameters(
1754
1762
childNodeCount: 0,
@@ -1787,7 +1795,7 @@ struct _NativePVDictionaryStorage<Key : Hashable, Value> {
1787
1795
guard let oldRootNode = _rootNode else {
1788
1796
return nil
1789
1797
}
1790
- let hashValue = key.hashValue
1798
+ let hashValue = key.legacyHashValue
1791
1799
let isUnique = isKnownUniquelyReferenced(&_storageRef)
1792
1800
let (oldValue, newRootNode) = oldRootNode.removeValue(
1793
1801
forKey: key,
@@ -1858,6 +1866,12 @@ Bitmap.test("setBitIndices") {
1858
1866
expectEqualSequence([ 0, 4, 5, 7, 31 ], Array(bm.setBitIndices))
1859
1867
}
1860
1868
1869
+ extension MinimalHashableValue: LegacyHashable {
1870
+ var legacyHashValue: Int {
1871
+ return self.value % 10000
1872
+ }
1873
+ }
1874
+
1861
1875
var PersistentVectorTests = TestSuite("PersistentVector")
1862
1876
1863
1877
PersistentVectorTests.test("sizeof") {
@@ -1993,10 +2007,6 @@ func testDictionary(
1993
2007
print("---------------------------------------")
1994
2008
}
1995
2009
1996
- MinimalHashableValue.hashValueImpl.value = {
1997
- return $0 % 10000
1998
- }
1999
-
2000
2010
typealias MyDictionary = _NativePVDictionaryStorage<
2001
2011
MinimalHashableValue, OpaqueValue<Int>
2002
2012
>
0 commit comments