public static PrimitiveLongSet longSet() { return longSet( DEFAULT_HEAP_CAPACITY ); }
public static PrimitiveLongIntMap longIntMap() { return longIntMap( DEFAULT_HEAP_CAPACITY ); }
public static <VALUE> PrimitiveIntObjectMap<VALUE> intObjectMap() { return intObjectMap( DEFAULT_HEAP_CAPACITY ); }
public static <VALUE> PrimitiveLongObjectMap<VALUE> longObjectMap() { return longObjectMap( DEFAULT_HEAP_CAPACITY ); }
public static PrimitiveIntIterator deduplicate( PrimitiveIntIterator source ) { return new PrimitiveIntFilteringIterator( source ) { private final PrimitiveIntSet visited = Primitive.intSet(); @Override public boolean test( int testItem ) { return visited.add( testItem ); } }; }
public static PrimitiveLongLongMap offHeapLongLongMap( MemoryAllocationTracker allocationTracker ) { return offHeapLongLongMap( DEFAULT_OFFHEAP_CAPACITY, allocationTracker ); }
public static PrimitiveLongLongMap longLongMap() { return longLongMap( DEFAULT_HEAP_CAPACITY ); }
public static PrimitiveIntSet offHeapIntSet() { return offHeapIntSet( GlobalMemoryTracker.INSTANCE ); }
public static PrimitiveIntLongMap intLongMap() { return intLongMap( DEFAULT_HEAP_CAPACITY ); }
public static <T> PrimitiveLongObjectMap<T> copy( PrimitiveLongObjectMap<T> original ) { PrimitiveLongObjectMap<T> copy = Primitive.longObjectMap( original.size() ); original.visitEntries( ( key, value ) -> { copy.put( key, value ); return false; } ); return copy; }
public static PrimitiveIntSet intSet() { return intSet( DEFAULT_HEAP_CAPACITY ); }
public static PrimitiveLongLongMap offHeapLongLongMap() { return offHeapLongLongMap( GlobalMemoryTracker.INSTANCE ); }
@Test void longLongEntryVisitorShouldNotSeeEntriesAfterRequestingBreakOut() { // GIVEN AtomicInteger counter = new AtomicInteger(); try ( PrimitiveLongLongMap map = Primitive.longLongMap() ) { map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); map.put( 4, 400 ); // WHEN map.visitEntries( ( key, value ) -> counter.incrementAndGet() > 2 ); } // THEN assertThat( counter.get(), is( 3 ) ); }
@Test void trackPrimitiveMemoryAllocations() { LocalMemoryTracker memoryTracker = new LocalMemoryTracker(); PrimitiveIntSet offHeapIntSet = Primitive.offHeapIntSet( memoryTracker ); assertTrue( memoryTracker.usedDirectMemory() > 0 ); offHeapIntSet.close(); assertEquals( 0, memoryTracker.usedDirectMemory() ); }
@Test void intLongEntryVisitorShouldNotSeeEntriesAfterRequestingBreakOut() { // GIVEN PrimitiveIntLongMap map = Primitive.intLongMap(); map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); map.put( 4, 400 ); final AtomicInteger counter = new AtomicInteger(); // WHEN map.visitEntries( ( key, value ) -> counter.incrementAndGet() > 2 ); // THEN assertThat( counter.get(), is( 3 ) ); }
public static PrimitiveLongSet asSet( long... values ) { PrimitiveLongSet result = Primitive.longSet( values.length ); for ( long value: values ) { result.add( value ); } return result; }
private static void verifyMapRetainsAllEntries( List<Long> lst ) { PrimitiveLongIntMap map = Primitive.longIntMap(); Set<Long> set = new HashSet<>(); for ( Long value: lst ) { assertThat( map.put( value, 1 ), is( -1 ) ); assertTrue( set.add( value ) ); } assertThat( map.size(), is( set.size() ) ); for ( Long aLong: set ) { assertThat( map.get( aLong ), is( 1 ) ); } } }
@Test void longObjectEntryVisitorShouldNotSeeEntriesAfterRequestingBreakOut() { // GIVEN PrimitiveLongObjectMap<Integer> map = Primitive.longObjectMap(); map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); map.put( 4, 400 ); final AtomicInteger counter = new AtomicInteger(); // WHEN map.visitEntries( ( key, value ) -> counter.incrementAndGet() > 2 ); // THEN assertThat( counter.get(), is( 3 ) ); }
public static PrimitiveIntSet asSet( int[] values ) { PrimitiveIntSet set = Primitive.intSet( values.length ); for ( int value: values ) { set.add( value ); } return set; }
public static <T> PrimitiveIntObjectMap<T> copy( PrimitiveIntObjectMap<T> original ) { PrimitiveIntObjectMap<T> copy = Primitive.intObjectMap( original.size() ); original.visitEntries( ( key, value ) -> { copy.put( key, value ); return false; } ); return copy; }