1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2022 - 2024 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
//
//===----------------------------------------------------------------------===//
#if !COLLECTIONS_SINGLE_MODULE
import InternalCollectionsUtilities
#endif
extension _HashNode {
@usableFromInline
internal func dump(
iterationOrder: Bool = false,
limit: Int = Int.max,
firstPrefix: String = "",
restPrefix: String = "",
depth: Int = 0
) {
read {
$0.dump(
iterationOrder: iterationOrder,
limit: limit,
extra: "count: \(count), ",
firstPrefix: firstPrefix,
restPrefix: restPrefix,
depth: depth)
}
}
}
extension _HashNode.Storage {
@usableFromInline
final internal func dump(iterationOrder: Bool = false) {
UnsafeHandle.read(self) { $0.dump(iterationOrder: iterationOrder) }
}
}
extension _HashNode {
internal static func _itemString(for item: Element) -> String {
let hash = _Hash(item.key).description
return "hash: \(hash), key: \(item.key), value: \(item.value)"
}
}
extension _HashNode.UnsafeHandle {
internal func _itemString(at slot: _HashSlot) -> String {
let item = self[item: slot]
return _HashNode._itemString(for: item)
}
@usableFromInline
internal func dump(
iterationOrder: Bool = false,
limit: Int = .max,
extra: String = "",
firstPrefix: String = "",
restPrefix: String = "",
depth: Int = 0
) {
var firstPrefix = firstPrefix
var restPrefix = restPrefix
if iterationOrder && depth == 0 {
firstPrefix += "@"
restPrefix += "@"
}
if iterationOrder {
firstPrefix += " "
}
print("""
\(firstPrefix)\(isCollisionNode ? "CollisionNode" : "Node")(\
at: \(_addressString(for: _header)), \
\(isCollisionNode ? "hash: \(collisionHash), " : "")\
\(extra)\
byteCapacity: \(byteCapacity), \
freeBytes: \(bytesFree))
""")
guard limit > 0 else { return }
if iterationOrder {
for slot in stride(from: .zero, to: itemsEndSlot, by: 1) {
print(" \(restPrefix)[\(slot)] \(_itemString(at: slot))")
}
for slot in stride(from: .zero, to: childrenEndSlot, by: 1) {
self[child: slot].dump(
iterationOrder: true,
limit: limit - 1,
firstPrefix: " \(restPrefix).\(slot)",
restPrefix: " \(restPrefix).\(slot)",
depth: depth + 1)
}
}
else if isCollisionNode {
for slot in stride(from: .zero, to: itemsEndSlot, by: 1) {
print("\(restPrefix)[\(slot)] \(_itemString(at: slot))")
}
} else {
var itemSlot: _HashSlot = .zero
var childSlot: _HashSlot = .zero
for b in 0 ..< UInt(_Bitmap.capacity) {
let bucket = _Bucket(b)
let bucketStr = "#\(String(b, radix: _Bitmap.capacity, uppercase: true))"
if itemMap.contains(bucket) {
print("\(restPrefix) \(bucketStr) \(_itemString(at: itemSlot))")
itemSlot = itemSlot.next()
} else if childMap.contains(bucket) {
self[child: childSlot].dump(
iterationOrder: false,
limit: limit - 1,
firstPrefix: "\(restPrefix) \(bucketStr) ",
restPrefix: "\(restPrefix) ",
depth: depth + 1)
childSlot = childSlot.next()
}
}
}
}
}
|