mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
[BasicContainers] Hashed containers: Add Equatable/Hashable conformances and related methods
This commit is contained in:
19 files changed
+445
-14
No files matched your search
@@ -46,10 +46,35 @@ public protocol GeneralizedHashable: GeneralizedEquatable, ~Copyable, ~Escapable
|
||||
/// of this instance.
|
||||
func hash(into hasher: inout Hasher)
|
||||
|
||||
// Raw top-level hashing interface. Some standard library types (mostly
|
||||
// primitives) specialize this to eliminate small resiliency overheads. (This
|
||||
// only matters for tiny keys.)
|
||||
func _rawHashValue(seed: Int) -> Int
|
||||
/// The temporary substitute to `Hashable._rawHashValue(seed:)`, the raw
|
||||
/// top-level hashing interface. Some standard library types (mostly
|
||||
/// primitives) specialize this to eliminate small resiliency overheads. (This
|
||||
/// only matters for tiny keys.)
|
||||
///
|
||||
/// We avoid using the stdlib name as the stdlib's default implementation is
|
||||
/// overwhelmingly preferable but it isn't (easily) reimplementable outside
|
||||
/// of the stdlib.
|
||||
///
|
||||
/// This will be replaced by the actual `Hashable` method when its
|
||||
/// generalization ships.
|
||||
func _rawHashValue_temp(seed: Int) -> Int
|
||||
}
|
||||
|
||||
extension GeneralizedHashable where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
public func _rawHashValue_temp(seed: Int) -> Int {
|
||||
var hasher = Hasher()
|
||||
hasher.combine(seed)
|
||||
self.hash(into: &hasher)
|
||||
return hasher.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
extension GeneralizedHashable where Self: Hashable {
|
||||
@inlinable
|
||||
public func _rawHashValue_temp(seed: Int) -> Int {
|
||||
_rawHashValue(seed: seed)
|
||||
}
|
||||
}
|
||||
|
||||
extension GeneralizedHashable where Self: ~Copyable & ~Escapable {
|
||||
@@ -60,7 +85,7 @@ extension GeneralizedHashable where Self: ~Copyable & ~Escapable {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public var hashValue: Int {
|
||||
_rawHashValue(seed: 0)
|
||||
_rawHashValue_temp(seed: 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -223,4 +223,15 @@ extension _HTable {
|
||||
self._maxProbeLength = 0
|
||||
}
|
||||
}
|
||||
|
||||
extension _HTable {
|
||||
@usableFromInline
|
||||
package func isTriviallyIdentical(to other: borrowing Self) -> Bool {
|
||||
self._count == other._count
|
||||
&& self._capacity == other._capacity
|
||||
&& self._bitmap == other._bitmap
|
||||
&& self._maxProbeLength == other._maxProbeLength
|
||||
&& self.scale == other.scale
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user