@@ -84,30 +84,29 @@ private void decodeSparse(MatrixBlock in, FrameBlock out, int rl, int ru) {
8484 }
8585
8686 private void decodeSparseRow (FrameBlock out , final SparseBlock sb , int i ) {
87- if (!sb .isEmpty (i )) {
88- final int apos = sb .pos (i );
89- final int alen = sb .size (i ) + apos ;
90- final int [] aix = sb .indexes (i );
91- // double[] val = sb.values(i); always 1... therefore not needed
92- int h = 0 ;
93- for (int j = 0 ; j < _colList .length && h < alen ; j ++) { // for each decode column.
94- // find k, the index in aix, within the range of low and high
95- int low = _clPos [j ];
96- int high = _cuPos [j ];
97- while (h < alen && aix [h ] < low ) {
98- h ++;
99- }
100- if (h < alen && aix [h ] >= low && aix [h ] < high ) {
101- int k = aix [h ];
102- int col = _colList [j ] - 1 ;
103- out .getColumn (col ).set (i , k - _clPos [j ] + 1 );
104- h ++;
105- }
106- while (h < alen && aix [h ] < high ) {
107- h ++;
108- }
87+ if (sb .isEmpty (i ))
88+ return ;
89+ int apos = sb .pos (i );
90+ final int alen = sb .size (i ) + apos ;
91+ final int [] aix = sb .indexes (i );
92+
93+ for (int j = 0 ; j < _colList .length ; j ++) { // for each decode column.
94+ // find k, the index in aix, within the range of low and high
95+ final int low = _clPos [j ];
96+ final int high = _cuPos [j ];
97+ int h = Arrays .binarySearch (aix , apos , alen , low ); // start h at column.
98+ if (h < 0 ) // search gt col index (see binary search)
99+ h = Math .abs (h + 1 );
100+
101+ if (h < alen && aix [h ] >= low && aix [h ] < high ) {
102+ int k = aix [h ];
103+ int col = _colList [j ] - 1 ;
104+ out .getColumn (col ).set (i , k - _clPos [j ] + 1 );
109105 }
106+ // limit the binary search.
107+ apos = h ;
110108 }
109+
111110 }
112111
113112 @ Override
0 commit comments