Skip to content

Commit 44f49db

Browse files
author
Abduqodiri Qurbonzoda
committed
Get rid of polymorphism in set TrieNode
1 parent 4b94413 commit 44f49db

File tree

7 files changed

+157
-184
lines changed

7 files changed

+157
-184
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ internal class TrieNode<K, V>(
7777
private set
7878

7979
internal fun isCollision(): Boolean {
80-
return dataMap == 0 && nodeMap == 0 && buffer.size > 0
80+
return dataMap == 0 && nodeMap == 0 && buffer.isNotEmpty()
8181
}
8282

8383
/** Returns number of entries stored in this trie node (not counting subnodes) */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal class PersistentHashSet<E>(internal val node: TrieNode<E>,
5252
}
5353

5454
internal companion object {
55-
private val EMPTY = PersistentHashSet(CompactTrieNode.EMPTY, 0)
55+
private val EMPTY = PersistentHashSet(TrieNode.EMPTY, 0)
5656
internal fun <E> emptyOf(): PersistentSet<E> = PersistentHashSet.EMPTY
5757
}
5858
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ internal class PersistentHashSetBuilder<E>(private var set: PersistentHashSet<E>
4646
override fun remove(element: E): Boolean {
4747
val size = this.size
4848
@Suppress("UNCHECKED_CAST")
49-
node = node.mutableRemove(element.hashCode(), element, 0, this) ?: CompactTrieNode.EMPTY as TrieNode<E>
49+
node = node.mutableRemove(element.hashCode(), element, 0, this) ?: TrieNode.EMPTY as TrieNode<E>
5050
return size != this.size
5151
}
5252

5353
override fun clear() {
5454
@Suppress("UNCHECKED_CAST")
55-
node = CompactTrieNode.EMPTY as TrieNode<E>
55+
node = TrieNode.EMPTY as TrieNode<E>
5656
size = 0
5757
}
5858

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal open class PersistentHashSetIterator<E>(node: TrieNode<E>) : Iterator<E
7878
}
7979

8080
internal class TrieNodeIterator<out E> {
81-
private var buffer = CompactTrieNode.EMPTY.buffer
81+
private var buffer = TrieNode.EMPTY.buffer
8282
private var index = 0
8383

8484
fun reset(buffer: Array<Any?>, index: Int = 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal class PersistentHashSetMutableIterator<E>(private val builder: Persiste
4848

4949
val position = 1 shl ((hashCode shr (pathIndex * LOG_MAX_BRANCHING_FACTOR)) and MAX_BRANCHING_FACTOR_MINUS_ONE)
5050
@UseExperimental(ExperimentalStdlibApi::class)
51-
val index = ((node as CompactTrieNode<*>).bitmap and (position - 1)).countOneBits()
51+
val index = (node.bitmap and (position - 1)).countOneBits()
5252

5353
path[pathIndex].reset(node.buffer, index)
5454

0 commit comments

Comments
 (0)