@Override public void print(PrintStream os, Module m) { os.println("**************** Intervals ******************"); TIntObjectIterator<LiveInterval> itr = slot2LI.iterator(); while (itr.hasNext()) { int slot = itr.key(); LiveInterval interval = itr.value(); interval.print(os, null); TargetRegisterClass rc = getIntervalRegClass(slot); if (rc != null) { os.printf("[%s]\n", rc.getName()); } else { os.println("[unknown]"); } } }
public void testIteratorRemoval2() { int element_count = 10000; int remaining = element_count / 2; TIntObjectHashMap<String> map = new TIntObjectHashMap<String>( element_count, 0.5f, Integer.MIN_VALUE ); for ( int pass = 0; pass < 10; pass++ ) { Random r = new Random(); for ( int i = 0; i <= element_count; i++ ) { map.put( Integer.valueOf( r.nextInt() ), String.valueOf( i ) ); } TIntObjectIterator iterator = map.iterator(); while ( map.size() > remaining && iterator.hasNext() ) { iterator.advance(); iterator.remove(); } } }
@Override public void process(@Nonnull final EntityPlayer player) { if (this.messages.size() == 0) return; // Go through the cached messages and get rid of those // that expire. final int currentTick = EnvironState.getTickCounter(); final TIntObjectIterator<EntityBubbleContext> entityData = this.messages.iterator(); while (entityData.hasNext()) { entityData.advance(); final EntityBubbleContext ctx = entityData.value(); if (ctx.clean(currentTick)) entityData.remove(); } }
public void writeTopKBounds(MultipleOutputs<?, ?> sideOutputs, String outputName, String path, int minsup) throws IOException, InterruptedException { final IntWritable itemW = new IntWritable(); final IntWritable boundW = new IntWritable(); TIntObjectIterator<PatternWithFreq[]> it = this.topK.iterator(); while (it.hasNext()) { it.advance(); if (it.value()[this.k - 1] != null) { final int supportCount = it.value()[this.k - 1].getSupportCount(); if (supportCount > minsup) { itemW.set(it.key()); boundW.set(supportCount); sideOutputs.write(outputName, itemW, boundW, path); } } } }
/** * @see infoMode */ private void collectItemStats() { TIntObjectIterator<PatternWithFreq[]> iterator = this.topK.iterator(); while (iterator.hasNext()) { iterator.advance(); int item = iterator.key(); PatternWithFreq[] itemTopK = iterator.value(); int nbPatterns = 0; int supportSum = 0; while (nbPatterns < this.k && itemTopK[nbPatterns] != null) { supportSum += itemTopK[nbPatterns].getSupportCount(); nbPatterns++; } int lowestSupport = itemTopK[nbPatterns - 1].getSupportCount(); if (itemTopK[0] != null) { this.decorated.collect(itemTopK[0].getSupportCount(), new int[] { item, nbPatterns, supportSum, lowestSupport }); } } }
public void getFulfilledRowRequests(ArrayList<ServerRowRequest> requests) { int clock = bgClock.getMinClock(); requests.clear(); TIntObjectMap<List<ServerRowRequest>> bgRowRequests = clockBgRowRequests .get(clock); if (bgRowRequests == null) { return; } TIntObjectIterator<List<ServerRowRequest>> iter = bgRowRequests.iterator(); while (iter.hasNext()) { iter.advance(); requests.addAll(iter.value()); } clockBgRowRequests.remove(clock); }
public static void tickTimeouts() { if (++timer >= 200) { timer = 0; int threshold = 30; // 5 minute timeout for non-accessed images TIntObjectIterator<ImageHandler> iterator = HANDLERS.iterator(); for (int i = HANDLERS.size(); i > 0; --i) { iterator.advance(); ImageHandler imageHandler = iterator.value(); if (imageHandler.useSingleTemplateImage == false) { imageHandler.regionImageCache.removeOld(threshold); } } } }
/** Normalizes all potentials in the tree, both node and sepset. */ public void normalizeAll() { int n = cpfs.length; for (int i = 0; i < n; i++) { if (cpfs[i] != null) { cpfs[i].normalize(); } } TIntObjectIterator it = sepsets.iterator(); while (it.hasNext()) { it.advance(); Factor ptl = ((Sepset) it.value()).ptl; ptl.normalize(); } }
public void dump () { int n = cpfs.length; // This will cause OpenJGraph to print all our nodes and edges System.out.println(dumpToString()); // Now lets print all the cpfs System.out.println("Vertex CPFs"); for (int i = 0; i < n; i++) { if (cpfs[i] != null) { System.out.println("CPF "+i+" "+cpfs[i].dumpToString ()); } } // And the sepset potentials System.out.println("sepset CPFs"); TIntObjectIterator it = sepsets.iterator(); while (it.hasNext()) { it.advance(); Factor ptl = ((Sepset) it.value()).ptl; System.out.println(ptl.dumpToString ()); } System.out.println ("/End JT"); }
public boolean isNaN() { int n = cpfs.length; for (int i = 0; i < n; i++) if (cpfs[i].isNaN()) return true; // And the sepset potentials TIntObjectIterator it = sepsets.iterator(); while (it.hasNext()) { it.advance(); Factor ptl = ((Sepset) it.value()).ptl; if (ptl.isNaN()) return true; } return false; }
private void generateAppendInstanceCaches() { MxGeneratorAdapter mv = cleanableWriter.defineMethod(ACC_PUBLIC, APPEND_INSTANCE_CACHES_METHOD); mv.visitCode(); mv.loadArg(1); mv.checkCast(thisType); int instance = mv.newLocal(thisType); mv.storeLocal(instance); for (TIntObjectIterator<Generator> it = instanceCleanMethods.iterator(); it.hasNext();) { it.advance(); mv.loadArg(0); mv.loadLocal(instance); it.value().generate(mv); mv.invokeInterface(CommonRuntimeTypes.LIST_TYPE, LIST_ADD_METHOD); mv.pop(); } mv.returnValue(); mv.endMethod(); }
protected void dumpMap() { try { tmpFileIndex++; String outfile = tmpDIR + "/" + tmpFileIndex + ".tmp"; logger.info("dumping memory to file: " + outfile); PrintStream tmpContentFile = new PrintStream(outfile); TIntObjectIterator<T> it = id2item.iterator(); while (it.hasNext()) { it.advance(); T item = it.value(); tmpContentFile.print(item.getID()); tmpContentFile.print("\t"); tmpContentFile.print(Serialization.serialize(item)); tmpContentFile.print("\n"); it.remove(); } tmpContentFile.close(); } catch (Exception e) { logger.error(e.toString()); } }
protected void writeSimnilarity(int element1Id, double element1Score, TIntObjectIterator<ElementSimilarityScoring> it, boolean bR2L) throws SerializationException, IOException, NoScoreFoundException { TIntDoubleMap elementsScores = new TIntDoubleHashMap(); while (it.hasNext()) { it.advance(); int element2Id = it.key(); if (elementFilter == null || elementFilter.isRelevantElementForCalculation(element2Id)) { double element2Score = elementFeatureScoreStorage.getElementScore(element2Id); ElementSimilarityScoring similarityScoring = it.value(); double similarityScore = bR2L ? similarityScoring.getSimilarityScore(element2Score, element1Score) : similarityScoring.getSimilarityScore(element1Score, element2Score); if (similarityScore > 0) elementsScores.put(element2Id, similarityScore); } } LinkedHashMap<Integer, Double> sortedElementScores = SortUtil.sortMapByValue(elementsScores,true); if (vectorTruncater != null) sortedElementScores = vectorTruncater.truncate(sortedElementScores); if (bR2L) outR2LDevice.write(element1Id, sortedElementScores); else outL2RDevice.write(element1Id, sortedElementScores); }
public Iterable<EntityRef> iteratorEntities(Class<? extends Component>... componentClasses) { if (componentClasses.length == 0) { return iteratorEntities(); } TIntList idList = new TIntArrayList(); TIntObjectIterator<? extends Component> primeIterator = store.componentIterator(componentClasses[0]); if (primeIterator == null) { return NullIterator.newInstance(); } while (primeIterator.hasNext()) { primeIterator.advance(); int id = primeIterator.key(); boolean discard = false; for (int i = 1; i < componentClasses.length; ++i) { if (store.get(id, componentClasses[i]) == null) { discard = true; break; } } if (!discard) { idList.add(primeIterator.key()); } } return new EntityIterable(idList); }
@Override public boolean initialisationComplete(TIndexedCollection<DAGNode> nodes, TIndexedCollection<DAGEdge> edges, boolean forceRebuild) { if (taggedNodes_ == null) { taggedNodes_ = MultiMap.createSortedSetMultiMap(); TIntObjectIterator<DAGNode> iter = nodes.iterator(); for (int i = nodes.size(); i-- > 0;) { iter.advance(); DAGNode n = iter.value(); String[] props = n.getProperties(); for (String prop : props) { if (prop.startsWith(TAG_PREFIX)) { taggedNodes_.put(prop, n); } } } } return super.initialisationComplete(nodes, edges, forceRebuild); }
@Override public boolean initialisationComplete(TIndexedCollection<DAGNode> nodes, TIndexedCollection<DAGEdge> edges, boolean forceRebuild) { if (depthCalculated_ && !forceRebuild) return false; // Compute the depths of each node in the graph System.out.print("Calculating node depths... "); depthMap_ = MultiMap.createConcurrentHashSetMultiMap(); int tenPercent = nodes.size() / 10; // TODO Embarrassingly parallel. TIntObjectIterator<DAGNode> iter = nodes.iterator(); int i = 1; for (; i <= nodes.size(); i++) { iter.advance(); processNode(iter.value(), new HashSet<Integer>()); if (i % tenPercent == 0) System.out.print((i / tenPercent * 10) + "% "); } System.out.println("Depth calculation complete!"); depthCalculated_ = true; return true; }
/** * Topologically sorts a collection of nodes. * * @param nodes * The nodes to sort. * @return The topologically sorted list of nodes. */ public List<DAGNode> topologicalList(TIndexedCollection<DAGNode> nodes) { cycles_ = new ArrayList<>(); LinkedList<DAGNode> sortedNodes = new LinkedList<>(); RewriteOfModule rewriteModule = (RewriteOfModule) dag_ .getModule(RewriteOfModule.class); TIntObjectIterator<DAGNode> iter = nodes.iterator(); for (int i = nodes.size(); i-- > 0;) { iter.advance(); DAGNode n = iter.value(); if (rewriteModule != null) n = rewriteModule.getRewrite(n); // Ignore non-collections if (queryModule_.prove(false, CommonConcepts.ISA.getNode(dag_), n, CommonConcepts.COLLECTION.getNode(dag_)) == QueryResult.TRUE) topologicalVisit(n, sortedNodes, new HashMap<DAGNode, String>(), new ArrayList<DAGNode>()); } return sortedNodes; }
void iterate(CellFunction fn) { TIntObjectIterator<TIntObjectHashMap<ExchangeCell>> rowIterator = cells .iterator(); while (rowIterator.hasNext()) { rowIterator.advance(); int row = rowIterator.key(); TIntObjectHashMap<ExchangeCell> rowMap = rowIterator.value(); if (rowMap == null) continue; TIntObjectIterator<ExchangeCell> colIterator = rowMap.iterator(); while (colIterator.hasNext()) { colIterator.advance(); int col = colIterator.key(); ExchangeCell cell = colIterator.value(); if (cell == null) continue; fn.apply(row, col, cell); } } }
/** * 一次性统计概率,节约时间 */ private void statisticProb() { System.out.println("统计概率"); float totalword = alpahbet.size(); TIntFloatIterator it = wordProb.iterator(); while(it.hasNext()){ it.advance(); float v = it.value()/totalword; it.setValue(v); Cluster cluster = new Cluster(it.key(),v,alpahbet.lookupString(it.key())); clusters.put(it.key(), cluster); } TIntObjectIterator<TIntFloatHashMap> it1 = pcc.iterator(); while(it1.hasNext()){ it1.advance(); TIntFloatHashMap map = it1.value(); TIntFloatIterator it2 = map.iterator(); while(it2.hasNext()){ it2.advance(); it2.setValue(it2.value()/totalword); } } }
@Override public String toString() { StringBuilder outputBuilder = new StringBuilder(); outputBuilder.append("EquivalenceClasses\n"); for (TIntObjectIterator<EquivalenceClass> it = this.iterator(); it.hasNext(); ) { it.advance(); outputBuilder.append(String.format("ec(%d(\t", it.key())); outputBuilder.append(String.format("{%s}\n", it.value().toString())); } outputBuilder.append("EquivalenceClasses\n"); return outputBuilder.toString(); }
/** {@inheritDoc} */ public boolean equals( Object other ) { if ( ! ( other instanceof TIntObjectMap ) ) { return false; } TIntObjectMap that = ( TIntObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TIntObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); int key = iter.key(); Object value = iter.value(); if ( value == null ) { if ( !( that.get( key ) == null && that.containsKey( key ) ) ) { return false; } } else { if ( !value.equals( that.get( key ) ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
protected void updatePredecessors() { TIntObjectIterator<BitSet> iterator = nodeToSplit.getValue().predecessors.iterator(); Node<ValueNode> parent = nodeToSplit.getParent(); BitSet letterToDeleted = new BitSet(); while(iterator.hasNext()) { iterator.advance(); int letter = iterator.key(); BitSet statePrevs = iterator.value(); BitSet stateLeft = (BitSet) statePrevs.clone(); for(int stateNr = statePrevs.nextSetBit(0) ; stateNr >= 0 ; stateNr = statePrevs.nextSetBit(stateNr + 1)) { ValueNode statePrev = states.get(stateNr); Node<ValueNode> nodeOther = sift(statePrev.label.append(letter), parent); if (nodeOther != nodeToSplit) { updateTransition(stateNr, letter, nodeOther.getValue().id); stateLeft.clear(stateNr); } } if(stateLeft.isEmpty()) { letterToDeleted.set(letter); }else { iterator.setValue(stateLeft); } } for(int letter = letterToDeleted.nextSetBit(0) ; letter >= 0 ; letter = letterToDeleted.nextSetBit(letter + 1)) { nodeToSplit.getValue().predecessors.remove(letter); } }
public boolean equals( Object other ) { if ( ! ( other instanceof TIntObjectMap ) ) { return false; } TIntObjectMap that = ( TIntObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TIntObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); int key = iter.key(); Object value = iter.value(); if ( value == null ) { if ( !( that.get( key ) == null && that.containsKey( key ) ) ) { return false; } } else { if ( !value.equals( that.get( key ) ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
/** {@inheritDoc} */ @Override @SuppressWarnings("rawtypes") public boolean equals( Object other ) { if ( ! ( other instanceof TIntObjectMap ) ) { return false; } TIntObjectMap that = ( TIntObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TIntObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); int key = iter.key(); Object value = iter.value(); if ( value == null ) { if ( !( that.get( key ) == null && that.containsKey( key ) ) ) { return false; } } else { if ( !value.equals( that.get( key ) ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
@Override public void process(@Nonnull final EntityPlayer player) { if (this.emojiParticles.size() > 0) { // Get rid of dead particles final TIntObjectIterator<IParticleMote> data = this.emojiParticles.iterator(); while (data.hasNext()) { data.advance(); if (!data.value().isAlive()) data.remove(); } } }
@Override public TidList clone() { UShortMapTidList o = (UShortMapTidList) super.clone(); o.occurrences = new TIntObjectHashMap<TCharList>(this.occurrences.size()); TIntObjectIterator<TCharList> iter = this.occurrences.iterator(); while (iter.hasNext()) { iter.advance(); o.occurrences.put(iter.key(), new TCharArrayList(iter.value())); } return o; }
@Override public TidList clone() { ShortMapTidList o = (ShortMapTidList) super.clone(); o.occurrences = new TIntObjectHashMap<TShortList>(this.occurrences.size()); TIntObjectIterator<TShortList> iter = this.occurrences.iterator(); while (iter.hasNext()) { iter.advance(); o.occurrences.put(iter.key(), new TShortArrayList(iter.value())); } return o; }
@Override public TidList clone() { MapTidList o = (MapTidList) super.clone(); o.occurrences = new TIntObjectHashMap<TIntList>(this.occurrences.size()); TIntObjectIterator<TIntList> iter = this.occurrences.iterator(); while (iter.hasNext()) { iter.advance(); o.occurrences.put(iter.key(), new TIntArrayList(iter.value())); } return o; }
@Override protected void cleanup(Context context) throws IOException, InterruptedException { final IntWritable keyW = new IntWritable(); ProgressWatcherThread pokeMaster = new ProgressWatcherThread(); pokeMaster.setHadoopContext(context); pokeMaster.start(); getGlobalSupports(getDatasetPath(context)); TIntObjectIterator<TreeMatcher> iterator = this.perItempatterns.iterator(); while(iterator.hasNext()) { iterator.advance(); int keyItem = iterator.key(); keyW.set(keyItem); TreeMatcher found = iterator.value(); PatternsHeap heap = new PatternsHeap(this.k, this.itemSupports.get(keyItem)); Iterator<ItemsetSupports> patterns = found.iterator(); while (patterns.hasNext()) { ItemsetSupports pattern = patterns.next(); int[] itemset = pattern.getItemset(); try { int itemsetSupport = this.searchedPatterns.getSupport(itemset); heap.insert(itemset, itemsetSupport, pattern.getSupport()); } catch (NotMonitoredException e) { e.printStackTrace(); } } Iterator<SupportAndTransactionWritable> writables = heap.getWritables(); while (writables.hasNext()) { context.write(keyW, writables.next()); } } pokeMaster.interrupt(); }
public void resetDirty() { TIntObjectIterator<ServerRow> iter = storage.iterator(); while (iter.hasNext()) { iter.advance(); ServerRow serverRow = iter.value(); serverRow.resetDirty(); } }
public TIntSet getRowIdsToPush(int clientId) { TIntSet rowIds = new TIntHashSet(); TIntObjectIterator<ServerRow> iter = storage.iterator(); while (iter.hasNext()) { iter.advance(); int rowId = iter.key(); ServerRow serverRow = iter.value(); if (serverRow.isSubscribed(clientId) && serverRow.isDirty()) { rowIds.add(rowId); } } return rowIds; }
public static void init(int numLocalCommChannels, int numLocalWorkerThreads, TIntObjectMap<HostInfo> hostMap, int clientId) { GlobalContext.numLocalCommChannels = numLocalCommChannels; GlobalContext.numLocalWorkerThreads = numLocalWorkerThreads; GlobalContext.numClients = hostMap.size(); GlobalContext.clientId = clientId; GlobalContext.localIdMin = getThreadIdMin(clientId); GlobalContext.serverMap = new TIntObjectHashMap<>(); GlobalContext.serverIds = new TIntArrayList(); for (TIntObjectIterator<HostInfo> entry = hostMap.iterator(); entry .hasNext(); ) { entry.advance(); HostInfo hostInfo = entry.value(); int portNum = Integer.parseInt(hostInfo.port); if (entry.key() == getNameNodeId()) { GlobalContext.nameNodeHostInfo = hostInfo; portNum++; hostInfo = new HostInfo(hostInfo); hostInfo.port = Integer.toString(portNum); } for (int i = 0; i < GlobalContext.numLocalCommChannels; i++) { int serverId = getServerThreadId(entry.key(), i); GlobalContext.serverMap.put(serverId, hostInfo); portNum++; hostInfo = new HostInfo(hostInfo); hostInfo.port = Integer.toString(portNum); GlobalContext.serverIds.add(serverId); } } }