public int numItems() { return itemIDMapping.size(); }
public int numUsers() { return userIDMapping.size(); }
public int numItems() { return itemIDMapping.size(); }
public int numItems() { return itemIDMapping.size(); }
public int numUsers() { return userIDMapping.size(); }
public int numUsers() { return userIDMapping.size(); }
protected Integer itemIndex(long itemID) { Integer itemIndex = itemIDMapping.get(itemID); if (itemIndex == null) { itemIndex = itemIDMapping.size(); itemIDMapping.put(itemID, itemIndex); } return itemIndex; }
protected Integer userIndex(long userID) { Integer userIndex = userIDMapping.get(userID); if (userIndex == null) { userIndex = userIDMapping.size(); userIDMapping.put(userID, userIndex); } return userIndex; }
protected Integer itemIndex(long itemID) { Integer itemIndex = itemIDMapping.get(itemID); if (itemIndex == null) { itemIndex = itemIDMapping.size(); itemIDMapping.put(itemID, itemIndex); } return itemIndex; }
protected Integer userIndex(long userID) { Integer userIndex = userIDMapping.get(userID); if (userIndex == null) { userIndex = userIDMapping.size(); userIDMapping.put(userID, userIndex); } return userIndex; }
protected Integer userIndex(long userID) { Integer userIndex = userIDMapping.get(userID); if (userIndex == null) { userIndex = userIDMapping.size(); userIDMapping.put(userID, userIndex); } return userIndex; }
protected Integer itemIndex(long itemID) { Integer itemIndex = itemIDMapping.get(itemID); if (itemIndex == null) { itemIndex = itemIDMapping.size(); itemIDMapping.put(itemID, itemIndex); } return itemIndex; }
this.userIDs = new long[userData.size()]; int i = 0; LongPrimitiveIterator it = userData.keySetIterator();
this.userIDs = new long[userData.size()]; int i = 0; LongPrimitiveIterator it = userData.keySetIterator();
@Test public void testMaxSize() { FastByIDMap<String> map = new FastByIDMap<String>(); map.put(4, "bang"); assertEquals(1, map.size()); map.put(47L, "bang"); assertEquals(2, map.size()); assertNull(map.get(500000L)); map.put(47L, "buzz"); assertEquals(2, map.size()); assertEquals("buzz", map.get(47L)); }
this.userIDs = new long[userData.size()]; int i = 0; LongPrimitiveIterator it = userData.keySetIterator();
@Test public void testVersusHashMap() { FastByIDMap<String> actual = new FastByIDMap<String>(); Map<Long, String> expected = Maps.newHashMapWithExpectedSize(1000000); Random r = RandomUtils.getRandom(); for (int i = 0; i < 1000000; i++) { double d = r.nextDouble(); Long key = (long) r.nextInt(100); if (d < 0.4) { assertEquals(expected.get(key), actual.get(key)); } else { if (d < 0.7) { assertEquals(expected.put(key, "bang"), actual.put(key, "bang")); } else { assertEquals(expected.remove(key), actual.remove(key)); } assertEquals(expected.size(), actual.size()); assertEquals(expected.isEmpty(), actual.isEmpty()); } } }
@Test public void testClear() { FastByIDMap<Long> map = new FastByIDMap<Long>(); map.put(500000L, 2L); map.clear(); assertEquals(0, map.size()); assertTrue(map.isEmpty()); assertNull(map.get(500000L)); }
@Test public void testRemove() { FastByIDMap<Long> map = new FastByIDMap<Long>(); map.put(500000L, 2L); map.remove(500000L); assertEquals(0, map.size()); assertTrue(map.isEmpty()); assertNull(map.get(500000L)); }