Skip to content

Commit d14c192

Browse files
author
Abduqodiri Qurbonzoda
committed
Add map TrieNode structure tests
1 parent 3eb424c commit d14c192

File tree

2 files changed

+472
-0
lines changed

2 files changed

+472
-0
lines changed

core/commonMain/src/implementations/immutableMap/TrieNode.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,33 @@ internal class TrieNode<K, V>(
654654
return this
655655
}
656656

657+
// For testing trie structure
658+
internal fun accept(visitor: (node: TrieNode<K, V>, shift: Int, hash: Int, dataMap: Int, nodeMap: Int) -> Unit) {
659+
accept(visitor, 0, 0)
660+
}
661+
662+
@UseExperimental(ExperimentalStdlibApi::class)
663+
private fun accept(
664+
visitor: (node: TrieNode<K, V>, shift: Int, hash: Int, dataMap: Int, nodeMap: Int) -> Unit,
665+
hash: Int,
666+
shift: Int
667+
) {
668+
visitor(this, shift, hash, dataMap, nodeMap)
669+
670+
var nodePositions = nodeMap
671+
while (nodePositions != 0) {
672+
val mask = nodePositions.takeLowestOneBit()
673+
// assert(hasNodeAt(mask))
674+
675+
val hashSegment = mask.countTrailingZeroBits()
676+
677+
val childNode = nodeAtIndex(nodeIndex(mask))
678+
childNode.accept(visitor, hash + (hashSegment shl shift), shift + LOG_MAX_BRANCHING_FACTOR)
679+
680+
nodePositions -= mask
681+
}
682+
}
683+
657684
internal companion object {
658685
internal val EMPTY = TrieNode<Nothing, Nothing>(0, 0, emptyArray())
659686
}

0 commit comments

Comments
 (0)