public static PrimitiveLongIntMap longIntMap() { return longIntMap( DEFAULT_HEAP_CAPACITY ); }
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 longIntKeyVisitorShouldNotSeeEntriesAfterRequestingBreakOut() { // GIVEN PrimitiveLongIntMap map = Primitive.longIntMap(); map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); map.put( 4, 400 ); final AtomicInteger counter = new AtomicInteger(); // WHEN map.visitKeys( value -> counter.incrementAndGet() > 2 ); // THEN assertThat( counter.get(), is( 3 ) ); }
@Test void longIntEntryVisitorShouldNotSeeEntriesAfterRequestingBreakOut() { // GIVEN PrimitiveLongIntMap map = Primitive.longIntMap(); 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 ) ); }
@SuppressWarnings( "unchecked" ) @Test void longIntEntryVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() { // GIVEN PrimitiveLongIntMap map = Primitive.longIntMap(); map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); PrimitiveLongIntVisitor<RuntimeException> visitor = mock( PrimitiveLongIntVisitor.class ); // WHEN map.visitEntries( visitor ); // THEN verify( visitor ).visited( 1, 100 ); verify( visitor ).visited( 2, 200 ); verify( visitor ).visited( 3, 300 ); verifyNoMoreInteractions( visitor ); }
@SuppressWarnings( "unchecked" ) @Test void longIntKeyVisitorShouldSeeAllEntriesIfItDoesNotBreakOut() { // GIVEN PrimitiveLongIntMap map = Primitive.longIntMap(); map.put( 1, 100 ); map.put( 2, 200 ); map.put( 3, 300 ); PrimitiveLongVisitor<RuntimeException> visitor = mock( PrimitiveLongVisitor.class ); // WHEN map.visitKeys( visitor ); // THEN verify( visitor ).visited( 1 ); verify( visitor ).visited( 2 ); verify( visitor ).visited( 3 ); verifyNoMoreInteractions( visitor ); }
@Test void shouldReturnCorrectPreviousValue() { // GIVEN PrimitiveLongIntMap map = Primitive.longIntMap(); map.remove( 2050585513 ); map.put( 429170228, 99 ); map.put( 1356282827, 24 ); map.remove( 1341095873 ); // WHEN/THEN int sizeBefore = map.size(); boolean existedBefore = map.containsKey( 429170228 ); int valueBefore = map.get( 429170228 ); int previous = map.put( 429170228, 1 ); boolean existsAfter = map.containsKey( 429170228 ); int valueAfter = map.get( 429170228 ); int sizeAfter = map.size(); assertEquals( 2, sizeBefore, "Size before put should have been 2" ); assertTrue( existedBefore, "429170228 should exist before putting here" ); assertEquals( 99, valueBefore, "value before should be 99" ); assertEquals( 99, previous, "value returned from put should be 99" ); assertTrue( existsAfter, "429170228 should exist" ); assertEquals( 1, valueAfter, "value after putting should be 1" ); assertEquals( 2, sizeAfter, "Size after put should have been 2" ); }
public RelationshipLoader(int task, boolean weighted, int defaultWeight, AlgoIdGenerator algoIdGenerator) { this.task = task; this.weighted = weighted; this.defaultWeight = defaultWeight; int nodeCount = algoIdGenerator.getNodeCount(); relData = new Chunks(nodeCount); this.algoIdGenerator = algoIdGenerator; sourceDegreeData = new Chunks(nodeCount).withDefault(0); if (weighted) { weights = Primitive.longIntMap(INITIAL_ARRAY_SIZE); } }
PrimitiveLongIntMap map = Primitive.longIntMap(); map.put( 913910231, 25 ); map.put( 102310782, 40 );
public static PrimitiveLongIntMap longIntMap() { return longIntMap( DEFAULT_HEAP_CAPACITY ); }
public static PrimitiveLongIntMap longIntMap() { return longIntMap( DEFAULT_HEAP_CAPACITY ); }
public ForsetiClient( int id, ConcurrentMap<Long,ForsetiLockManager.Lock>[] lockMaps, WaitStrategy<AcquireLockTimeoutException>[] waitStrategies, Pool<ForsetiClient> clientPool, DeadlockResolutionStrategy deadlockResolutionStrategy, IntFunction<ForsetiClient> clientById, long lockAcquisitionTimeoutMillis, Clock clock ) { this.clientId = id; this.lockMaps = lockMaps; this.waitStrategies = waitStrategies; this.deadlockResolutionStrategy = deadlockResolutionStrategy; this.clientPool = clientPool; this.clientById = clientById; this.sharedLockCounts = new PrimitiveLongIntMap[lockMaps.length]; this.exclusiveLockCounts = new PrimitiveLongIntMap[lockMaps.length]; this.lockAcquisitionTimeoutMillis = lockAcquisitionTimeoutMillis; this.clock = clock; for ( int i = 0; i < sharedLockCounts.length; i++ ) { sharedLockCounts[i] = Primitive.longIntMap(); exclusiveLockCounts[i] = Primitive.longIntMap(); } }
PrimitiveLongIntMap map = Primitive.longIntMap(); map.put( 1179059774, 54 ); map.put( 612612792, 91 );
exclusiveLockCounts[i] = Primitive.longIntMap(); sharedLockCounts[i] = Primitive.longIntMap();