Java Code Examples for it.unimi.dsi.fastutil.ints.IntIterator#nextInt()
The following examples show how to use
it.unimi.dsi.fastutil.ints.IntIterator#nextInt() .
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: 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 2
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 3
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 4
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 5
Source File: TimeColumn.java From tablesaw with Apache License 2.0 | 5 votes |
@Override public TimeColumn removeMissing() { TimeColumn noMissing = emptyCopy(); IntIterator iterator = intIterator(); while (iterator.hasNext()) { int i = iterator.nextInt(); if (!valueIsMissing(i)) { noMissing.appendInternal(i); } } return noMissing; }
Example 6
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 7
Source File: SetSimilarity.java From RankSys with Mozilla Public License 2.0 | 5 votes |
private int[] getFasterIntersectionArray(int uidx) { int[] intersectionMap = new int[data.numUsers()]; IntIterator iidxs = data.getUidxIidxs(uidx); while (iidxs.hasNext()) { IntIterator vidxs = data.getIidxUidxs(iidxs.nextInt()); while (vidxs.hasNext()) { intersectionMap[vidxs.nextInt()]++; } } intersectionMap[uidx] = 0; return intersectionMap; }
Example 8
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 9
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 10
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 11
Source File: DateColumn.java From tablesaw with Apache License 2.0 | 5 votes |
@Override public DateColumn removeMissing() { DateColumn noMissing = emptyCopy(); IntIterator iterator = intIterator(); while (iterator.hasNext()) { int i = iterator.nextInt(); if (!valueIsMissing(i)) { noMissing.appendInternal(i); } } return noMissing; }
Example 12
Source File: TimeColumn.java From tablesaw with Apache License 2.0 | 5 votes |
@Override public TimeColumn removeMissing() { TimeColumn noMissing = emptyCopy(); IntIterator iterator = intIterator(); while (iterator.hasNext()) { int i = iterator.nextInt(); if (!valueIsMissing(i)) { noMissing.appendInternal(i); } } return noMissing; }
Example 13
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 14
Source File: SparseDataSet.java From hlta with GNU General Public License v3.0 | 5 votes |
private DataSet SparseToDense(int batchSize, int start){ if(isRandomised == false){ randomiseDatacaseIndex(); } /* * convert from sparse to dense */ // create a dataset over variables corresponding to the external IDs DataSet Dense = new DataSet(_VariablesSet); // adding datacases for(int i = start ; i < batchSize + start ; i++){ int[] states = new int[_VariablesSet.length]; IntCollection row = SDataSet.userMatrix().get(_randomToOriginalDataCaseIndexMap.get(i)); // Filling in the positive entries IntIterator iter = row.iterator(); while(iter.hasNext()){ int internal_ID = iter.nextInt(); // the id of the item String name = _item_mapping.toOriginalID(internal_ID); states[_mapNameToIndex.get(name)] = 1; } Dense.addDataCase(states, 1); } return Dense; }
Example 15
Source File: CustomHashMap.java From kourami with BSD 3-Clause "New" or "Revised" License | 5 votes |
public boolean intersection(CustomHashMap other){ boolean modified = false; IntIterator itr = this.keySet().iterator(); while(itr.hasNext()){ int curInt = itr.nextInt(); if(!other.containsKey(curInt)){ itr.remove(); modified = false; } } return modified; }
Example 16
Source File: UnaryInverseDocumentFrequency.java From jstarcraft-ai with Apache License 2.0 | 5 votes |
public UnaryInverseDocumentFrequency(Int2FloatMap keyValues, Iterator<TermFrequency> documents) { super(keyValues); while (documents.hasNext()) { TermFrequency document = documents.next(); IntIterator iterator = document.getKeys().iterator(); while (iterator.hasNext()) { int term = iterator.nextInt(); keyValues.put(term, 1F); } } }
Example 17
Source File: UnaryInverseDocumentFrequency.java From jstarcraft-ai with Apache License 2.0 | 5 votes |
public UnaryInverseDocumentFrequency(Int2FloatMap keyValues, Collection<TermFrequency> documents) { super(keyValues); for (TermFrequency document : documents) { IntIterator iterator = document.getKeys().iterator(); while (iterator.hasNext()) { int term = iterator.nextInt(); keyValues.put(term, 1F); } } }
Example 18
Source File: UnaryInverseDocumentFrequency.java From jstarcraft-ai with Apache License 2.0 | 5 votes |
public UnaryInverseDocumentFrequency(Int2FloatMap keyValues, TermFrequency... documents) { super(keyValues); for (TermFrequency document : documents) { IntIterator iterator = document.getKeys().iterator(); while (iterator.hasNext()) { int term = iterator.nextInt(); keyValues.put(term, 1F); } } }
Example 19
Source File: Path.java From kourami with BSD 3-Clause "New" or "Revised" License | 4 votes |
public PathBaseErrorProb getBaseErrorProbMatrix(SimpleDirectedWeightedGraph<Node, CustomWeightedEdge> g){ //updated with +1 to include the start base of the bubble. PathBaseErrorProb eProbMatrix = new PathBaseErrorProb(this.readset.size(), this.getPathLength() + 1); //for each position (edge) for(int j=-1; j<this.orderedEdgeList.size(); j++){ CustomWeightedEdge cur; CustomHashMap curEdgeReadSet; char curChar; if(j<0){ cur = this.orderedEdgeList.get(0); curEdgeReadSet = new CustomHashMap();//empty curChar = g.getEdgeSource(cur).getBase(); eProbMatrix.addPathBases(curChar, j+1); }else{ cur = this.orderedEdgeList.get(j); curEdgeReadSet = cur.getReadHashSet(); curChar = g.getEdgeTarget(cur).getBase(); eProbMatrix.addPathBases(curChar,j+1); } /* CustomWeightedEdge cur = this.orderedEdgeList.get(j); CustomHashMap curEdgeReadSet = cur.getReadHashSet(); char curChar = g.getEdgeTarget(cur).getBase(); eProbMatrix.addPathBases(curChar, j); */ /* for each read */ int i = 0; IntIterator itr = this.readset.keySet().iterator(); while(itr.hasNext()){ int curReadID = itr.nextInt(); int qual = 15;//set it as 15 for unknown //if(this.readset.containsKey(curReadID)) if(curEdgeReadSet.containsKey(curReadID)) qual = curEdgeReadSet.get(curReadID); //else{ //HLA.log.appendln("NO READ COVERAGE"); //} //int qual = this.readset.get(curReadID); //if(qual == -1) // qual = 15; double errorProb = QualityUtil.getErrorProbabilityFromPhredScore(qual); eProbMatrix.add(errorProb, i, j+1); i++; } } return eProbMatrix; }
Example 20
Source File: GroupedTopNBuilder.java From presto with Apache License 2.0 | 4 votes |
private void processPage(Page newPage, GroupByIdBlock groupIds) { checkArgument(newPage != null); checkArgument(groupIds != null); // save the new page PageReference newPageReference = new PageReference(newPage); int newPageId; if (emptyPageReferenceSlots.isEmpty()) { // all the previous slots are full; create a new one pageReferences.ensureCapacity(currentPageCount + 1); newPageId = currentPageCount; currentPageCount++; } else { // reuse a previously removed page's slot newPageId = emptyPageReferenceSlots.dequeueInt(); } verify(pageReferences.get(newPageId) == null, "should not overwrite a non-empty slot"); pageReferences.set(newPageId, newPageReference); // update the affected heaps and record candidate pages that need compaction IntSet pagesToCompact = new IntOpenHashSet(); for (int position = 0; position < newPage.getPositionCount(); position++) { long groupId = groupIds.getGroupId(position); groupedRows.ensureCapacity(groupId + 1); RowHeap rows = groupedRows.get(groupId); if (rows == null) { // a new group rows = new RowHeap(Ordering.from(comparator).reversed()); groupedRows.set(groupId, rows); } else { // update an existing group; // remove the memory usage for this group for now; add it back after update memorySizeInBytes -= rows.getEstimatedSizeInBytes(); } if (rows.size() < topN) { // still have space for the current group Row row = new Row(newPageId, position); rows.enqueue(row); newPageReference.reference(row); } else { // may compare with the topN-th element with in the heap to decide if update is necessary Row previousRow = rows.first(); Row newRow = new Row(newPageId, position); if (comparator.compare(newRow, previousRow) < 0) { // update reference and the heap rows.dequeue(); PageReference previousPageReference = pageReferences.get(previousRow.getPageId()); previousPageReference.dereference(previousRow.getPosition()); newPageReference.reference(newRow); rows.enqueue(newRow); // compact a page if it is not the current input page and the reference count is below the threshold if (previousPageReference.getPage() != newPage && previousPageReference.getUsedPositionCount() * COMPACT_THRESHOLD < previousPageReference.getPage().getPositionCount()) { pagesToCompact.add(previousRow.getPageId()); } } } memorySizeInBytes += rows.getEstimatedSizeInBytes(); } // unreference new page if it was not used if (newPageReference.getUsedPositionCount() == 0) { pageReferences.set(newPageId, null); } else { // assure new page is loaded newPageReference.loadPage(); memorySizeInBytes += newPageReference.getEstimatedSizeInBytes(); // may compact the new page as well if (newPageReference.getUsedPositionCount() * COMPACT_THRESHOLD < newPage.getPositionCount()) { verify(!pagesToCompact.contains(newPageId)); pagesToCompact.add(newPageId); } } // compact pages IntIterator iterator = pagesToCompact.iterator(); while (iterator.hasNext()) { int pageId = iterator.nextInt(); PageReference pageReference = pageReferences.get(pageId); if (pageReference.getUsedPositionCount() == 0) { pageReferences.set(pageId, null); emptyPageReferenceSlots.enqueue(pageId); memorySizeInBytes -= pageReference.getEstimatedSizeInBytes(); } else { memorySizeInBytes -= pageReference.getEstimatedSizeInBytes(); pageReference.compact(); memorySizeInBytes += pageReference.getEstimatedSizeInBytes(); } } }