public void clearUpTo ( int key ) { if ( ( ( start <= key ) && ( key < ( end - 1 ) ) ) ) { // Loop from the start of the data, up to the key to clear up to, clearing all data encountered in-between. int newStart ; for ( newStart = start ; ( newStart <= end ) && ( newStart <= key ) ; newStart ++ ) { int offset = offset ( newStart ) ; if ( data [ offset ] != null ) { data [ offset ] = null ; count -- ; } } // Continue on after the clear up to point, until the first non-null entry or end of array is encountered, // and make that the new start. for ( ; newStart <= end ; newStart ++ ) { if ( data [ offset ( newStart ) ] != null ) { break ; } } start = newStart ; } else { // The key does not lie between the start and end markers, so clear the entire map up to the end int newStart ; for ( newStart = start ; ( newStart <= end ) ; newStart ++ ) { int offset = offset ( newStart ) ; if ( data [ offset ] != null ) { data [ offset ] = null ; count -- ; } } start = newStart ; offset = - start ; } }
Clears entries up to and including the specified key from the map . This is a simple garbage collection operation to clear consumed data from the circular buffer .