use of gnu.trove.map.TLongLongMap in project SkyBot by duncte123.
the class GuildSettingsUtils method loadVcAutoRoles.
public static void loadVcAutoRoles(Variables variables) {
final DatabaseAdapter adapter = variables.getDatabaseAdapter();
final TLongObjectMap<TLongLongMap> vcAutoRoleCache = variables.getVcAutoRoleCache();
LOGGER.info("Loading vc auto roles.");
adapter.getVcAutoRoles((items) -> {
items.forEach((item) -> {
final TLongLongMap cache = Optional.ofNullable(vcAutoRoleCache.get(item.getGuildId())).orElseGet(() -> {
// This returns the old value which was null
vcAutoRoleCache.put(item.getGuildId(), new TLongLongHashMap());
return vcAutoRoleCache.get(item.getGuildId());
});
cache.put(item.getVoiceChannelId(), item.getRoleId());
});
LOGGER.info("Loaded " + items.size() + " vc auto roles.");
return null;
});
}
use of gnu.trove.map.TLongLongMap in project deephaven-core by deephaven.
the class TestLongLongMap method clear.
@Test
public void clear() {
final int numIterations = 10;
final int sizeAtWhichToClear = 10000;
TLongLongMap map = factory.create(initialCapacity, loadFactor);
for (int iteration = 0; iteration < numIterations; ++iteration) {
TestCase.assertEquals(map.size(), 0);
for (long ii = 0; ii < sizeAtWhichToClear; ++ii) {
map.put(ii, ii + 1);
}
TestCase.assertEquals(map.size(), sizeAtWhichToClear);
map.clear();
}
}
use of gnu.trove.map.TLongLongMap in project deephaven-core by deephaven.
the class TestLongLongMap method testKeysAndValues.
@Test
public void testKeysAndValues() {
Map<Long, Long> reference = new HashMap<>(initialCapacity, loadFactor);
TLongLongMap test = factory.create(initialCapacity, loadFactor);
Random rng = new Random(1283712890);
// populate(rng, 1000000, 10000, 0.75, reference, test);
populate(rng, 1000000, 10000, 0.75, reference, test);
final long[] expectedKeys = new long[reference.size()];
final long[] expectedValues = new long[reference.size()];
int nextIndex = 0;
for (Map.Entry<Long, Long> entry : reference.entrySet()) {
expectedKeys[nextIndex] = entry.getKey();
expectedValues[nextIndex] = entry.getValue();
++nextIndex;
}
TestCase.assertEquals(nextIndex, reference.size());
TestCase.assertEquals(reference.size(), test.size());
final long[] actualKeys = test.keys();
final long[] actualValues = test.values();
TestCase.assertEquals(expectedKeys.length, actualKeys.length);
TestCase.assertEquals(expectedValues.length, actualValues.length);
Arrays.sort(expectedKeys);
Arrays.sort(expectedValues);
Arrays.sort(actualKeys);
Arrays.sort(actualValues);
TestCase.assertTrue(Arrays.equals(expectedKeys, actualKeys));
TestCase.assertTrue(Arrays.equals(expectedValues, actualValues));
final long[] myKeySpace = new long[reference.size()];
final long[] myValueSpace = new long[reference.size()];
final long[] keysWithMySpace = test.keys(myKeySpace);
final long[] valuesWithMySpace = test.values(myValueSpace);
TestCase.assertSame(keysWithMySpace, myKeySpace);
TestCase.assertSame(valuesWithMySpace, myValueSpace);
Arrays.sort(keysWithMySpace);
Arrays.sort(valuesWithMySpace);
TestCase.assertTrue(Arrays.equals(expectedKeys, keysWithMySpace));
TestCase.assertTrue(Arrays.equals(expectedValues, valuesWithMySpace));
}
use of gnu.trove.map.TLongLongMap in project deephaven-core by deephaven.
the class TestLongLongMap method do100KInserts.
@Test
public void do100KInserts() {
TLongLongMap map = factory.create(initialCapacity, loadFactor);
final long beginKey = -50000;
final long endKey = 50000;
final long size = endKey - beginKey;
final long noEntryValue = map.getNoEntryValue();
for (long key = beginKey; key < endKey; ++key) {
map.put(key, key + 1000000);
}
TestCase.assertEquals(map.size(), size);
// These lookups should fail
for (long key = beginKey - size; key < beginKey; ++key) {
final long result = map.get(key);
TestCase.assertEquals(result, noEntryValue);
}
// These lookups should succeed
for (long key = beginKey; key < endKey; ++key) {
final long result = map.get(key);
TestCase.assertEquals(result, key + 1000000);
}
// These lookups should fail
for (long key = endKey; key < endKey + size; ++key) {
final long result = map.get(key);
TestCase.assertEquals(result, noEntryValue);
}
}
use of gnu.trove.map.TLongLongMap in project deephaven-core by deephaven.
the class TestLongLongMap method do100KInsertsThen50KRemoves.
@Test
public void do100KInsertsThen50KRemoves() {
TLongLongMap map = factory.create(initialCapacity, loadFactor);
final long beginKey = 0;
final long endKey = 100000;
final long size = endKey - beginKey;
final long noEntryValue = map.getNoEntryValue();
for (long key = beginKey; key < endKey; ++key) {
map.put(key, key + 1000000);
}
for (long key = beginKey; key < endKey; key += 2) {
map.remove(key);
}
TestCase.assertEquals(map.size(), size / 2);
for (long key = beginKey; key < endKey; ++key) {
final long expectedResult = (key % 2) == 0 ? noEntryValue : key + 1000000;
final long actualResult = map.get(key);
TestCase.assertEquals(expectedResult, actualResult);
}
}
Aggregations