mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +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.
48 lines
1.2 KiB
Swift
48 lines
1.2 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
extension PersistentDictionary: Collection {
|
|
public struct Index: Comparable {
|
|
internal let _value: Int
|
|
|
|
internal init(_value: Int) {
|
|
self._value = _value
|
|
}
|
|
|
|
public static func < (lhs: Self, rhs: Self) -> Bool {
|
|
lhs._value < rhs._value
|
|
}
|
|
}
|
|
|
|
///
|
|
/// Manipulating Indices
|
|
///
|
|
|
|
public var startIndex: Index { Index(_value: 0) }
|
|
|
|
public var endIndex: Index { Index(_value: count) }
|
|
|
|
public func index(after i: Index) -> Index {
|
|
Index(_value: i._value + 1)
|
|
}
|
|
|
|
/// Returns the index for the given key.
|
|
public func index(forKey key: Key) -> Index? {
|
|
rootNode.index(forKey: key, _HashPath(key), 0)
|
|
}
|
|
|
|
/// Accesses the key-value pair at the specified position.
|
|
public subscript(position: Index) -> Element {
|
|
rootNode.item(position: position._value)
|
|
}
|
|
}
|
|
|