HashTreeCollections: Qualify internal type names with “Hash”

This makes them unique throughout the package, allowing this code to be built as a single, huge module.
This commit is contained in:
Karoy Lorentey committed 2023-03-21 16:37:22 -07:00
1 parent 9151af9fa8
commit 424c8ece98
56 files changed
+653 -645

No files matched your search

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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 _HashNode {
@inlinable
internal func compactMapValues<T>(
_ level: _HashLevel,
_ transform: (Value) throws -> T?
) rethrows -> _HashNode<Key, T>.Builder {
return try self.read {
var result: _HashNode<Key, T>.Builder = .empty(level)
if isCollisionNode {
let items = $0.reverseItems
for i in items.indices {
if let v = try transform(items[i].value) {
result.addNewCollision(level, (items[i].key, v), $0.collisionHash)
}
}
return result
}
for (bucket, slot) in $0.itemMap {
let p = $0.itemPtr(at: slot)
if let v = try transform(p.pointee.value) {
result.addNewItem(level, (p.pointee.key, v), at: bucket)
}
}
for (bucket, slot) in $0.childMap {
let branch = try $0[child: slot]
.compactMapValues(level.descend(), transform)
result.addNewChildBranch(level, branch, at: bucket)
}
return result
}
}
}