it.unimi.dsi.fastutil.ints.IntIterator Java Examples
The following examples show how to use
it.unimi.dsi.fastutil.ints.IntIterator.
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: VectorSimilarity.java From RankSys with Mozilla Public License 2.0 | 6 votes |
private double[] getProductArray(int uidx) { double[] productArray = new double[data.numUsers()]; if (data.useIteratorsPreferentially()) { IntIterator iidxs = data.getUidxIidxs(uidx); DoubleIterator ivs = data.getUidxVs(uidx); while (iidxs.hasNext()) { int iidx = iidxs.nextInt(); double iv = ivs.nextDouble(); IntIterator vidxs = data.getIidxUidxs(iidx); DoubleIterator vvs = data.getIidxVs(iidx); while (vidxs.hasNext()) { productArray[vidxs.nextInt()] += iv * vvs.nextDouble(); } } } else { data.getUidxPreferences(uidx) .forEach(ip -> data.getIidxPreferences(ip.v1) .forEach(up -> productArray[up.v1] += ip.v2 * up.v2)); } productArray[uidx] = 0.0; return productArray; }
Example #2
Source File: NormalRepresentation.java From zetasketch with Apache License 2.0 | 6 votes |
@Override public NormalRepresentation addSparseValues( Encoding.Sparse encoding, @Nullable IntIterator sparseValues) { NormalRepresentation repr = maybeDowngrade(encoding.normal(), encoding.sparsePrecision); if (sparseValues == null) { return repr; } // Add each sparse value to our backing array, downgrading it if necessary. byte[] data = getWriteableData(state); while (sparseValues.hasNext()) { addSparseValueMaybeDowngrading(data, repr.encoding, sparseValues.nextInt(), encoding); } return repr; }
Example #3
Source File: DateColumn.java From tablesaw with Apache License 2.0 | 6 votes |
/** * Returns an iterator over elements of type {@code T}. * * @return an Iterator. */ @Override public Iterator<LocalDate> iterator() { return new Iterator<LocalDate>() { final IntIterator intIterator = intIterator(); @Override public boolean hasNext() { return intIterator.hasNext(); } @Override public LocalDate next() { return PackedLocalDate.asLocalDate(intIterator.nextInt()); } }; }
Example #4
Source File: SparseRepresentation.java From zetasketch with Apache License 2.0 | 6 votes |
/** Sets the representation's values from {@code iter}. */ private void set(@Nullable IntIterator iter) { GrowingByteSlice slice = getRecycledData(); DifferenceEncoder encoder = new DifferenceEncoder(slice); int size = 0; while (iter != null && iter.hasNext()) { encoder.putInt(iter.nextInt()); size++; } buffer.clear(); recycledData = new WeakReference<>(state.sparseData); state.sparseData = slice.flip(); state.sparseSize = size; }
Example #5
Source File: SparseRepresentation.java From zetasketch with Apache License 2.0 | 6 votes |
/** * Returns an iterator over the sorted (but not de-duplicated) values of the difference encoded * data and the temporary buffer, or {@code null} if both are empty. */ @Nullable private IntIterator sortedIterator() { IntIterator a = dataIterator(); IntIterator b = bufferIterator(); if (a != null && b != null) { return new MergedIntIterator(a, b); } if (b != null) { return b; } return a; }
Example #6
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 #7
Source File: SparseRepresentation.java From zetasketch with Apache License 2.0 | 6 votes |
private Representation downgrade(Encoding.Sparse encoding) { if (!encoding.isLessThan(this.encoding)) { return this; } GrowingByteSlice originalData = state.sparseData; state.sparseData = null; state.precision = Math.min(this.encoding.normalPrecision, encoding.normalPrecision); state.sparsePrecision = Math.min(this.encoding.sparsePrecision, encoding.sparsePrecision); Representation repr = new SparseRepresentation(state); // Add values from the backing data and from the buffer. if (originalData != null && originalData.hasRemaining()) { IntIterator iter = this.encoding.downgrade(new DifferenceDecoder(originalData), encoding); repr = addUnsortedSparseValues(repr, encoding, iter); } repr = addUnsortedSparseValues(repr, encoding, this.bufferIterator()); return repr; }
Example #8
Source File: InternalIdToLongIteratorTest.java From GraphJet with Apache License 2.0 | 6 votes |
@Test public void testInternalIdToLongIterator() { LongToInternalIntBiMap nodesToIndexBiMap = new ArrayBasedLongToInternalIntBiMap(10, 0.5, -1, -1L, nullStatsReceiver); int n = 7; int[] expectedIndices = new int[n]; long[] expectedEntries = new long[n]; for (int i = 0; i < n; i++) { expectedIndices[i] = nodesToIndexBiMap.put(i); expectedEntries[i] = (long) i; } IntIterator intIterator = new IntArrayList(expectedIndices).iterator(); InternalIdToLongIterator internalIdToLongIterator = new InternalIdToLongIterator(nodesToIndexBiMap, new IdentityEdgeTypeMask()); internalIdToLongIterator.resetWithIntIterator(new WithEdgeMetadataIntIteratorImpl(intIterator)); assertEquals(new LongArrayList(expectedEntries), new LongArrayList(internalIdToLongIterator)); }
Example #9
Source File: SawWriter.java From tablesaw with Apache License 2.0 | 6 votes |
private static void writeColumn(String fileName, IntColumn column) throws IOException { try (FileOutputStream fos = new FileOutputStream(fileName); SnappyFramedOutputStream sos = new SnappyFramedOutputStream(fos); DataOutputStream dos = new DataOutputStream(sos)) { int i = 0; IntIterator iterator = (IntIterator) column.iterator(); while (iterator.hasNext()) { dos.writeInt(iterator.nextInt()); i++; if (i == FLUSH_AFTER_ITERATIONS) { // TODO does this break the pipelining? dos.flush(); i = 0; } } dos.flush(); } }
Example #10
Source File: DifferenceDecoderTest.java From zetasketch with Apache License 2.0 | 6 votes |
@Test public void next_DecodesIntegers() { IntIterator iter = new DifferenceDecoder(GrowingByteSlice.copyOnWrite(varints( 42, 170 - 42, 2903 - 170, 20160531 - 2903 ))); assertTrue(iter.hasNext()); assertEquals(42, iter.nextInt()); assertTrue(iter.hasNext()); assertEquals(170, iter.nextInt()); assertTrue(iter.hasNext()); assertEquals(2903, iter.nextInt()); assertTrue(iter.hasNext()); assertEquals(20160531, iter.nextInt()); assertFalse(iter.hasNext()); }
Example #11
Source File: TimeColumn.java From tablesaw with Apache License 2.0 | 6 votes |
/** * Returns an iterator over elements of type {@code T}. * * @return an Iterator. */ @Override public Iterator<LocalTime> iterator() { return new Iterator<LocalTime>() { final IntIterator intIterator = intIterator(); @Override public boolean hasNext() { return intIterator.hasNext(); } @Override public LocalTime next() { return PackedLocalTime.asLocalTime(intIterator.nextInt()); } }; }
Example #12
Source File: FastCollectionsUtils.java From fastjgame with Apache License 2.0 | 6 votes |
/** * 移除map中符合条件的元素,并对删除的元素执行后续的操作。 * * @param collection 必须是可修改的集合 * @param predicate 过滤条件,为真的删除 * @param then 元素删除之后执行的逻辑 * @return 删除的元素数量 */ public static int removeIfAndThen(IntCollection collection, IntPredicate predicate, IntConsumer then) { if (collection.size() == 0) { return 0; } final IntIterator itr = collection.iterator(); int value; int removeNum = 0; while (itr.hasNext()) { value = itr.nextInt(); if (predicate.test(value)) { itr.remove(); removeNum++; then.accept(value); } } return removeNum; }
Example #13
Source File: VectorSimilarity.java From RankSys with Mozilla Public License 2.0 | 6 votes |
private Int2DoubleMap getProductMap(int uidx) { Int2DoubleOpenHashMap productMap = new Int2DoubleOpenHashMap(); productMap.defaultReturnValue(0.0); if (data.useIteratorsPreferentially()) { IntIterator iidxs = data.getUidxIidxs(uidx); DoubleIterator ivs = data.getUidxVs(uidx); while (iidxs.hasNext()) { int iidx = iidxs.nextInt(); double iv = ivs.nextDouble(); IntIterator vidxs = data.getIidxUidxs(iidx); DoubleIterator vvs = data.getIidxVs(iidx); while (vidxs.hasNext()) { productMap.addTo(vidxs.nextInt(), iv * vvs.nextDouble()); } } } else { data.getUidxPreferences(uidx) .forEach(ip -> data.getIidxPreferences(ip.v1) .forEach(up -> productMap.addTo(up.v1, ip.v2 * up.v2))); } productMap.remove(uidx); return productMap; }
Example #14
Source File: SawWriter.java From tablesaw with Apache License 2.0 | 6 votes |
private static void writeColumn(String fileName, TimeColumn column) throws IOException { try (FileOutputStream fos = new FileOutputStream(fileName); SnappyFramedOutputStream sos = new SnappyFramedOutputStream(fos); DataOutputStream dos = new DataOutputStream(sos)) { int i = 0; IntIterator iterator = column.intIterator(); while (iterator.hasNext()) { dos.writeInt(iterator.nextInt()); i++; if (i == FLUSH_AFTER_ITERATIONS) { dos.flush(); i = 0; } } dos.flush(); } }
Example #15
Source File: SawWriter.java From tablesaw with Apache License 2.0 | 6 votes |
private static void writeColumn(String fileName, DateColumn column) throws IOException { try (FileOutputStream fos = new FileOutputStream(fileName); SnappyFramedOutputStream sos = new SnappyFramedOutputStream(fos); DataOutputStream dos = new DataOutputStream(sos)) { int i = 0; IntIterator iterator = column.intIterator(); while (iterator.hasNext()) { dos.writeInt(iterator.nextInt()); i++; if (i == FLUSH_AFTER_ITERATIONS) { dos.flush(); i = 0; } } dos.flush(); } }
Example #16
Source File: SawWriter.java From tablesaw with Apache License 2.0 | 6 votes |
private static void writeColumn(String fileName, IntColumn column) throws IOException { try (FileOutputStream fos = new FileOutputStream(fileName); SnappyFramedOutputStream sos = new SnappyFramedOutputStream(fos); DataOutputStream dos = new DataOutputStream(sos)) { int i = 0; IntIterator iterator = (IntIterator) column.iterator(); while (iterator.hasNext()) { dos.writeInt(iterator.nextInt()); i++; if (i == FLUSH_AFTER_ITERATIONS) { // TODO does this break the pipelining? dos.flush(); i = 0; } } dos.flush(); } }
Example #17
Source File: CustomHashMap.java From kourami with BSD 3-Clause "New" or "Revised" License | 6 votes |
public boolean intersectionPE(CustomHashMap other){ boolean modified = false; IntIterator itr = this.keySet().iterator(); while(itr.hasNext()){ int key = itr.nextInt(); int keyInv = 0 - key; if(!other.containsKey(key) && !other.containsKey(keyInv)){ itr.remove(); modified = true; } } for(int otherKey : other.keySet()){ int otherKeyInv = 0-otherKey; boolean intst = this.containsKey(otherKey); //does this contain otherKey? boolean intstPrime = this.containsKey(otherKeyInv); //does this contain -(otherkey)? if(!intst && intstPrime){ this.put(otherKey, other.get(otherKey)); modified = true; } } return modified; }
Example #18
Source File: StandaloneExp.java From data-polygamy with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Attribute createNewAttribute(HashMap<String, Attribute> attributes, String attribute, int noMonths) { Attribute a = attributes.get(attribute); int ct = 0; IntSet keys = a.data.keySet(); IntIterator it = keys.iterator(); ArrayList<SpatioTemporalVal> arr = new ArrayList<SpatioTemporalVal>(); while(ct < noMonths) { if(!it.hasNext()) { Utilities.er("no. of months is greater than what is present"); } int month = it.nextInt(); arr.addAll(a.data.get(month)); ct++; } Collections.sort(arr); Attribute na = new Attribute(); na.data.put(0, arr); na.nodeSet = a.nodeSet; return na; }
Example #19
Source File: Anchor.java From tagme with Apache License 2.0 | 6 votes |
/** * Iterates pages sorted by their commonness * @return */ public IntIterator pages() { return new IntIterator() { int idx=0; @Override public void remove() {throw new UnsupportedOperationException();} @Override public Integer next() { return nextInt(); } @Override public boolean hasNext() { return idx < (q==null? 1 : q.length); } @Override public int skip(int offset) {throw new UnsupportedOperationException();} @Override public int nextInt() { if (idx >= (q==null? 1 : q.length)) throw new IllegalArgumentException(); idx++; return q==null? p : q[idx-1]; } }; }
Example #20
Source File: DateColumn.java From tablesaw with Apache License 2.0 | 6 votes |
/** * Returns an iterator over elements of type {@code T}. * * @return an Iterator. */ @Override public Iterator<LocalDate> iterator() { return new Iterator<LocalDate>() { final IntIterator intIterator = intIterator(); @Override public boolean hasNext() { return intIterator.hasNext(); } @Override public LocalDate next() { return PackedLocalDate.asLocalDate(intIterator.nextInt()); } }; }
Example #21
Source File: NodeMetadataInternalIdToLongIterator.java From GraphJet with Apache License 2.0 | 5 votes |
@Override public IntIterator getRightNodeMetadata(byte nodeMetadataType) { IntIterator metadataIterator = metadataIterators[nodeMetadataType]; if (metadataIterator == null) { metadataIterator = metadataMap.get(nodeMetadataType).get(edgeTypeMask.restore(currentNodeId)); metadataIterators[nodeMetadataType] = metadataIterator; } else { metadataIterator = metadataMap.get(nodeMetadataType).get( edgeTypeMask.restore(currentNodeId), (IntArrayIterator) metadataIterator ); } return metadataIterator; }
Example #22
Source File: PositiveOnlyFeedback.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nonnull public int[] getUsers() { final int size = rows.size(); final int[] keys = new int[size]; final IntIterator itor = rows.keySet().iterator(); for (int i = 0; i < size; i++) { if (!itor.hasNext()) { throw new IllegalStateException(); } int key = itor.nextInt(); keys[i] = key; } return keys; }
Example #23
Source File: SparseMatrix.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public int nonZeroElements() { int res = 0; IntIterator rowIter = indexesMap().keySet().iterator(); while (rowIter.hasNext()) { int row = rowIter.nextInt(); res += indexesMap().get(row).size(); } return res; }
Example #24
Source File: AbstractRegularDegreeEdgePool.java From GraphJet with Apache License 2.0 | 5 votes |
@Override public IntIterator getRandomNodeEdges( int node, int numSamples, Random random, ReusableNodeRandomIntIterator regularDegreeEdgeRandomIterator) { return regularDegreeEdgeRandomIterator.resetForNode(node, numSamples, random); }
Example #25
Source File: DateFilters.java From tablesaw with Apache License 2.0 | 5 votes |
/** * This version operates on predicates that treat the given IntPredicate as operating on a packed * local time This is much more efficient that using a LocalTimePredicate, but requires that the * developer understand the semantics of packedLocalTimes */ default Selection eval(IntPredicate predicate) { Selection selection = new BitmapBackedSelection(); IntIterator iterator = intIterator(); int idx = 0; while (iterator.hasNext()) { int next = iterator.nextInt(); if (predicate.test(next)) { selection.add(idx); } idx++; } return selection; }
Example #26
Source File: NodeMetadataInternalIdToLongIterator.java From GraphJet with Apache License 2.0 | 5 votes |
/** * This constructor is to map internal integer ids back to longs, and it allows node metadata * access. * * @param nodesIndexMap is the map from integer ids to longs * @param metadataMap is the map from node metadata types to node metadata * @param edgeTypeMask is the edge type between LHS node and RHS node */ public NodeMetadataInternalIdToLongIterator( LongToInternalIntBiMap nodesIndexMap, List<IntToIntArrayMap> metadataMap, EdgeTypeMask edgeTypeMask ) { this.nodesIndexMap = nodesIndexMap; this.metadataMap = metadataMap; this.edgeTypeMask = edgeTypeMask; this.currentNodeId = 0; this.metadataIterators = new IntIterator[metadataMap.size()]; }
Example #27
Source File: SQLPreferenceData.java From RankSys with Mozilla Public License 2.0 | 5 votes |
@Override public IntIterator getUidxIidxs(int uidx) { return new StreamIntIterator(dsl .select(IIDX) .from(DATA) .where(UIDX.eq(uidx)) .fetch().stream() .mapToInt(Record1::value1)); }
Example #28
Source File: AbstractOptimizedEdgePool.java From GraphJet with Apache License 2.0 | 5 votes |
@Override public IntIterator getRandomNodeEdges( int node, int numSamples, Random random, ReusableNodeRandomIntIterator optimizedEdgeRandomIterator) { return optimizedEdgeRandomIterator.resetForNode(node, numSamples, random); }
Example #29
Source File: DateFilters.java From tablesaw with Apache License 2.0 | 5 votes |
default Selection eval(IntBiPredicate predicate, int value) { Selection selection = new BitmapBackedSelection(); IntIterator iterator = intIterator(); int idx = 0; while (iterator.hasNext()) { int next = iterator.nextInt(); if (predicate.test(next, value)) { selection.add(idx); } idx++; } return selection; }
Example #30
Source File: CustomHashMap.java From kourami with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void printKeys(){ IntIterator itr = this.keySet().iterator(); HLA.log.append("{"); if(this.size() > 0) HLA.log.append(itr.nextInt()); while(itr.hasNext()) HLA.log.append("," + itr.nextInt()); HLA.log.appendln("}"); }