it.unimi.dsi.fastutil.ints.Int2ObjectMap Java Examples
The following examples show how to use
it.unimi.dsi.fastutil.ints.Int2ObjectMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FixedLifespanScheduler.java From presto with Apache License 2.0 | 6 votes |
public FixedLifespanScheduler(BucketNodeMap bucketNodeMap, List<ConnectorPartitionHandle> partitionHandles, OptionalInt concurrentLifespansPerTask) { checkArgument(!partitionHandles.equals(ImmutableList.of(NOT_PARTITIONED))); checkArgument(partitionHandles.size() == bucketNodeMap.getBucketCount()); Map<InternalNode, IntList> nodeToDriverGroupMap = new HashMap<>(); Int2ObjectMap<InternalNode> driverGroupToNodeMap = new Int2ObjectOpenHashMap<>(); for (int bucket = 0; bucket < bucketNodeMap.getBucketCount(); bucket++) { InternalNode node = bucketNodeMap.getAssignedNode(bucket).get(); nodeToDriverGroupMap.computeIfAbsent(node, key -> new IntArrayList()).add(bucket); driverGroupToNodeMap.put(bucket, node); } this.driverGroupToNodeMap = driverGroupToNodeMap; this.nodeToDriverGroupsMap = nodeToDriverGroupMap.entrySet().stream() .collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().iterator())); this.partitionHandles = requireNonNull(partitionHandles, "partitionHandles is null"); if (concurrentLifespansPerTask.isPresent()) { checkArgument(concurrentLifespansPerTask.getAsInt() >= 1, "concurrentLifespansPerTask must be great or equal to 1 if present"); } this.concurrentLifespansPerTask = requireNonNull(concurrentLifespansPerTask, "concurrentLifespansPerTask is null"); }
Example #2
Source File: TextureUtil.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
protected void calculateLayerArrays() { Int2ObjectOpenHashMap<char[]> colorLayerMap = new Int2ObjectOpenHashMap<>(); for (int i = 0; i < validBlockIds.length; i++) { int color = validColors[i]; int combined = validBlockIds[i]; if (hasAlpha(color)) { for (int j = 0; j < validBlockIds.length; j++) { int colorOther = validColors[j]; if (!hasAlpha(colorOther)) { int combinedOther = validBlockIds[j]; int combinedColor = combineTransparency(color, colorOther); colorLayerMap.put(combinedColor, new char[]{(char) combined, (char) combinedOther}); } } } } this.validLayerColors = new int[colorLayerMap.size()]; this.validLayerBlocks = new char[colorLayerMap.size()][]; int index = 0; for (Int2ObjectMap.Entry<char[]> entry : colorLayerMap.int2ObjectEntrySet()) { validLayerColors[index] = entry.getIntKey(); validLayerBlocks[index++] = entry.getValue(); } }
Example #3
Source File: DimensionalConfigurationSchema.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
protected void buildNonCompositeAggregatorIDMap(String aggregatorName, FieldsDescriptor inputDescriptor, IntArrayList aggIDList, Int2ObjectMap<FieldsDescriptor> inputMap, Int2ObjectMap<FieldsDescriptor> outputMap) { IncrementalAggregator incrementalAggregator = aggregatorRegistry.getNameToIncrementalAggregator().get( aggregatorName); //don't need to build OTF aggregate if (incrementalAggregator == null) { return; } int aggregatorID = aggregatorRegistry.getIncrementalAggregatorNameToID().get(aggregatorName); mergeAggregatorID(aggIDList, aggregatorID); inputMap.put(aggregatorID, inputDescriptor); outputMap.put(aggregatorID, AggregatorUtils.getOutputFieldsDescriptor(inputDescriptor, incrementalAggregator)); }
Example #4
Source File: HybridMDEnforcer.java From metanome-algorithms with Apache License 2.0 | 6 votes |
private MDEnforcer build() { DictionaryRecords leftRecords = preprocessed.getLeftRecords(); DictionaryRecords rightRecords = preprocessed.getRightRecords(); Map<ColumnMapping<?>, PreprocessedColumnPair> columnPairs = getColumnPairs(); EnforcerFactory factory = EnforcerFactory.builder() .leftRecords(leftRecords) .rightRecords(rightRecords) .columnPairs(columnPairs) .build(); List<Dictionary<?>> leftDictionaries = preprocessed.getLeftDictionaries(); List<Int2ObjectMap<?>> leftInvertedDictionaries = invert(leftDictionaries); RecordInflater leftInflater = new RecordInflater(leftInvertedDictionaries); List<Dictionary<?>> rightDictionaries = preprocessed.getRightDictionaries(); List<Int2ObjectMap<?>> rightInvertedDictionaries = invert(rightDictionaries); RecordInflater rightInflater = new RecordInflater(rightInvertedDictionaries); return new HybridMDEnforcer(factory, leftInflater, rightInflater); }
Example #5
Source File: SlimUDTF.java From incubator-hivemall with Apache License 2.0 | 6 votes |
private static double predict(final int user, final int itemI, @Nonnull final Int2ObjectMap<Int2FloatMap> knnItems, final int excludeIndex, @Nonnull final FloatMatrix weightMatrix) { final Int2FloatMap kNNu = knnItems.get(user); if (kNNu == null) { return 0.d; } double pred = 0.d; for (Int2FloatMap.Entry e : Fastutil.fastIterable(kNNu)) { final int itemK = e.getIntKey(); if (itemK == excludeIndex) { continue; } float ruk = e.getFloatValue(); pred += ruk * weightMatrix.get(itemI, itemK, 0.d); } return pred; }
Example #6
Source File: SlimUDTF.java From incubator-hivemall with Apache License 2.0 | 6 votes |
private void replayTrain(@Nonnull final ByteBuffer buf) { final int itemI = buf.getInt(); final int knnSize = buf.getInt(); final Int2ObjectMap<Int2FloatMap> knnItems = new Int2ObjectOpenHashMap<>(1024); final IntSet pairItems = new IntOpenHashSet(); for (int i = 0; i < knnSize; i++) { int user = buf.getInt(); int ruSize = buf.getInt(); Int2FloatMap ru = new Int2FloatOpenHashMap(ruSize); ru.defaultReturnValue(0.f); for (int j = 0; j < ruSize; j++) { int itemK = buf.getInt(); pairItems.add(itemK); float ruk = buf.getFloat(); ru.put(itemK, ruk); } knnItems.put(user, ru); } for (int itemJ : pairItems) { train(itemI, knnItems, itemJ); } }
Example #7
Source File: ArrayMap.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override public ObjectSet<Int2ObjectMap.Entry<V>> int2ObjectEntrySet() { return entrySet != null ? entrySet : (entrySet = new AbstractObjectSet<Int2ObjectMap.Entry<V>>() { @Override @Nonnull public ObjectIterator<Int2ObjectMap.Entry<V>> iterator() { return new EntryIterator<Int2ObjectMap.Entry<V>>() { @Override public Int2ObjectMap.Entry<V> next() { return nextEntry(); } }; } @Override public int size() { return size; } }); }
Example #8
Source File: SlimUDTF.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Nonnull private static Int2ObjectMap<Int2FloatMap> kNNentries(@Nonnull final Object kNNiObj, @Nonnull final MapObjectInspector knnItemsOI, @Nonnull final PrimitiveObjectInspector knnItemsKeyOI, @Nonnull final MapObjectInspector knnItemsValueOI, @Nonnull final PrimitiveObjectInspector knnItemsValueKeyOI, @Nonnull final PrimitiveObjectInspector knnItemsValueValueOI, @Nullable Int2ObjectMap<Int2FloatMap> knnItems, @Nonnull final MutableInt nnzKNNi) { if (knnItems == null) { knnItems = new Int2ObjectOpenHashMap<>(1024); } else { knnItems.clear(); } int numElementOfKNNItems = 0; for (Map.Entry<?, ?> entry : knnItemsOI.getMap(kNNiObj).entrySet()) { int user = PrimitiveObjectInspectorUtils.getInt(entry.getKey(), knnItemsKeyOI); Int2FloatMap ru = int2floatMap(knnItemsValueOI.getMap(entry.getValue()), knnItemsValueKeyOI, knnItemsValueValueOI); knnItems.put(user, ru); numElementOfKNNItems += ru.size(); } nnzKNNi.setValue(numElementOfKNNItems); return knnItems; }
Example #9
Source File: AgreeSetGenerator.java From metanome-algorithms with Apache License 2.0 | 6 votes |
private void handleList(IntList list, Int2ObjectMap<Set<IntList>> maxSets, boolean firstStep) { for (int i = 0; i < list.size(); i++) { int removedElement = list.removeInt(i); if (maxSets.containsKey(list.size()) && maxSets.get(list.size()).contains(list)) maxSets.get(list.size()).remove(list); else { if (list.size() > 2) { this.handleList(list, maxSets, false); } } list.add(i, removedElement); } if (firstStep) maxSets.get(list.size()).add(list); }
Example #10
Source File: FastCollectionsUtils.java From fastjgame with Apache License 2.0 | 6 votes |
/** * 移除map中符合条件的元素,并对删除的元素执行后续的操作 * * @param map 必须是可修改的map * @param predicate 过滤条件,为真的删除 * @param then 元素删除之后执行的逻辑 * @param <V> the type of value * @return 删除的元素数量 */ public static <V> int removeIfAndThen(final Int2ObjectMap<V> map, final IntObjPredicate<? super V> predicate, IntObjConsumer<V> then) { if (map.size() == 0) { return 0; } ObjectIterator<Int2ObjectMap.Entry<V>> itr = map.int2ObjectEntrySet().iterator(); int removeNum = 0; Int2ObjectMap.Entry<V> entry; int k; V v; while (itr.hasNext()) { entry = itr.next(); k = entry.getIntKey(); v = entry.getValue(); if (predicate.test(k, v)) { itr.remove(); removeNum++; then.accept(k, v); } } return removeNum; }
Example #11
Source File: AgreeSetGenerator.java From metanome-algorithms with Apache License 2.0 | 6 votes |
private void calculateRelationship(StrippedPartition partitions, Int2ObjectMap<TupleEquivalenceClassRelation> relationships) { int partitionNr = 0; for (IntList partition : partitions.getValues()) { if (this.debugSysout) System.out.println("."); for (int index : partition) { if (!relationships.containsKey(index)) { relationships.put(index, new TupleEquivalenceClassRelation()); } relationships.get(index).addNewRelationship(partitions.getAttributeID(), partitionNr); } partitionNr++; } }
Example #12
Source File: DioriteRandomUtils.java From Diorite with MIT License | 6 votes |
@Nullable public static <T> T getWeightedRandomReversed(Random random, Int2ObjectMap<T> choices) { long i = 0; IntSet ints = choices.keySet(); for (IntIterator iterator = ints.iterator(); iterator.hasNext(); ) { int x = iterator.nextInt(); i += x; } i = getRandomLong(random, 0, i); for (Int2ObjectMap.Entry<T> entry : choices.int2ObjectEntrySet()) { i -= entry.getIntKey(); if (i < 0) { return entry.getValue(); } } return null; }
Example #13
Source File: BlockVectorSet.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
public Vector get(int index) { int count = 0; ObjectIterator<Int2ObjectMap.Entry<LocalBlockVectorSet>> iter = localSets.int2ObjectEntrySet().iterator(); while (iter.hasNext()) { Int2ObjectMap.Entry<LocalBlockVectorSet> entry = iter.next(); LocalBlockVectorSet set = entry.getValue(); int size = set.size(); int newSize = count + size; if (newSize > index) { int localIndex = index - count; Vector pos = set.getIndex(localIndex); if (pos != null) { int pair = entry.getIntKey(); int cx = MathMan.unpairX(pair); int cz = MathMan.unpairY(pair); pos.mutX((cx << 11) + pos.getBlockX()); pos.mutZ((cz << 11) + pos.getBlockZ()); return pos; } } count += newSize; } return null; }
Example #14
Source File: BlockVectorSet.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public Iterator<Vector> iterator() { final ObjectIterator<Int2ObjectMap.Entry<LocalBlockVectorSet>> entries = localSets.int2ObjectEntrySet().iterator(); if (!entries.hasNext()) { return new ArrayList<Vector>().iterator(); } return new Iterator<Vector>() { Int2ObjectMap.Entry<LocalBlockVectorSet> entry = entries.next(); Iterator<Vector> entryIter = entry.getValue().iterator(); MutableBlockVector mutable = new MutableBlockVector(); @Override public void remove() { entryIter.remove(); } @Override public boolean hasNext() { return entryIter.hasNext() || entries.hasNext(); } @Override public Vector next() { while (!entryIter.hasNext()) { if (!entries.hasNext()) { throw new NoSuchElementException("End of iterator"); } entry = entries.next(); entryIter = entry.getValue().iterator(); } Vector localPos = entryIter.next(); int pair = entry.getIntKey(); int cx = MathMan.unpairX(pair); int cz = MathMan.unpairY(pair); return mutable.setComponents((cx << 11) + localPos.getBlockX(), localPos.getBlockY(), (cz << 11) + localPos.getBlockZ()); } }; }
Example #15
Source File: SlimUDTF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
private void train(final int itemI, @Nonnull final Int2FloatMap ri, @Nonnull final Int2ObjectMap<Int2FloatMap> kNNi, final int itemJ, @Nonnull final Int2FloatMap rj) { final FloatMatrix W = _weightMatrix; final int N = rj.size(); if (N == 0) { return; } double gradSum = 0.d; double rateSum = 0.d; double lossSum = 0.d; for (Int2FloatMap.Entry e : Fastutil.fastIterable(rj)) { int user = e.getIntKey(); double ruj = e.getFloatValue(); double rui = ri.get(user); // ri.getOrDefault(user, 0.f); double eui = rui - predict(user, itemI, kNNi, itemJ, W); gradSum += ruj * eui; rateSum += ruj * ruj; lossSum += eui * eui; } gradSum /= N; rateSum /= N; double wij = W.get(itemI, itemJ, 0.d); double loss = lossSum / N + 0.5d * l2 * wij * wij + l1 * wij; _cvState.incrLoss(loss); W.set(itemI, itemJ, getUpdateTerm(gradSum, rateSum, l1, l2)); }
Example #16
Source File: ProtocolRegistry.java From ViaVersion with MIT License | 5 votes |
/** * Check if this plugin is useful to the server. * * @return True if there is a useful pipe */ public static boolean isWorkingPipe() { for (Int2ObjectMap<Protocol> map : registryMap.values()) { if (map.containsKey(SERVER_PROTOCOL)) return true; } return false; // No destination for protocol }
Example #17
Source File: SlimUDTF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
private void train(final int itemI, @Nonnull final Int2ObjectMap<Int2FloatMap> knnItems, final int itemJ) { final FloatMatrix A = _dataMatrix; final FloatMatrix W = _weightMatrix; final int N = A.numColumns(itemJ); if (N == 0) { return; } final MutableDouble mutableGradSum = new MutableDouble(0.d); final MutableDouble mutableRateSum = new MutableDouble(0.d); final MutableDouble mutableLossSum = new MutableDouble(0.d); A.eachNonZeroInRow(itemJ, new VectorProcedure() { @Override public void apply(int user, double ruj) { double rui = A.get(itemI, user, 0.d); double eui = rui - predict(user, itemI, knnItems, itemJ, W); mutableGradSum.addValue(ruj * eui); mutableRateSum.addValue(ruj * ruj); mutableLossSum.addValue(eui * eui); } }); double gradSum = mutableGradSum.getValue() / N; double rateSum = mutableRateSum.getValue() / N; double wij = W.get(itemI, itemJ, 0.d); double loss = mutableLossSum.getValue() / N + 0.5 * l2 * wij * wij + l1 * wij; _cvState.incrLoss(loss); W.set(itemI, itemJ, getUpdateTerm(gradSum, rateSum, l1, l2)); }
Example #18
Source File: LeftIndexedMultiSegmentBipartiteGraph.java From GraphJet with Apache License 2.0 | 5 votes |
protected Int2ObjectMap<T> getSegments() { // Hopefully branch prediction should make this really cheap as it'll always be false! if (crossMemoryBarrier() == -1) { return null; } return multiSegmentReaderAccessibleInfoProvider .getMultiSegmentReaderAccessibleInfo().getSegments(); }
Example #19
Source File: SegmentEdgeRandomAccessor.java From GraphJet with Apache License 2.0 | 5 votes |
SegmentEdgeRandomAccessor( MultiSegmentReaderAccessibleInfo<T> readerAccessibleInfo, Int2ObjectMap<ReusableInternalIdToLongIterator> segmentInternalIdToLongIteratorMap, Int2ObjectMap<ReusableNodeRandomIntIterator> segmentNodeRandomIntIteratorMap) { super(readerAccessibleInfo); this.segmentInternalIdToLongIteratorMap = segmentInternalIdToLongIteratorMap; this.segmentNodeRandomIntIteratorMap = segmentNodeRandomIntIteratorMap; }
Example #20
Source File: RightSegmentRandomEdgeAccessor.java From GraphJet with Apache License 2.0 | 5 votes |
RightSegmentRandomEdgeAccessor( MultiSegmentReaderAccessibleInfo<BipartiteGraphSegment> readerAccessibleInfo, Int2ObjectMap<ReusableInternalIdToLongIterator> segmentInternalIdToLongIteratorMap, Int2ObjectMap<ReusableNodeRandomIntIterator> segmentNodeRandomIntIteratorMap) { super(readerAccessibleInfo, segmentInternalIdToLongIteratorMap, segmentNodeRandomIntIteratorMap); }
Example #21
Source File: MultiSegmentReaderAccessibleInfo.java From GraphJet with Apache License 2.0 | 5 votes |
/** * A new instance is immediately visible to the readers due to publication safety. * * @param segments contains all the present segments * @param oldestSegmentId is the id of the oldest segment * @param liveSegmentId is the id of the live segment */ public MultiSegmentReaderAccessibleInfo( Int2ObjectMap<T> segments, int oldestSegmentId, int liveSegmentId) { this.segments = segments; this.oldestSegmentId = oldestSegmentId; this.liveSegmentId = liveSegmentId; }
Example #22
Source File: BlockVectorSet.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public boolean isEmpty() { for (Int2ObjectMap.Entry<LocalBlockVectorSet> entry : localSets.int2ObjectEntrySet()) { if (!entry.getValue().isEmpty()) { return false; } } return true; }
Example #23
Source File: LeftSegmentRandomEdgeAccessor.java From GraphJet with Apache License 2.0 | 5 votes |
LeftSegmentRandomEdgeAccessor( MultiSegmentReaderAccessibleInfo<T> readerAccessibleInfo, Int2ObjectMap<ReusableInternalIdToLongIterator> segmentInternalIdToLongIteratorMap, Int2ObjectMap<ReusableNodeRandomIntIterator> segmentNodeRandomIntIteratorMap) { super(readerAccessibleInfo, segmentInternalIdToLongIteratorMap, segmentNodeRandomIntIteratorMap); }
Example #24
Source File: CustomTimeBucketRegistry.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
public CustomTimeBucketRegistry(Int2ObjectMap<CustomTimeBucket> idToTimeBucket, int startingId) { int tempId = initialize(idToTimeBucket); Preconditions.checkArgument(tempId < startingId, "The statingId " + startingId + " must be larger than the largest ID " + tempId + " in the given idToTimeBucket mapping"); this.idToTimeBucket = Preconditions.checkNotNull(idToTimeBucket); this.currentId = startingId; }
Example #25
Source File: AgreeSetGenerator.java From metanome-algorithms with Apache License 2.0 | 5 votes |
private Set<IntList> mergeResult(Int2ObjectMap<Set<IntList>> maxSets) { Set<IntList> max = new HashSet<IntList>(); for (Set<IntList> set : maxSets.values()) { max.addAll(set); } return max; }
Example #26
Source File: PositionListIndex.java From winter with Apache License 2.0 | 5 votes |
public PositionListIndex intersect(int[] otherPLI) { Int2ObjectMap<Int2ObjectMap<IntArrayList>> intersectMap = this.buildIntersectMap(otherPLI); List<IntArrayList> clusters = new ArrayList<>(); for (Int2ObjectMap<IntArrayList> cluster1 : intersectMap.values()) for (IntArrayList cluster2 : cluster1.values()) if (cluster2.size() > 1) clusters.add(cluster2); return new PositionListIndex(-1, clusters); }
Example #27
Source File: PositionListIndex.java From metanome-algorithms with Apache License 2.0 | 5 votes |
public PositionListIndex intersect(int[] otherPLI) { Int2ObjectMap<Int2ObjectMap<IntArrayList>> intersectMap = this.buildIntersectMap(otherPLI); List<IntArrayList> clusters = new ArrayList<>(); for (Int2ObjectMap<IntArrayList> cluster1 : intersectMap.values()) for (IntArrayList cluster2 : cluster1.values()) if (cluster2.size() > 1) clusters.add(cluster2); return new PositionListIndex(-1, clusters); }
Example #28
Source File: AgreeSetGenerator.java From metanome-algorithms with Apache License 2.0 | 5 votes |
public Int2ObjectMap<TupleEquivalenceClassRelation> calculateRelationships(List<StrippedPartition> partitions) { if (this.debugSysout) { System.out.println("\tstartet calculation of relationships"); } Int2ObjectMap<TupleEquivalenceClassRelation> relationships = new Int2ObjectOpenHashMap<TupleEquivalenceClassRelation>(); for (StrippedPartition p : partitions) { this.calculateRelationship(p, relationships); } return relationships; }
Example #29
Source File: AgreeSetGenerator.java From metanome-algorithms with Apache License 2.0 | 5 votes |
private IntersectWithAndAddToAgreeSetTask(int i, int j, IntList maxEquiClass, Int2ObjectMap<TupleEquivalenceClassRelation> relationships, Map<AgreeSet, Object> agreeSets) { this.i = i; this.j = j; this.maxEquiClass = maxEquiClass; this.relationships = relationships; this.agreeSets = agreeSets; }
Example #30
Source File: AgreeSetGenerator.java From metanome-algorithms with Apache License 2.0 | 5 votes |
private void handlePartition(IntList actuelList, int position, Int2ObjectMap<IntSet> index, Set<IntList> max) { if (!this.isSubset(actuelList, index)) { max.add(actuelList); for (int e : actuelList) { if (!index.containsKey(e)) { index.put(e, new IntArraySet()); } index.get(e).add(position); } } }