@Test( expected = NullPointerException.class ) public void testPutException() { TableCutList list = new TableCutList( 5, true ); list.put( 5000, null ); }
public boolean put( final long key, final Boolean entry ) { if ( entry == null ) { throw new NullPointerException(); } if ( size > 0 ) { if ( key > keys[size - 1] ) { ensureCapacity( size + 1 ); keys[size] = key; entries[size] = entry; size += 1; scaleFactor = ( key - keys[0] ) / size; return true; } } int start = 0; int end = size; if ( enableQuickLookup && size > 0 && scaleFactor != 0 ) { if ( key < keys[0] ) { end = 1; } else { final int maxIdx = size - 1; final long lastVal = keys[maxIdx]; if ( lastVal > 0 ) { final int targetIdx = (int) ( ( key - keys[0] ) / scaleFactor ); final int minTgtIdx = Math.max( 0, Math.min( maxIdx, targetIdx - 7 ) ); final int maxTgtIdx = Math.min( maxIdx, targetIdx + 7 ); final long minKey = keys[minTgtIdx]; final long maxKey = keys[maxTgtIdx]; final boolean minLessPos = key >= minKey; final boolean maxMorePos = key <= maxKey; if ( minLessPos ) { start = minTgtIdx; } if ( maxMorePos ) { end = maxTgtIdx + 1; } } } } final int position; if ( ( end - start ) < LIN_VS_BIN ) { lin += 1; position = linearSearch( keys, key, start, end ); } else { bin += 1; position = binarySearch( keys, key, start, end ); } if ( position >= 0 ) { final Boolean entryFromList = entries[position]; if ( entryFromList == null ) { throw new IllegalStateException( "Must not happen" ); } if ( Boolean.TRUE.equals( entryFromList ) ) { entries[position] = entry; } return false; } ensureCapacity( size + 1 ); final int insertPoint = -( position + 1 ); if ( insertPoint < size ) { System.arraycopy( keys, insertPoint, keys, insertPoint + 1, size - insertPoint ); System.arraycopy( entries, insertPoint, entries, insertPoint + 1, size - insertPoint ); } keys[insertPoint] = key; entries[insertPoint] = entry; size += 1; if ( insertPoint == ( size - 1 ) ) { scaleFactor = ( key - keys[0] ) / size; } else { scaleFactor = ( keys[size - 1] - keys[0] ) / size; } return true; }
TableCutList implements Cloneable { public boolean put( final long key, final Boolean entry ) { if ( entry == null ) { throw new NullPointerException(); } if ( size > 0 ) { if ( key > keys[size - 1] ) { ensureCapacity( size + 1 ); keys[size] = key; entries[size] = entry; size += 1; scaleFactor = ( key - keys[0] ) / size; return true; } } int start = 0; int end = size; if ( enableQuickLookup && size > 0 && scaleFactor != 0 ) { if ( key < keys[0] ) { end = 1; } else { final int maxIdx = size - 1; final long lastVal = keys[maxIdx]; if ( lastVal > 0 ) { final int targetIdx = (int) ( ( key - keys[0] ) / scaleFactor ); final int minTgtIdx = Math.max( 0, Math.min( maxIdx, targetIdx - 7 ) ); final int maxTgtIdx = Math.min( maxIdx, targetIdx + 7 ); final long minKey = keys[minTgtIdx]; final long maxKey = keys[maxTgtIdx]; final boolean minLessPos = key >= minKey; final boolean maxMorePos = key <= maxKey; if ( minLessPos ) { start = minTgtIdx; } if ( maxMorePos ) { end = maxTgtIdx + 1; } } } } final int position; if ( ( end - start ) < LIN_VS_BIN ) { lin += 1; position = linearSearch( keys, key, start, end ); } else { bin += 1; position = binarySearch( keys, key, start, end ); } if ( position >= 0 ) { final Boolean entryFromList = entries[position]; if ( entryFromList == null ) { throw new IllegalStateException( "Must not happen" ); } if ( Boolean.TRUE.equals( entryFromList ) ) { entries[position] = entry; } return false; } ensureCapacity( size + 1 ); final int insertPoint = -( position + 1 ); if ( insertPoint < size ) { System.arraycopy( keys, insertPoint, keys, insertPoint + 1, size - insertPoint ); System.arraycopy( entries, insertPoint, entries, insertPoint + 1, size - insertPoint ); } keys[insertPoint] = key; entries[insertPoint] = entry; size += 1; if ( insertPoint == ( size - 1 ) ) { scaleFactor = ( key - keys[0] ) / size; } else { scaleFactor = ( keys[size - 1] - keys[0] ) / size; } return true; } }
TableCutList implements Cloneable { public boolean put( final long key, final Boolean entry ) { if ( entry == null ) { throw new NullPointerException(); } if ( size > 0 ) { if ( key > keys[size - 1] ) { ensureCapacity( size + 1 ); keys[size] = key; entries[size] = entry; size += 1; scaleFactor = ( key - keys[0] ) / size; return true; } } int start = 0; int end = size; if ( enableQuickLookup && size > 0 && scaleFactor != 0 ) { if ( key < keys[0] ) { end = 1; } else { final int maxIdx = size - 1; final long lastVal = keys[maxIdx]; if ( lastVal > 0 ) { final int targetIdx = (int) ( ( key - keys[0] ) / scaleFactor ); final int minTgtIdx = Math.max( 0, Math.min( maxIdx, targetIdx - 7 ) ); final int maxTgtIdx = Math.min( maxIdx, targetIdx + 7 ); final long minKey = keys[minTgtIdx]; final long maxKey = keys[maxTgtIdx]; final boolean minLessPos = key >= minKey; final boolean maxMorePos = key <= maxKey; if ( minLessPos ) { start = minTgtIdx; } if ( maxMorePos ) { end = maxTgtIdx + 1; } } } } final int position; if ( ( end - start ) < LIN_VS_BIN ) { lin += 1; position = linearSearch( keys, key, start, end ); } else { bin += 1; position = binarySearch( keys, key, start, end ); } if ( position >= 0 ) { final Boolean entryFromList = entries[position]; if ( entryFromList == null ) { throw new IllegalStateException( "Must not happen" ); } if ( Boolean.TRUE.equals( entryFromList ) ) { entries[position] = entry; } return false; } ensureCapacity( size + 1 ); final int insertPoint = -( position + 1 ); if ( insertPoint < size ) { System.arraycopy( keys, insertPoint, keys, insertPoint + 1, size - insertPoint ); System.arraycopy( entries, insertPoint, entries, insertPoint + 1, size - insertPoint ); } keys[insertPoint] = key; entries[insertPoint] = entry; size += 1; if ( insertPoint == ( size - 1 ) ) { scaleFactor = ( key - keys[0] ) / size; } else { scaleFactor = ( keys[size - 1] - keys[0] ) / size; } return true; } TableCutList( final int increment, final boolean enableQuickLookup ); }
TableCutList implements Cloneable { public boolean put( final long key, final Boolean entry ) { if ( entry == null ) { throw new NullPointerException(); } if ( size > 0 ) { if ( key > keys[size - 1] ) { ensureCapacity( size + 1 ); keys[size] = key; entries[size] = entry; size += 1; scaleFactor = ( key - keys[0] ) / size; return true; } } int start = 0; int end = size; if ( enableQuickLookup && size > 0 && scaleFactor != 0 ) { if ( key < keys[0] ) { end = 1; } else { final int maxIdx = size - 1; final long lastVal = keys[maxIdx]; if ( lastVal > 0 ) { final int targetIdx = (int) ( ( key - keys[0] ) / scaleFactor ); final int minTgtIdx = Math.max( 0, Math.min( maxIdx, targetIdx - 7 ) ); final int maxTgtIdx = Math.min( maxIdx, targetIdx + 7 ); final long minKey = keys[minTgtIdx]; final long maxKey = keys[maxTgtIdx]; final boolean minLessPos = key >= minKey; final boolean maxMorePos = key <= maxKey; if ( minLessPos ) { start = minTgtIdx; } if ( maxMorePos ) { end = maxTgtIdx + 1; } } } } final int position; if ( ( end - start ) < LIN_VS_BIN ) { lin += 1; position = linearSearch( keys, key, start, end ); } else { bin += 1; position = binarySearch( keys, key, start, end ); } if ( position >= 0 ) { final Boolean entryFromList = entries[position]; if ( entryFromList == null ) { throw new IllegalStateException( "Must not happen" ); } if ( Boolean.TRUE.equals( entryFromList ) ) { entries[position] = entry; } return false; } ensureCapacity( size + 1 ); final int insertPoint = -( position + 1 ); if ( insertPoint < size ) { System.arraycopy( keys, insertPoint, keys, insertPoint + 1, size - insertPoint ); System.arraycopy( entries, insertPoint, entries, insertPoint + 1, size - insertPoint ); } keys[insertPoint] = key; entries[insertPoint] = entry; size += 1; if ( insertPoint == ( size - 1 ) ) { scaleFactor = ( key - keys[0] ) / size; } else { scaleFactor = ( keys[size - 1] - keys[0] ) / size; } return true; } TableCutList( final int increment, final boolean enableQuickLookup ); TableCutList clone(); void clear(); boolean isEnableQuickLookup(); void setEnableQuickLookup( final boolean enableQuickLookup ); int size(); boolean put( final long key, final Boolean entry ); boolean remove( final long key ); Boolean get( final long key ); Boolean getPrevious( final long key ); boolean containsKey( final long key ); Boolean[] getRawEntries(); long[] getKeys(); long[] getKeys( long[] retval ); int findKeyPosition( final long coordinate, final boolean greater ); int findKeyPosition( final long coordinate, final boolean greater, final int lastFoundPos ); long getKeyAt( final int indexPosition ); Boolean getValueAt( final int indexPosition ); long findKey( final long key, final boolean upperBounds ); void removeAll( final long[] cutArray, final long cutSize ); }
TableCutList implements Cloneable { public boolean put( final long key, final Boolean entry ) { if ( entry == null ) { throw new NullPointerException(); } if ( size > 0 ) { if ( key > keys[size - 1] ) { ensureCapacity( size + 1 ); keys[size] = key; entries[size] = entry; size += 1; scaleFactor = ( key - keys[0] ) / size; return true; } } int start = 0; int end = size; if ( enableQuickLookup && size > 0 && scaleFactor != 0 ) { if ( key < keys[0] ) { end = 1; } else { final int maxIdx = size - 1; final long lastVal = keys[maxIdx]; if ( lastVal > 0 ) { final int targetIdx = (int) ( ( key - keys[0] ) / scaleFactor ); final int minTgtIdx = Math.max( 0, Math.min( maxIdx, targetIdx - 7 ) ); final int maxTgtIdx = Math.min( maxIdx, targetIdx + 7 ); final long minKey = keys[minTgtIdx]; final long maxKey = keys[maxTgtIdx]; final boolean minLessPos = key >= minKey; final boolean maxMorePos = key <= maxKey; if ( minLessPos ) { start = minTgtIdx; } if ( maxMorePos ) { end = maxTgtIdx + 1; } } } } final int position; if ( ( end - start ) < LIN_VS_BIN ) { lin += 1; position = linearSearch( keys, key, start, end ); } else { bin += 1; position = binarySearch( keys, key, start, end ); } if ( position >= 0 ) { final Boolean entryFromList = entries[position]; if ( entryFromList == null ) { throw new IllegalStateException( "Must not happen" ); } if ( Boolean.TRUE.equals( entryFromList ) ) { entries[position] = entry; } return false; } ensureCapacity( size + 1 ); final int insertPoint = -( position + 1 ); if ( insertPoint < size ) { System.arraycopy( keys, insertPoint, keys, insertPoint + 1, size - insertPoint ); System.arraycopy( entries, insertPoint, entries, insertPoint + 1, size - insertPoint ); } keys[insertPoint] = key; entries[insertPoint] = entry; size += 1; if ( insertPoint == ( size - 1 ) ) { scaleFactor = ( key - keys[0] ) / size; } else { scaleFactor = ( keys[size - 1] - keys[0] ) / size; } return true; } TableCutList( final int increment, final boolean enableQuickLookup ); TableCutList clone(); void clear(); boolean isEnableQuickLookup(); void setEnableQuickLookup( final boolean enableQuickLookup ); int size(); boolean put( final long key, final Boolean entry ); boolean remove( final long key ); Boolean get( final long key ); Boolean getPrevious( final long key ); boolean containsKey( final long key ); Boolean[] getRawEntries(); long[] getKeys(); long[] getKeys( long[] retval ); int findKeyPosition( final long coordinate, final boolean greater ); int findKeyPosition( final long coordinate, final boolean greater, final int lastFoundPos ); long getKeyAt( final int indexPosition ); Boolean getValueAt( final int indexPosition ); long findKey( final long key, final boolean upperBounds ); void removeAll( final long[] cutArray, final long cutSize ); static long bin; static long lin; }