@@ -54,15 +54,15 @@ internal class LinkedHashTreeMap<K, V>(
5454
5555 // Clear all links to help GC
5656 val header = header
57- var e = header.next
57+ var e = header.next!!
5858 while (e != = header) {
59- val next = e!! .next
59+ val next = e.next
6060 e.prev = null
6161 e.next = null
62- e = next
62+ e = next!!
6363 }
6464 header.prev = header
65- header.next = header.prev
65+ header.next = header
6666 }
6767
6868 override fun remove (key : K ) = removeInternalByKey(key)?.value
@@ -85,7 +85,8 @@ internal class LinkedHashTreeMap<K, V>(
8585
8686 private var realKey: K ? = null
8787
88- override val key: K get() = knownNotNull(realKey)
88+ override val key: K
89+ get() = knownNotNull(realKey)
8990
9091 @JvmField
9192 val hash: Int
@@ -137,7 +138,7 @@ internal class LinkedHashTreeMap<K, V>(
137138 }
138139
139140 override fun hashCode (): Int {
140- return (realKey?.hashCode() ? : 0 ) xor if (value == null ) 0 else value .hashCode()
141+ return (realKey?.hashCode() ? : 0 ) xor (value? .hashCode() ? : 0 )
141142 }
142143
143144 override fun toString () = " $key =$value "
@@ -188,7 +189,7 @@ internal class LinkedHashTreeMap<K, V>(
188189 val comparator: Comparator <in K ?> = comparator
189190 val table = table
190191 val hash = secondaryHash(key.hashCode())
191- val index = hash and table.size - 1
192+ val index = hash and ( table.size - 1 )
192193 var nearest = table[index]
193194 var comparison = 0
194195 if (nearest != null ) {
@@ -246,7 +247,7 @@ internal class LinkedHashTreeMap<K, V>(
246247 return try {
247248 @Suppress(" UNCHECKED_CAST" )
248249 if (key != null ) find(key as K , false ) else null
249- } catch (e : ClassCastException ) {
250+ } catch (_ : ClassCastException ) {
250251 null
251252 }
252253 }
@@ -363,7 +364,7 @@ internal class LinkedHashTreeMap<K, V>(
363364 parent.right = replacement
364365 }
365366 } else {
366- val index = node.hash and table.size - 1
367+ val index = node.hash and ( table.size - 1 )
367368 table[index] = replacement
368369 }
369370 }
@@ -437,17 +438,19 @@ internal class LinkedHashTreeMap<K, V>(
437438 /* * Rotates the subtree so that its root's right child is the new root. */
438439 private fun rotateLeft (root : Node <K , V >) {
439440 val left = root.left
440- val pivot = root.right
441- val pivotLeft = pivot!! .left
441+ val pivot = root.right!!
442+ val pivotLeft = pivot.left
442443 val pivotRight = pivot.right
443444
444445 // move the pivot's left child to the root's right
445446 root.right = pivotLeft
446447 if (pivotLeft != null ) {
447448 pivotLeft.parent = root
448449 }
450+
449451 replaceInParent(root, pivot)
450452
453+ // move the root to the pivot's left
451454 pivot.left = root
452455 root.parent = pivot
453456
@@ -458,16 +461,17 @@ internal class LinkedHashTreeMap<K, V>(
458461
459462 /* * Rotates the subtree so that its root's left child is the new root. */
460463 private fun rotateRight (root : Node <K , V >) {
461- val pivot = root.left
464+ val pivot = root.left!!
462465 val right = root.right
463- val pivotLeft = pivot!! .left
466+ val pivotLeft = pivot.left
464467 val pivotRight = pivot.right
465468
466469 // move the pivot's right child to the root's left
467470 root.left = pivotRight
468471 if (pivotRight != null ) {
469472 pivotRight.parent = root
470473 }
474+
471475 replaceInParent(root, pivot)
472476
473477 // move the root to the pivot's right
@@ -480,7 +484,7 @@ internal class LinkedHashTreeMap<K, V>(
480484 }
481485
482486 abstract inner class LinkedTreeMapIterator <T > : MutableIterator <T > {
483- var next = header.next
487+ var next: Node < K , V > = header.next!!
484488 private var lastReturned: Node <K , V >? = null
485489 private var expectedModCount: Int = modCount
486490 override fun hasNext (): Boolean = next != = header
@@ -493,7 +497,7 @@ internal class LinkedHashTreeMap<K, V>(
493497 if (modCount != expectedModCount) {
494498 throw ConcurrentModificationException ()
495499 }
496- next = e!! .next
500+ next = e.next!!
497501 return e.also { lastReturned = it }
498502 }
499503
@@ -639,6 +643,7 @@ internal fun <K, V> doubleCapacity(oldTable: Array<Node<K, V>?>): Array<Node<K,
639643internal class AvlIterator <K , V > {
640644 /* * This stack is a singly linked list, linked by the 'parent' field. */
641645 private var stackTop: Node <K , V >? = null
646+
642647 fun reset (root : Node <K , V >? ) {
643648 var stackTop: Node <K , V >? = null
644649 var n = root
@@ -652,8 +657,8 @@ internal class AvlIterator<K, V> {
652657
653658 operator fun next (): Node <K , V >? {
654659 var stackTop: Node <K , V >? = stackTop ? : return null
655- val result = stackTop
656- stackTop = result!! .parent
660+ val result = stackTop!!
661+ stackTop = result.parent
657662 result.parent = null
658663 var n = result.right
659664 while (n != null ) {
@@ -682,9 +687,11 @@ internal class AvlIterator<K, V> {
682687internal class AvlBuilder <K , V > {
683688 /* * This stack is a singly linked list, linked by the 'parent' field. */
684689 private var stack: Node <K , V >? = null
690+
685691 private var leavesToSkip = 0
686692 private var leavesSkipped = 0
687693 private var size = 0
694+
688695 fun reset (targetSize : Int ) {
689696 // compute the target tree size. This is a power of 2 minus one, like 15 or 31.
690697 val treeCapacity = Integer .highestOneBit(targetSize) * 2 - 1
@@ -701,7 +708,7 @@ internal class AvlBuilder<K, V> {
701708 node.height = 1
702709
703710 // Skip a leaf if necessary.
704- if (leavesToSkip > 0 && size and 1 == 0 ) {
711+ if (leavesToSkip > 0 && ( size and 1 ) == 0 ) {
705712 size++
706713 leavesToSkip--
707714 leavesSkipped++
@@ -711,7 +718,7 @@ internal class AvlBuilder<K, V> {
711718 size++
712719
713720 // Skip a leaf if necessary.
714- if (leavesToSkip > 0 && size and 1 == 0 ) {
721+ if (leavesToSkip > 0 && ( size and 1 ) == 0 ) {
715722 size++
716723 leavesToSkip--
717724 leavesSkipped++
@@ -731,14 +738,14 @@ internal class AvlBuilder<K, V> {
731738 * size (N-1) whenever the total size is 2N-1 whenever N is a power of 2.
732739 */
733740 var scale = 4
734- while (size and scale - 1 == scale - 1 ) {
741+ while (size and ( scale - 1 ) == scale - 1 ) {
735742 when (leavesSkipped) {
736743 0 -> {
737744 // Pop right, center and left, then make center the top of the stack.
738- val right = stack
739- val center = right!! .parent
740- val left = center!! .parent
741- center.parent = left!! .parent
745+ val right = stack!!
746+ val center = right.parent!!
747+ val left = center.parent!!
748+ center.parent = left.parent
742749 stack = center
743750 // Construct a tree.
744751 center.left = left
@@ -750,9 +757,9 @@ internal class AvlBuilder<K, V> {
750757
751758 1 -> {
752759 // Pop right and center, then make center the top of the stack.
753- val right = stack
754- val center = right!! .parent
755- stack = center!!
760+ val right = stack!!
761+ val center = right.parent!!
762+ stack = center
756763 // Construct a tree with no left child.
757764 center.right = right
758765 center.height = right.height + 1
0 commit comments