/** * Clear the array and set a new capacity if not already large enough. * * @param newCapacity the new capacity requirement */ public void reset( int newCapacity ) { size = 0; ensureCapacity( newCapacity ); }
@Test void testPutIfAbsent() { PrimitiveLongIntKeyValueArray map = new PrimitiveLongIntKeyValueArray(); assertThat( map.putIfAbsent( 1, 100 ), equalTo( true ) ); assertThat( map.putIfAbsent( 2, 200 ), equalTo( true ) ); assertThat( map.putIfAbsent( 3, 300 ), equalTo( true ) ); assertThat( map.size(), equalTo( 3 ) ); assertThat( map.keys(), equalTo( new long[]{1, 2, 3} ) ); assertThat( map.putIfAbsent( 2, 2000 ), equalTo( false ) ); assertThat( map.putIfAbsent( 3, 3000 ), equalTo( false ) ); assertThat( map.putIfAbsent( 4, 4000 ), equalTo( true ) ); assertThat( map.size(), equalTo( 4 ) ); assertThat( map.keys(), equalTo( new long[]{1, 2, 3, 4} ) ); assertThat( map.getOrDefault( 2, DEFAULT_VALUE ), equalTo( 200 ) ); assertThat( map.getOrDefault( 3, DEFAULT_VALUE ), equalTo( 300 ) ); assertThat( map.getOrDefault( 4, DEFAULT_VALUE ), equalTo( 4000 ) ); }
private void writeNodesForPath( NodeValue[] nodes ) throws IOException { nodeIndexes.reset( nodes.length ); for ( NodeValue node : nodes ) { nodeIndexes.putIfAbsent( node.id(), nodeIndexes.size() ); } int size = nodeIndexes.size(); packListHeader( size ); if ( size > 0 ) { NodeValue node = nodes[0]; for ( long id : nodeIndexes.keys() ) { int i = 1; while ( node.id() != id ) { node = nodes[i++]; } node.writeTo( this ); } } }
@Test void testKeys() { PrimitiveLongIntKeyValueArray map = new PrimitiveLongIntKeyValueArray(); map.putIfAbsent( 1, 100 ); map.putIfAbsent( 2, 200 ); map.putIfAbsent( 3, 300 ); map.putIfAbsent( 2, 200 ); map.putIfAbsent( 3, 300 ); map.putIfAbsent( 8, 800 ); map.putIfAbsent( 7, 700 ); map.putIfAbsent( 6, 600 ); map.putIfAbsent( 5, 500 ); assertThat( map.size(), equalTo( 7 ) ); assertThat( map.keys(), equalTo( new long[]{1, 2, 3, 8, 7, 6, 5} ) ); } }
@Test void testSize() { PrimitiveLongIntKeyValueArray map = new PrimitiveLongIntKeyValueArray(); assertThat( map.size(), equalTo( 0 ) ); map.putIfAbsent( 1, 100 ); map.putIfAbsent( 2, 200 ); map.putIfAbsent( 3, 300 ); assertThat( map.size(), equalTo( 3 ) ); }
@Test void testReset() { PrimitiveLongIntKeyValueArray map = new PrimitiveLongIntKeyValueArray(); map.putIfAbsent( 1, 100 ); map.putIfAbsent( 2, 200 ); map.putIfAbsent( 3, 300 ); map.reset( 1000 ); assertThat( map.size(), equalTo( 0 ) ); assertThat( map.capacity(), greaterThanOrEqualTo( 1000 ) ); }
@Test void testGetOrDefault() { PrimitiveLongIntKeyValueArray map = new PrimitiveLongIntKeyValueArray(); map.putIfAbsent( 1, 100 ); map.putIfAbsent( 2, 200 ); map.putIfAbsent( 3, 300 ); assertThat( map.getOrDefault( 1, DEFAULT_VALUE ), equalTo( 100 ) ); assertThat( map.getOrDefault( 2, DEFAULT_VALUE ), equalTo( 200 ) ); assertThat( map.getOrDefault( 3, DEFAULT_VALUE ), equalTo( 300 ) ); assertThat( map.getOrDefault( 4, DEFAULT_VALUE ), equalTo( DEFAULT_VALUE ) ); }
@Test void testEnsureCapacity() { PrimitiveLongIntKeyValueArray map = new PrimitiveLongIntKeyValueArray(); assertThat( map.capacity(), equalTo( PrimitiveLongIntKeyValueArray.DEFAULT_INITIAL_CAPACITY ) ); map.ensureCapacity( 10 ); assertThat( map.capacity(), greaterThanOrEqualTo( 10 ) ); map.ensureCapacity( 100 ); assertThat( map.capacity(), greaterThanOrEqualTo( 100 ) ); map.ensureCapacity( 1000 ); assertThat( map.capacity(), greaterThanOrEqualTo( 1000 ) ); }
int index = nodeIndexes.getOrDefault( node.id(), NO_SUCH_ID ); pack( index ); int index = relationshipIndexes.getOrDefault( r.id(), NO_SUCH_ID );
int index = nodeIndexes.getOrDefault( node.id(), NO_SUCH_ID ); pack( index ); int index = relationshipIndexes.getOrDefault( r.id(), NO_SUCH_ID );
private void writeRelationshipsForPath( RelationshipValue[] relationships ) throws IOException relationshipIndexes.reset( relationships.length ); for ( RelationshipValue node : relationships ) relationshipIndexes.putIfAbsent( node.id(), relationshipIndexes.size() + 1 ); int size = relationshipIndexes.size(); packListHeader( size ); if ( size > 0 ) for ( long id : relationshipIndexes.keys() )
if ( size == capacity ) ensureCapacity( (int) Math.floor( growthFactor * capacity ) );
private void writeNodesForPath( NodeValue[] nodes ) throws IOException { nodeIndexes.reset( nodes.length ); for ( NodeValue node : nodes ) { nodeIndexes.putIfAbsent( node.id(), nodeIndexes.size() ); } int size = nodeIndexes.size(); packListHeader( size ); if ( size > 0 ) { NodeValue node = nodes[0]; for ( long id : nodeIndexes.keys() ) { int i = 1; while ( node.id() != id ) { node = nodes[i++]; } node.writeTo( this ); } } }
/** * Clear the array and set a new capacity if not already large enough. * * @param newCapacity the new capacity requirement */ public void reset( int newCapacity ) { size = 0; ensureCapacity( newCapacity ); }
private void writeRelationshipsForPath( RelationshipValue[] relationships ) throws IOException relationshipIndexes.reset( relationships.length ); for ( RelationshipValue node : relationships ) relationshipIndexes.putIfAbsent( node.id(), relationshipIndexes.size() + 1 ); int size = relationshipIndexes.size(); packListHeader( size ); if ( size > 0 ) for ( long id : relationshipIndexes.keys() )
/** * Clear the array and set a new capacity if not already large enough. * * @param newCapacity the new capacity requirement */ public void reset( int newCapacity ) { size = 0; ensureCapacity( newCapacity ); }
if ( size == capacity ) ensureCapacity( (int) Math.floor( growthFactor * capacity ) );
if ( size == capacity ) ensureCapacity( (int) Math.floor( growthFactor * capacity ) );