public PerfectFrequency(Config config) { sampleSize = 10 * new BasicSettings(config).maximumSize(); counts = new Long2IntOpenHashMap(); }
public LongToIdMap() { _valueToIdMap = new Long2IntOpenHashMap(); _valueToIdMap.defaultReturnValue(INVALID_KEY); _idToValueMap = new LongArrayList(); }
/** * Constructor for the class. * Populates the value <-> mappings. * * @param dataBuffer Pinot data buffer * @param length Length of the dictionary */ public OnHeapLongDictionary(PinotDataBuffer dataBuffer, int length) { super(dataBuffer, length, Long.BYTES, (byte) 0); _valToDictId = new Long2IntOpenHashMap(length); _valToDictId.defaultReturnValue(-1); _dictIdToVal = new long[length]; for (int dictId = 0; dictId < length; dictId++) { long value = getLong(dictId); _dictIdToVal[dictId] = value; _valToDictId.put(value, dictId); } }
numValues = sortedLongs.length; Preconditions.checkState(numValues > 0); _longValueToIndexMap = new Long2IntOpenHashMap(numValues);
Long2IntOpenHashMap longMap = new Long2IntOpenHashMap(); longMap.defaultReturnValue(INVALID_ID); map = longMap;
public KeyedObjectMapBuilder(KeyExtractor<? super T> ex) { extractor = ex; builder = new ArrayList<>(); posMap = new Long2IntOpenHashMap(); posMap.defaultReturnValue(-1); }
/** * Construct a new key index with pre-built storage. */ FrozenHashKeyIndex(Long2IntMap indexes, LongList keys) { indexMap = new Long2IntOpenHashMap(indexes); indexMap.defaultReturnValue(-1); keyList = new LongArrayList(keys); }
/** * Construct a new empty indexer. The first interned ID will have index 0. */ public HashKeyIndex() { indexMap = new Long2IntOpenHashMap(); indexMap.defaultReturnValue(-1); keyList = new LongArrayList(); }
@Override public Long2IntMap splitEntities(LongSet entities, int np, Random rng) { Long2IntMap emap = new Long2IntOpenHashMap(entities.size()); logger.info("Splitting {} entities into {} partitions", entities.size(), np); long[] array = entities.toLongArray(); LongArrays.shuffle(array, rng); for (int i = 0; i < array.length; i++) { final long user = array[i]; emap.put(user, i % np); } return emap; }
@Override public InteractionStatistics get() { Long2IntOpenHashMap counts = new Long2IntOpenHashMap(); try (ObjectStream<Entity> stream = dao.query(entityType).stream()) { for (Entity e : stream) { long item = e.getLong(CommonAttributes.ITEM_ID); counts.addTo(item, 1); } } return new InteractionStatistics(entityType, counts); } }
@Override public InteractionStatistics get() { Long2IntOpenHashMap counts = new Long2IntOpenHashMap(); try (ObjectStream<Entity> stream = dao.query(entityType).stream()) { for (Entity e : stream) { long item = e.getLong(CommonAttributes.ITEM_ID); counts.addTo(item, e.getInteger(CommonAttributes.COUNT)); } } return new InteractionStatistics(entityType, counts); } }
/** * Creates an accumulator to process rating data and generate the necessary data for * a {@code SlopeOneItemScorer}. * * @param damping A damping term for deviation calculations. * @param items The set of known item IDs. */ public SlopeOneModelDataAccumulator(double damping, LongSet items) { this.damping = damping; workMatrix = new Long2ObjectOpenHashMap<>(items.size()); LongIterator iter = items.iterator(); while (iter.hasNext()) { long item = iter.nextLong(); workMatrix.put(item, Pair.<Long2DoubleMap, Long2IntMap>of(new Long2DoubleOpenHashMap(), new Long2IntOpenHashMap())); } }
@Override public Long2IntMap splitEntities(LongSet entities, int np, Random rng) { if (np * sampleSize > entities.size()) { logger.warn("cannot make {} disjoint samples of {} from {} entities, partitioning", np, sampleSize, entities.size()); return partition().splitEntities(entities, np, rng); } else { Long2IntMap emap = new Long2IntOpenHashMap(entities.size()); logger.info("Sampling {} entities into {} disjoint samples of {}", entities.size(), np, sampleSize); long[] earray = entities.toLongArray(); LongArrays.shuffle(earray, rng); for (int p = 0; p < np; p++) { for (int i = 0; i < sampleSize; i++) { long u = earray[p*sampleSize + i]; emap.put(u, p); } } return emap; } }
/** * Construct a new key index. It maps each long key to its position in the list. * * @param keys The list of keys to store. */ FrozenHashKeyIndex(LongList keys) { keyList = new LongArrayList(keys); indexMap = new Long2IntOpenHashMap(keys.size()); indexMap.defaultReturnValue(-1); LongListIterator iter = keys.listIterator(); while (iter.hasNext()) { int idx = iter.nextIndex(); long key = iter.next(); int old = indexMap.put(key, idx); if (old >= 0) { throw new IllegalArgumentException("key " + key + " appears multiple times"); } } }
/** * Compute the ranks for a list of longs. * @param results The list of longs. * @return The map of ranks; its default return value will be -1. */ public static Long2IntMap itemRanks(LongList results) { Long2IntMap ranks = new Long2IntOpenHashMap(results.size()); ranks.defaultReturnValue(-1); LongListIterator iter = results.listIterator(); while (iter.hasNext()) { int i = iter.nextIndex(); long val = iter.nextLong(); ranks.put(val, i); } return ranks; }
Long2IntMap imap = new Long2IntOpenHashMap(); imap.defaultReturnValue(-1); uiIndexes.put(uid, imap);
/** * Construct a new empty indexer. The first interned ID will have index 0. */ public HashKeyIndex() { indexMap = new Long2IntOpenHashMap(); indexMap.defaultReturnValue(-1); keyList = new LongArrayList(); }
/** * Construct a new key index with pre-built storage. */ FrozenHashKeyIndex(Long2IntMap indexes, LongList keys) { indexMap = new Long2IntOpenHashMap(indexes); indexMap.defaultReturnValue(-1); keyList = new LongArrayList(keys); }
@Override public InteractionStatistics get() { Long2IntOpenHashMap counts = new Long2IntOpenHashMap(); try (ObjectStream<Entity> stream = dao.query(entityType).stream()) { for (Entity e : stream) { long item = e.getLong(CommonAttributes.ITEM_ID); counts.addTo(item, 1); } } return new InteractionStatistics(entityType, counts); } }
@Override public InteractionStatistics get() { Long2IntOpenHashMap counts = new Long2IntOpenHashMap(); try (ObjectStream<Entity> stream = dao.query(entityType).stream()) { for (Entity e : stream) { long item = e.getLong(CommonAttributes.ITEM_ID); counts.addTo(item, e.getInteger(CommonAttributes.COUNT)); } } return new InteractionStatistics(entityType, counts); } }