private void addTimestamp(long userID, long itemID, String timestampString, FastByIDMap<FastByIDMap<Long>> timestamps) { if (timestampString != null) { FastByIDMap<Long> itemTimestamps = timestamps.get(userID); if (itemTimestamps == null) { itemTimestamps = new FastByIDMap<Long>(); timestamps.put(userID, itemTimestamps); } long timestamp = readTimestampFromString(timestampString); itemTimestamps.put(itemID, timestamp); } }
growAndRehash(); } else { rehash(); int index = findForAdd(key); long keyIndex = keys[index]; if (keyIndex == key) { clearStaleEntry(index);
@Override public void addTimestamp(Long u, Long i, Long t) { if (model != null) { throw new IllegalArgumentException("DataModel already generated. It is not possible to add more information."); } FastByIDMap<Long> prefs = null; if (!timestampData.containsKey(u)) { prefs = new FastByIDMap<Long>(); timestampData.put(u, prefs); } else { prefs = timestampData.get(u); } prefs.put(i, t); }
this.preferenceForItems = new FastByIDMap<FastIDSet>(); FastIDSet itemIDSet = new FastIDSet(); for (Map.Entry<Long, FastIDSet> entry : preferenceFromUsers.entrySet()) { long userID = entry.getKey(); FastIDSet itemIDs = entry.getValue(); while (it.hasNext()) { long itemID = it.nextLong(); FastIDSet userIDs = preferenceForItems.get(itemID); if (userIDs == null) { userIDs = new FastIDSet(2); preferenceForItems.put(itemID, userIDs); this.userIDs = new long[userData.size()]; int i = 0; LongPrimitiveIterator it = userData.keySetIterator(); while (it.hasNext()) { userIDs[i++] = it.next();
private FastByIDMap<String> buildMapping() throws IOException { FastByIDMap<String> mapping = new FastByIDMap<String>(); for (String line : new FileLineIterable(dataFile)) { mapping.put(toLongID(line), line); } lastModified = dataFile.lastModified(); return mapping; }
Object maybePrefs = data.get(userID); if (fromPriorData) { data.remove(userID); } else { PreferenceArray newPrefs = new GenericUserPreferenceArray(length - 1); ((FastByIDMap<PreferenceArray>) data).put(userID, newPrefs); prefs.setItemID(0, itemID); prefs.setValue(0, preferenceValue); ((FastByIDMap<PreferenceArray>) data).put(userID, prefs); if (prefs == null) { prefs = Lists.newArrayListWithCapacity(2); ((FastByIDMap<Collection<Preference>>) data).put(userID, prefs);
@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)); }
@Override public void clear() { model = null; data = new FastByIDMap<Collection<Preference>>(); timestampData = new FastByIDMap<FastByIDMap<Long>>(); } }
@Override public String toStringID(long longID) { synchronized (longToString) { return longToString.get(longID); } }
public Iterable<Map.Entry<Long,Integer>> getUserIDMappings() { return userIDMapping.entrySet(); }
@Override public void storeMapping(long longID, String stringID) { synchronized (longToString) { longToString.put(longID, stringID); } }
private void growAndRehash() { if (keys.length * loadFactor >= RandomUtils.MAX_INT_SMALLER_TWIN_PRIME) { throw new IllegalStateException("Can't grow any more"); } rehash(RandomUtils.nextTwinPrime((int) (loadFactor * keys.length))); }
public int numItems() { return itemIDMapping.size(); }
@Override public String toString() { if (isEmpty()) { return "{}"; } StringBuilder result = new StringBuilder(); result.append('{'); for (int i = 0; i < keys.length; i++) { long key = keys[i]; if (key != NULL && key != REMOVED) { result.append(key).append('=').append(values[i]).append(','); } } result.setCharAt(result.length() - 1, '}'); return result.toString(); }