@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 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 ) ); }
@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 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 ) ); }
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 ); } } }
relationshipIndexes.putIfAbsent( node.id(), relationshipIndexes.size() + 1 );
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 ); } } }
relationshipIndexes.putIfAbsent( node.id(), relationshipIndexes.size() + 1 );