@@ -76,7 +76,8 @@ internal class TrieNode<K, V>(
76
76
internal var buffer: Array <Any ?> = buffer
77
77
private set
78
78
79
- internal fun isCollision (): Boolean {
79
+ @Suppress(" NOTHING_TO_INLINE" )
80
+ internal inline fun isCollision (): Boolean {
80
81
return dataMap == 0 && nodeMap == 0 && buffer.isNotEmpty()
81
82
}
82
83
@@ -487,10 +488,6 @@ internal class TrieNode<K, V>(
487
488
}
488
489
489
490
fun containsKey (keyHash : Int , key : K , shift : Int ): Boolean {
490
- if (isCollision()) {
491
- return collisionContainsKey(key)
492
- }
493
-
494
491
val keyPositionMask = 1 shl indexSegment(keyHash, shift)
495
492
496
493
if (hasEntryAt(keyPositionMask)) { // key is directly in buffer
@@ -501,15 +498,15 @@ internal class TrieNode<K, V>(
501
498
return targetNode.containsKey(keyHash, key, shift + LOG_MAX_BRANCHING_FACTOR )
502
499
}
503
500
501
+ if (isCollision()) {
502
+ return collisionContainsKey(key)
503
+ }
504
+
504
505
// key is absent
505
506
return false
506
507
}
507
508
508
509
fun get (keyHash : Int , key : K , shift : Int ): V ? {
509
- if (isCollision()) {
510
- return collisionGet(key)
511
- }
512
-
513
510
val keyPositionMask = 1 shl indexSegment(keyHash, shift)
514
511
515
512
if (hasEntryAt(keyPositionMask)) { // key is directly in buffer
@@ -525,15 +522,15 @@ internal class TrieNode<K, V>(
525
522
return targetNode.get(keyHash, key, shift + LOG_MAX_BRANCHING_FACTOR )
526
523
}
527
524
525
+ if (isCollision()) {
526
+ return collisionGet(key)
527
+ }
528
+
528
529
// key is absent
529
530
return null
530
531
}
531
532
532
533
fun put (keyHash : Int , key : K , value : @UnsafeVariance V , shift : Int ): ModificationResult <K , V >? {
533
- if (isCollision()) {
534
- return collisionPut(key, value, shift)
535
- }
536
-
537
534
val keyPositionMask = 1 shl indexSegment(keyHash, shift)
538
535
539
536
if (hasEntryAt(keyPositionMask)) { // key is directly in buffer
@@ -554,15 +551,15 @@ internal class TrieNode<K, V>(
554
551
return putResult.replaceNode { node -> updateNodeAtIndex(nodeIndex, node) }
555
552
}
556
553
554
+ if (isCollision()) {
555
+ return collisionPut(key, value, shift)
556
+ }
557
+
557
558
// no entry at this key hash segment
558
559
return insertEntryAt(keyPositionMask, key, value).asInsertResult()
559
560
}
560
561
561
562
fun mutablePut (keyHash : Int , key : K , value : @UnsafeVariance V , shift : Int , mutator : PersistentHashMapBuilder <K , V >): TrieNode <K , V > {
562
- if (isCollision()) {
563
- return mutableCollisionPut(key, value, shift, mutator)
564
- }
565
-
566
563
val keyPositionMask = 1 shl indexSegment(keyHash, shift)
567
564
568
565
if (hasEntryAt(keyPositionMask)) { // key is directly in buffer
@@ -590,16 +587,16 @@ internal class TrieNode<K, V>(
590
587
return mutableUpdateNodeAtIndex(nodeIndex, newNode, mutator.ownership)
591
588
}
592
589
590
+ if (isCollision()) {
591
+ return mutableCollisionPut(key, value, shift, mutator)
592
+ }
593
+
593
594
// key is absent
594
595
mutator.size++
595
596
return mutableInsertEntryAt(keyPositionMask, key, value, mutator.ownership)
596
597
}
597
598
598
599
fun remove (keyHash : Int , key : K , shift : Int ): TrieNode <K , V >? {
599
- if (isCollision()) {
600
- return collisionRemove(key)
601
- }
602
-
603
600
val keyPositionMask = 1 shl indexSegment(keyHash, shift)
604
601
605
602
if (hasEntryAt(keyPositionMask)) { // key is directly in buffer
@@ -622,15 +619,15 @@ internal class TrieNode<K, V>(
622
619
}
623
620
}
624
621
622
+ if (isCollision()) {
623
+ return collisionRemove(key)
624
+ }
625
+
625
626
// key is absent
626
627
return this
627
628
}
628
629
629
630
fun mutableRemove (keyHash : Int , key : K , shift : Int , mutator : PersistentHashMapBuilder <K , V >): TrieNode <K , V >? {
630
- if (isCollision()) {
631
- return mutableCollisionRemove(key, mutator)
632
- }
633
-
634
631
val keyPositionMask = 1 shl indexSegment(keyHash, shift)
635
632
636
633
if (hasEntryAt(keyPositionMask)) { // key is directly in buffer
@@ -653,15 +650,15 @@ internal class TrieNode<K, V>(
653
650
}
654
651
}
655
652
653
+ if (isCollision()) {
654
+ return mutableCollisionRemove(key, mutator)
655
+ }
656
+
656
657
// key is absent
657
658
return this
658
659
}
659
660
660
661
fun remove (keyHash : Int , key : K , value : @UnsafeVariance V , shift : Int ): TrieNode <K , V >? {
661
- if (isCollision()) {
662
- return collisionRemove(key, value)
663
- }
664
-
665
662
val keyPositionMask = 1 shl indexSegment(keyHash, shift)
666
663
667
664
if (hasEntryAt(keyPositionMask)) { // key is directly in buffer
@@ -684,15 +681,15 @@ internal class TrieNode<K, V>(
684
681
}
685
682
}
686
683
684
+ if (isCollision()) {
685
+ return collisionRemove(key, value)
686
+ }
687
+
687
688
// key is absent
688
689
return this
689
690
}
690
691
691
692
fun mutableRemove (keyHash : Int , key : K , value : @UnsafeVariance V , shift : Int , mutator : PersistentHashMapBuilder <K , V >): TrieNode <K , V >? {
692
- if (isCollision()) {
693
- return mutableCollisionRemove(key, value, mutator)
694
- }
695
-
696
693
val keyPositionMask = 1 shl indexSegment(keyHash, shift)
697
694
698
695
if (hasEntryAt(keyPositionMask)) { // key is directly in buffer
@@ -715,6 +712,10 @@ internal class TrieNode<K, V>(
715
712
}
716
713
}
717
714
715
+ if (isCollision()) {
716
+ return mutableCollisionRemove(key, value, mutator)
717
+ }
718
+
718
719
// key is absent
719
720
return this
720
721
}
0 commit comments