mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
These provide nicer tools for slicing up hash values and dealing with node bitmaps. _Bucket is a logical entry in the hash table inside a node. _Bitmap is a set of bucket values, represented by a bitset. _HashPath facilitates slicing up a hash value into a series of bucket values. _HashValue represents a hash value. This is still just mostly superficial refactoring, with little to no functional changes.
36 lines
1.0 KiB
Swift
36 lines
1.0 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// Identifies an entry in the hash table inside a node.
|
|
/// (Internally, a number between 0 and 31.)
|
|
internal struct _Bucket {
|
|
var value: UInt
|
|
|
|
init(_ value: UInt) { self.value = value }
|
|
|
|
static var bitWidth: Int { _Bitmap.capacity.trailingZeroBitCount }
|
|
static var bitMask: UInt { UInt(bitPattern: _Bitmap.capacity) &- 1 }
|
|
}
|
|
|
|
extension _Bucket: Equatable {
|
|
@inline(__always)
|
|
internal static func ==(left: Self, right: Self) -> Bool {
|
|
left.value == right.value
|
|
}
|
|
}
|
|
|
|
extension _Bucket: Comparable {
|
|
@inline(__always)
|
|
internal static func <(left: Self, right: Self) -> Bool {
|
|
left.value < right.value
|
|
}
|
|
}
|