public void increment ( double coord , double val ) { int bin = getBinNr ( coord ) ; if ( bin < 0 ) { if ( size - bin > data . length ) { // Reallocate. TODO: use an arraylist-like grow strategy! double [ ] tmpdata = new double [ growSize ( data . length , size - bin ) ] ; System . arraycopy ( data , 0 , tmpdata , - bin , size ) ; data = tmpdata ; } else { // Shift in place and clear head System . arraycopy ( data , 0 , data , - bin , size ) ; Arrays . fill ( data , 0 , - bin , ( double ) 0 ) ; } data [ 0 ] = val ; // Note that bin is negative, -bin is the shift offset! assert ( data . length >= size - bin ) ; offset -= bin ; size -= bin ; // TODO: modCounter++; and have iterators fast-fail } else if ( bin >= data . length ) { double [ ] tmpdata = new double [ growSize ( data . length , bin + 1 ) ] ; System . arraycopy ( data , 0 , tmpdata , 0 , size ) ; tmpdata [ bin ] = val ; data = tmpdata ; size = bin + 1 ; // TODO: modCounter++; and have iterators fast-fail // Unset max value when resizing max = Double . MAX_VALUE ; } else { if ( bin >= size ) { // TODO: reset bins to 0 first? size = bin + 1 ; } data [ bin ] += val ; } }
Increment the value of a bin .