Skip to content

Commit 6b0db5e

Browse files
author
Abduqodiri Qurbonzoda
committed
Get rid of polymorphism in set TrieNode
1 parent 24e973a commit 6b0db5e

File tree

7 files changed

+158
-184
lines changed

7 files changed

+158
-184
lines changed

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableMap/TrieNode.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ internal class TrieNode<K, V>(
8888
private set
8989

9090
internal fun isCollision(): Boolean {
91-
return dataMap == 0 && nodeMap == 0 && buffer.size > 0
91+
return dataMap == 0 && nodeMap == 0 && buffer.isNotEmpty()
9292
}
9393

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

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableSet/PersistentHashSet.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal class PersistentHashSet<E>(internal val node: TrieNode<E>,
6363
}
6464

6565
internal companion object {
66-
private val EMPTY = PersistentHashSet(CompactTrieNode.EMPTY, 0)
66+
private val EMPTY = PersistentHashSet(TrieNode.EMPTY, 0)
6767
internal fun <E> emptyOf(): PersistentSet<E> = PersistentHashSet.EMPTY
6868
}
6969
}

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableSet/PersistentHashSetBuilder.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ internal class PersistentHashSetBuilder<E>(private var set: PersistentHashSet<E>
5757
override fun remove(element: E): Boolean {
5858
val size = this.size
5959
@Suppress("UNCHECKED_CAST")
60-
node = node.mutableRemove(element.hashCode(), element, 0, this) ?: CompactTrieNode.EMPTY as TrieNode<E>
60+
node = node.mutableRemove(element.hashCode(), element, 0, this) ?: TrieNode.EMPTY as TrieNode<E>
6161
return size != this.size
6262
}
6363

6464
override fun clear() {
6565
@Suppress("UNCHECKED_CAST")
66-
node = CompactTrieNode.EMPTY as TrieNode<E>
66+
node = TrieNode.EMPTY as TrieNode<E>
6767
size = 0
6868
}
6969

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableSet/PersistentHashSetIterator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ internal open class PersistentHashSetIterator<E>(node: TrieNode<E>) : Iterator<E
8585
}
8686

8787
internal class TrieNodeIterator<out E> {
88-
private var buffer = CompactTrieNode.EMPTY.buffer
88+
private var buffer = TrieNode.EMPTY.buffer
8989
private var index = 0
9090

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

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableSet/PersistentHashSetMutableIterator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal class PersistentHashSetMutableIterator<E>(private val builder: Persiste
5656
}
5757

5858
val position = 1 shl ((hashCode shr (pathIndex * LOG_MAX_BRANCHING_FACTOR)) and MAX_BRANCHING_FACTOR_MINUS_ONE)
59-
val index = Integer.bitCount((node as CompactTrieNode<*>).bitmap and (position - 1))
59+
val index = Integer.bitCount(node.bitmap and (position - 1))
6060

6161
path[pathIndex].reset(node.buffer, index)
6262

0 commit comments

Comments
 (0)