Skip to content

Commit a5f78bc

Browse files
Abduqodiri Qurbonzodaqurbonzoda
authored andcommitted
Small refactoring in Set builder iterator
1 parent 9965918 commit a5f78bc

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

core/commonMain/src/implementations/immutableSet/PersistentHashSetMutableIterator.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ internal class PersistentHashSetMutableIterator<E>(private val builder: Persiste
2626
if (hasNext()) {
2727
val currentElement = currentElement()
2828

29-
assert(builder.remove(lastIteratedElement))
29+
builder.remove(lastIteratedElement)
3030
resetPath(currentElement.hashCode(), builder.node, currentElement, 0)
3131
} else {
32-
assert(builder.remove(lastIteratedElement))
32+
builder.remove(lastIteratedElement)
3333
}
3434

3535
lastIteratedElement = null
@@ -46,9 +46,8 @@ internal class PersistentHashSetMutableIterator<E>(private val builder: Persiste
4646
return
4747
}
4848

49-
val position = 1 shl ((hashCode shr (pathIndex * LOG_MAX_BRANCHING_FACTOR)) and MAX_BRANCHING_FACTOR_MINUS_ONE)
50-
@UseExperimental(ExperimentalStdlibApi::class)
51-
val index = (node.bitmap and (position - 1)).countOneBits()
49+
val position = 1 shl indexSegment(hashCode, pathIndex * LOG_MAX_BRANCHING_FACTOR)
50+
val index = node.indexOfCellAt(position)
5251

5352
path[pathIndex].reset(node.buffer, index)
5453

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal class TrieNode<E>(
5454
}
5555

5656
@UseExperimental(ExperimentalStdlibApi::class)
57-
private fun indexOfCellAt(positionMask: Int): Int {
57+
internal fun indexOfCellAt(positionMask: Int): Int {
5858
return (bitmap and (positionMask - 1)).countOneBits()
5959
}
6060

0 commit comments

Comments
 (0)