@Override public LongSortedSet tailSet(long key) { int start = keys.findLowerBound(key); int end = keys.getUpperBound(); return new LongSortedArraySet(keys.subIndex(start, end)); }
@Override public Long2DoubleSortedMap headMap(long l) { int endIdx = keys.findLowerBound(l); // lower bound so we don't include 'l' return createSubMap(keys.getLowerBound(), endIdx); }
@Override public LongSortedSet headSet(long key) { int start = keys.getLowerBound(); int end = keys.findLowerBound(key); return new LongSortedArraySet(keys.subIndex(start, end)); }
static KeyedObjectMap<String> createMap(String... strings) { return KeyedObjectMap.newBuilder(StringEx.INSTANCE) .add(strings) .build(); }
/** * Get the mean rating for an item. * @param item The item. * @return The item's mean rating, or {@link Double#NaN} if the item is absent. */ public double getItemMean(long item) { int idx = itemIndex.tryGetIndex(item); return idx >= 0 ? itemOffsets[idx] + globalMean : Double.NaN; }
@Override public double get(long l) { int idx = keys.tryGetIndex(l); if (idx >= 0) { return values[idx]; } else { return defaultReturnValue(); } }
@Override public LongSortedSet subSet(long startKey, long endKey) { int start = keys.findLowerBound(startKey); int end = keys.findLowerBound(endKey); return new LongSortedArraySet(keys.subIndex(start, end)); }
@Override public Long2DoubleSortedMap tailMap(long l) { int startIdx = keys.findLowerBound(l); // include 'l' return createSubMap(startIdx, keys.getUpperBound()); }
@Override public Long2DoubleSortedArrayMap subMap(long from, long to) { int startIdx = keys.findLowerBound(from); // include 'from' int endIdx = keys.findLowerBound(to); // lower bound so we don't include 'to' return createSubMap(startIdx, endIdx); }
/** * Create a new builder for a keyed object map over a self-keying type. * @param <T> The keyed object type. * @return A builder for a keyed object map. */ public static <T extends KeyedObject> KeyedObjectMapBuilder<T> newBuilder() { return new KeyedObjectMapBuilder<>(Keys.selfExtractor()); }
/** * Create a new keyed object map. * @param objs A collection of objects to put in the map. * @param <T> The keyed object type. * @return A keyed object map of the objects in {@code objs}. */ public static <T extends KeyedObject> KeyedObjectMap<T> create(Collection<? extends T> objs) { return new KeyedObjectMap<>(objs, Keys.selfExtractor()); }
public KeyedObjectMapBuilder<T> add(T... items) { for (T item: items) { add(item); } return this; }
/** * Make an immutable copy of this index mapping. * * @return An immutable copy of the index mapping. */ public FrozenHashKeyIndex frozenCopy() { return new FrozenHashKeyIndex(indexMap, keyList); } }
/** * Get a view of the index as a set. * @return The set of keys. */ public LongSortedArraySet keySet() { return new LongSortedArraySet(this); }
/** * Get the item's average offset from global mean. * @param item The item. * @return The item's average offset from the global mean rating, or 0 if the item is missing */ public double getItemOffset(long item) { int idx = itemIndex.tryGetIndex(item); return idx >= 0 ? itemOffsets[idx] : 0; }
double getDeviation(long item) { int idx = items.tryGetIndex(item); if (idx >= 0) { return deviations[idx]; } else { return Double.NaN; } }
int getCoratings(long item) { int idx = items.tryGetIndex(item); if (idx >= 0) { return coratings[idx]; } else { return 0; } } }