Search in sources :

Example 1 with LongLongHashMap

use of org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method removeKeyIfAbsent.

@Test
public void removeKeyIfAbsent() {
    MutableLongLongMap map0 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    Assert.assertEquals(1L, map0.removeKeyIfAbsent(1L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L), map0);
    Assert.assertEquals(0L, map0.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(new LongLongHashMap(), map0);
    Assert.assertEquals(100L, map0.removeKeyIfAbsent(1L, 100L));
    Assert.assertEquals(100L, map0.removeKeyIfAbsent(0L, 100L));
    MutableLongLongMap map1 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    Assert.assertEquals(0L, map1.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L), map1);
    Assert.assertEquals(1L, map1.removeKeyIfAbsent(1L, 100L));
    Assert.assertEquals(new LongLongHashMap(), map1);
    Assert.assertEquals(100L, map1.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(100L, map1.removeKeyIfAbsent(1L, 100L));
    MutableLongLongMap map2 = this.classUnderTest();
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(5L, 100L));
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(50L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L, 31L, 31L, 32L, 32L), map2);
    Assert.assertEquals(0L, map2.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(31L, 31L, 32L, 32L), map2);
    Assert.assertEquals(31L, map2.removeKeyIfAbsent(31L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(32L, 32L), map2);
    Assert.assertEquals(32L, map2.removeKeyIfAbsent(32L, 100L));
    Assert.assertEquals(new LongLongHashMap(), map2);
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(31L, 100L));
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(32L, 100L));
    Assert.assertEquals(new LongLongHashMap(), map2);
    Verify.assertEmpty(map2);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(0), 1L);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(1), 2L);
    Assert.assertEquals(1L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    Assert.assertEquals(1L, map2.removeKeyIfAbsent(AbstractMutableLongLongMapTestCase.generateCollisions().get(0), 100L));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    Assert.assertEquals(2L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
    Assert.assertEquals(2L, map2.removeKeyIfAbsent(AbstractMutableLongLongMapTestCase.generateCollisions().get(1), 100L));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 2 with LongLongHashMap

use of org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method put.

@Test
public void put() {
    MutableLongLongMap map1 = this.classUnderTest();
    map1.put(0L, 1L);
    map1.put(31L, 32L);
    map1.put(32L, 33L);
    LongLongHashMap expected = LongLongHashMap.newWithKeysValues(0L, 1L, 31L, 32L, 32L, 33L);
    Assert.assertEquals(expected, map1);
    map1.put(1L, 2L);
    expected.put(1L, 2L);
    Assert.assertEquals(expected, map1);
    map1.put(33L, 34L);
    expected.put(33L, 34L);
    Assert.assertEquals(expected, map1);
    map1.put(30L, 31L);
    expected.put(30L, 31L);
    Assert.assertEquals(expected, map1);
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 3 with LongLongHashMap

use of org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method put_every_slot.

@Test
public void put_every_slot() {
    LongLongHashMap hashMap = new LongLongHashMap();
    for (int i = 2; i < 100; i++) {
        Assert.assertEquals(0L, hashMap.get((long) i));
        hashMap.put((long) i, (long) i);
        Assert.assertEquals((long) i, hashMap.get((long) i));
        hashMap.remove((long) i);
        Assert.assertEquals(0L, hashMap.get((long) i));
    }
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) Test(org.junit.Test)

Example 4 with LongLongHashMap

use of org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method removeKey.

@Test
public void removeKey() {
    MutableLongLongMap map0 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    map0.removeKey(1L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L), map0);
    map0.removeKey(0L);
    Assert.assertEquals(new LongLongHashMap(), map0);
    MutableLongLongMap map1 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    map1.removeKey(0L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L), map1);
    map1.removeKey(1L);
    Assert.assertEquals(new LongLongHashMap(), map1);
    MutableLongLongMap map2 = this.classUnderTest();
    map2.removeKey(5L);
    map2.removeKey(50L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L, 31L, 31L, 32L, 32L), map2);
    map2.removeKey(0L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(31L, 31L, 32L, 32L), map2);
    map2.removeKey(31L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(32L, 32L), map2);
    map2.removeKey(32L);
    Assert.assertEquals(new LongLongHashMap(), map2);
    map2.removeKey(0L);
    map2.removeKey(31L);
    map2.removeKey(32L);
    Assert.assertEquals(new LongLongHashMap(), map2);
    Verify.assertEmpty(map2);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(0), 1L);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(1), 2L);
    Assert.assertEquals(1L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    map2.removeKey(AbstractMutableLongLongMapTestCase.generateCollisions().get(0));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    Assert.assertEquals(2L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
    map2.removeKey(AbstractMutableLongLongMapTestCase.generateCollisions().get(1));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 5 with LongLongHashMap

use of org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method generateCollisions.

protected static LongArrayList generateCollisions() {
    LongArrayList collisions = new LongArrayList();
    LongLongHashMap hashMap = new LongLongHashMap();
    for (long each = 2L; collisions.size() <= 10; each++) {
        //            if (hashMap.spreadAndMask(each) == hashMap.spreadAndMask(2L))
        {
            collisions.add(each);
        }
    }
    return collisions;
}
Also used : LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap)

Aggregations

LongLongHashMap (org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap)8 Test (org.junit.Test)7 MutableLongLongMap (org.eclipse.collections.api.map.primitive.MutableLongLongMap)6 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)1