@@ -277,9 +277,9 @@ extends AbstractSeq[A]
277
277
s
278
278
} else {
279
279
280
- val freeSpace = (1 << (5 * depth)) - endIndex // free space at the right given the current tree-structure depth
281
- val shift = freeSpace & ~ ((1 << (5 * (depth - 1 ))) - 1 ) // number of elements by which we'll shift right (only move at top level)
282
- val shiftBlocks = freeSpace >>> (5 * (depth - 1 )) // number of top-level blocks
280
+ val freeSpace = (1 << (5 * depth)) - endIndex // free space at the right given the current tree-structure depth
281
+ val shift = freeSpace & ~ ((1 << (5 * (depth - 1 ))) - 1 ) // number of elements by which we'll shift right (only move at top level)
282
+ val shiftBlocks = freeSpace >>> (5 * (depth - 1 )) // number of top-level blocks
283
283
284
284
if (shift != 0 ) {
285
285
// case A: we can shift right on the top level
@@ -354,13 +354,14 @@ extends AbstractSeq[A]
354
354
s.display0(lo) = value.asInstanceOf [AnyRef ]
355
355
s
356
356
} else {
357
- val shift = startIndex & ~ ((1 << (5 * (depth - 1 ))) - 1 )
357
+ val shift = startIndex & ~ ((1 << (5 * (depth - 1 ))) - 1 )
358
358
val shiftBlocks = startIndex >>> (5 * (depth - 1 ))
359
359
360
360
if (shift != 0 ) {
361
361
if (depth > 1 ) {
362
362
val newBlockIndex = blockIndex - shift
363
363
val newFocus = focus - shift
364
+
364
365
val s = new Vector (startIndex - shift, endIndex + 1 - shift, newBlockIndex)
365
366
s.initFrom(this )
366
367
s.dirty = dirty
@@ -371,6 +372,7 @@ extends AbstractSeq[A]
371
372
} else {
372
373
val newBlockIndex = blockIndex - 32
373
374
val newFocus = focus
375
+
374
376
val s = new Vector (startIndex - shift, endIndex + 1 - shift, newBlockIndex)
375
377
s.initFrom(this )
376
378
s.dirty = dirty
@@ -405,18 +407,12 @@ extends AbstractSeq[A]
405
407
// low-level implementation (needs cleanup, maybe move to util class)
406
408
407
409
private def shiftTopLevel (oldLeft : Int , newLeft : Int ) = (depth - 1 ) match {
408
- case 0 =>
409
- display0 = copyRange(display0, oldLeft, newLeft)
410
- case 1 =>
411
- display1 = copyRange(display1, oldLeft, newLeft)
412
- case 2 =>
413
- display2 = copyRange(display2, oldLeft, newLeft)
414
- case 3 =>
415
- display3 = copyRange(display3, oldLeft, newLeft)
416
- case 4 =>
417
- display4 = copyRange(display4, oldLeft, newLeft)
418
- case 5 =>
419
- display5 = copyRange(display5, oldLeft, newLeft)
410
+ case 0 => display0 = copyRange(display0, oldLeft, newLeft)
411
+ case 1 => display1 = copyRange(display1, oldLeft, newLeft)
412
+ case 2 => display2 = copyRange(display2, oldLeft, newLeft)
413
+ case 3 => display3 = copyRange(display3, oldLeft, newLeft)
414
+ case 4 => display4 = copyRange(display4, oldLeft, newLeft)
415
+ case 5 => display5 = copyRange(display5, oldLeft, newLeft)
420
416
}
421
417
422
418
private def zeroLeft (array : Array [AnyRef ], index : Int ): Unit = {
@@ -588,9 +584,9 @@ extends AbstractSeq[A]
588
584
}
589
585
590
586
class VectorIterator [+ A ](_startIndex : Int , endIndex : Int )
591
- extends AbstractIterator [A ]
592
- with Iterator [A ]
593
- with VectorPointer [A @ uncheckedVariance] {
587
+ extends AbstractIterator [A ]
588
+ with Iterator [A ]
589
+ with VectorPointer [A @ uncheckedVariance] {
594
590
595
591
private var blockIndex : Int = _startIndex & ~ 31
596
592
private var lo : Int = _startIndex & 31
@@ -728,17 +724,38 @@ private[immutable] trait VectorPointer[T] {
728
724
// requires structure is at pos oldIndex = xor ^ index
729
725
private [immutable] final def getElem (index : Int , xor : Int ): T = {
730
726
if (xor < (1 << 5 )) { // level = 0
731
- display0(index & 31 ).asInstanceOf [T ]
727
+ (display0
728
+ (index & 31 ).asInstanceOf [T ])
732
729
} else if (xor < (1 << 10 )) { // level = 1
733
- display1((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]](index & 31 ).asInstanceOf [T ]
730
+ (display1
731
+ ((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]]
732
+ (index & 31 ).asInstanceOf [T ])
734
733
} else if (xor < (1 << 15 )) { // level = 2
735
- display2((index >>> 10 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]](index & 31 ).asInstanceOf [T ]
734
+ (display2
735
+ ((index >>> 10 ) & 31 ).asInstanceOf [Array [AnyRef ]]
736
+ ((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]]
737
+ (index & 31 ).asInstanceOf [T ])
736
738
} else if (xor < (1 << 20 )) { // level = 3
737
- display3((index >>> 15 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 10 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]](index & 31 ).asInstanceOf [T ]
739
+ (display3
740
+ ((index >>> 15 ) & 31 ).asInstanceOf [Array [AnyRef ]]
741
+ ((index >>> 10 ) & 31 ).asInstanceOf [Array [AnyRef ]]
742
+ ((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]]
743
+ (index & 31 ).asInstanceOf [T ])
738
744
} else if (xor < (1 << 25 )) { // level = 4
739
- display4((index >>> 20 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 15 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 10 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]](index & 31 ).asInstanceOf [T ]
745
+ (display4
746
+ ((index >>> 20 ) & 31 ).asInstanceOf [Array [AnyRef ]]
747
+ ((index >>> 15 ) & 31 ).asInstanceOf [Array [AnyRef ]]
748
+ ((index >>> 10 ) & 31 ).asInstanceOf [Array [AnyRef ]]
749
+ ((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]]
750
+ (index & 31 ).asInstanceOf [T ])
740
751
} else if (xor < (1 << 30 )) { // level = 5
741
- display5((index >>> 25 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 20 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 15 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 10 ) & 31 ).asInstanceOf [Array [AnyRef ]]((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]](index & 31 ).asInstanceOf [T ]
752
+ (display5
753
+ ((index >>> 25 ) & 31 ).asInstanceOf [Array [AnyRef ]]
754
+ ((index >>> 20 ) & 31 ).asInstanceOf [Array [AnyRef ]]
755
+ ((index >>> 15 ) & 31 ).asInstanceOf [Array [AnyRef ]]
756
+ ((index >>> 10 ) & 31 ).asInstanceOf [Array [AnyRef ]]
757
+ ((index >>> 5 ) & 31 ).asInstanceOf [Array [AnyRef ]]
758
+ (index & 31 ).asInstanceOf [T ])
742
759
} else { // level = 6
743
760
throw new IllegalArgumentException ()
744
761
}
@@ -809,55 +826,45 @@ private[immutable] trait VectorPointer[T] {
809
826
// xor: oldIndex ^ index
810
827
private [immutable] final def gotoNextBlockStartWritable (index : Int , xor : Int ): Unit = { // goto block start pos
811
828
if (xor < (1 << 10 )) { // level = 1
812
- if (depth == 1 ) {
813
- display1 = new Array (32 ); display1(0 ) = display0; depth += 1
814
- }
829
+ if (depth == 1 ) { display1 = new Array (32 ); display1(0 ) = display0; depth += 1 }
815
830
display0 = new Array (32 )
816
- display1((index >>> 5 ) & 31 ) = display0
831
+ display1((index >>> 5 ) & 31 ) = display0
817
832
} else if (xor < (1 << 15 )) { // level = 2
818
- if (depth == 2 ) {
819
- display2 = new Array (32 ); display2(0 ) = display1; depth += 1
820
- }
833
+ if (depth == 2 ) { display2 = new Array (32 ); display2(0 ) = display1; depth += 1 }
821
834
display0 = new Array (32 )
822
835
display1 = new Array (32 )
823
- display1((index >>> 5 ) & 31 ) = display0
824
- display2((index >>> 10 ) & 31 ) = display1
836
+ display1((index >>> 5 ) & 31 ) = display0
837
+ display2((index >>> 10 ) & 31 ) = display1
825
838
} else if (xor < (1 << 20 )) { // level = 3
826
- if (depth == 3 ) {
827
- display3 = new Array (32 ); display3(0 ) = display2; depth += 1
828
- }
839
+ if (depth == 3 ) { display3 = new Array (32 ); display3(0 ) = display2; depth += 1 }
829
840
display0 = new Array (32 )
830
841
display1 = new Array (32 )
831
842
display2 = new Array (32 )
832
- display1((index >>> 5 ) & 31 ) = display0
833
- display2((index >>> 10 ) & 31 ) = display1
834
- display3((index >>> 15 ) & 31 ) = display2
843
+ display1((index >>> 5 ) & 31 ) = display0
844
+ display2((index >>> 10 ) & 31 ) = display1
845
+ display3((index >>> 15 ) & 31 ) = display2
835
846
} else if (xor < (1 << 25 )) { // level = 4
836
- if (depth == 4 ) {
837
- display4 = new Array (32 ); display4(0 ) = display3; depth += 1
838
- }
847
+ if (depth == 4 ) { display4 = new Array (32 ); display4(0 ) = display3; depth += 1 }
839
848
display0 = new Array (32 )
840
849
display1 = new Array (32 )
841
850
display2 = new Array (32 )
842
851
display3 = new Array (32 )
843
- display1((index >>> 5 ) & 31 ) = display0
844
- display2((index >>> 10 ) & 31 ) = display1
845
- display3((index >>> 15 ) & 31 ) = display2
846
- display4((index >>> 20 ) & 31 ) = display3
852
+ display1((index >>> 5 ) & 31 ) = display0
853
+ display2((index >>> 10 ) & 31 ) = display1
854
+ display3((index >>> 15 ) & 31 ) = display2
855
+ display4((index >>> 20 ) & 31 ) = display3
847
856
} else if (xor < (1 << 30 )) { // level = 5
848
- if (depth == 5 ) {
849
- display5 = new Array (32 ); display5(0 ) = display4; depth +
CD7A
= 1
850
- }
857
+ if (depth == 5 ) { display5 = new Array (32 ); display5(0 ) = display4; depth += 1 }
851
858
display0 = new Array (32 )
852
859
display1 = new Array (32 )
853
860
display2 = new Array (32 )
854
861
display3 = new Array (32 )
855
862
display4 = new Array (32 )
856
- display1((index >>> 5 ) & 31 ) = display0
857
- display2((index >>> 10 ) & 31 ) = display1
858
- display3((index >>> 15 ) & 31 ) = display2
859
- display4((index >>> 20 ) & 31 ) = display3
860
- display5((index >>> 25 ) & 31 ) = display4
863
+ display1((index >>> 5 ) & 31 ) = display0
864
+ display2((index >>> 10 ) & 31 ) = display1
865
+ display3((index >>> 15 ) & 31 ) = display2
866
+ display4((index >>> 20 ) & 31 ) = display3
867
+ display5((index >>> 25 ) & 31 ) = display4
861
868
} else { // level = 6
862
869
throw new IllegalArgumentException ()
863
870
}
@@ -1102,4 +1109,4 @@ private[immutable] trait VectorPointer[T] {
1102
1109
stabilize(oldIndex)
1103
1110
gotoFreshPosWritable0(oldIndex, newIndex, xor)
1104
1111
}
1105
- }
1112
+ }
0 commit comments