int i = indexOfInsertion(key); if (i<0) { //already contained i = -i -1; int newCapacity = chooseGrowCapacity(this.distinct+1,this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity); return put(key, value); int newCapacity = chooseGrowCapacity(this.distinct+1,this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity);
private static OpenIntIntHashMap getNodeAttIDToAttTypeMap() { if (nodeAttIDToAttTypeMap == null) nodeAttIDToAttTypeMap = new OpenIntIntHashMap(); return nodeAttIDToAttTypeMap; }
/** * Trims the capacity of the receiver to be the receiver's current * size. Releases any superfluous internal memory. An application can use this operation to minimize the * storage of the receiver. */ public void trimToSize() { // * 1.2 because open addressing's performance exponentially degrades beyond that point // so that even rehashing the table can take very long int newCapacity = nextPrime((int)(1 + 1.2*size())); if (table.length > newCapacity) { rehash(newCapacity); } } /**
public int indexOf(int varName) { // TODO Replacing zero-based indexing with the 1-based // allow remove invocation of containsKey method here // O(1) return permutationHash.containsKey(varName) ? permutationHash.get(varName) : -1; }
/** * Removes the given key with its associated element from the receiver, if present. * * @param key the key to be removed from the receiver. * @return <tt>true</tt> if the receiver contained the specified key, <tt>false</tt> otherwise. */ public boolean removeKey(int key) { int i = indexOfKey(key); if (i<0) return false; // key not contained this.state[i]=REMOVED; //this.values[i]=0; // delta this.distinct--; if (this.distinct < this.lowWaterMark) { int newCapacity = chooseShrinkCapacity(this.distinct,this.minLoadFactor, this.maxLoadFactor); /* if (table.length != newCapacity) { System.out.print("shrink rehashing "); System.out.println("at distinct="+distinct+", capacity="+table.length+" to newCapacity="+newCapacity+" ..."); } */ rehash(newCapacity); } return true; } /**
OpenIntIntHashMap candidateTopicWordNumSum = new OpenIntIntHashMap(); for (int i = 0; i < candidateList.size(); ++i) { String candidateName = candidateList.get(i); IntArrayList values = topicWordCountArray[j].values(); int totalTopicWordNum = 0; for (int k = 0; k < values.size(); ++k) { totalTopicWordNum += values.get(k); candidateTopicWordNumSum.put(topicId, totalTopicWordNum); for (int j = 0; j < topicList.size(); ++j) { int topicId = topicList.get(j); int docCount = topicCountMap.get(topicId); int wordCount = candidateTopicWordCount.get(topicId).get(wordId); int sumWordCount = candidateTopicWordNumSum.get(topicId); if (topicId == currentTopic) { docCount -= 1; int docCount = topicCountMap.get(currentTopic) - 1; topicCountMap.put(currentTopic, docCount); int wordCount = candidateTopicWordCount.get(currentTopic).get(wordId) - 1; candidateTopicWordCount.get(currentTopic).put(wordId, wordCount); int sumWordCount = candidateTopicWordNumSum.get(currentTopic) - 1; candidateTopicWordNumSum.put(currentTopic, sumWordCount); docCount = topicCountMap.get(sampledTopicId) + 1;
OpenIntIntHashMap internalToOriginalMap = new OpenIntIntHashMap(); OpenIntIntHashMap sourceIndices = new OpenIntIntHashMap(); IntArrayList sourceValues = readSourceValues(reader, sourceIndices); for (int originalVarName : sourceIndices.keys().elements()) internalToOriginalMap.put(sourceIndices.get(originalVarName), originalVarName); int var = sign * sourceIndices.get(Math.abs(sourceVar)); values.add(var);
nodeIDMap = new OpenIntIntHashMap(nodes.size()); giny_nodes = new IntArrayList(nodes.size()); OpenIntIntHashMap gml_id2order = new OpenIntIntHashMap(nodes.size()); Set<String> nodeNameSet = new HashSet<String>(nodes.size()); nodeIDMap.put(nodes.get(idx), node.getRootGraphIndex()); gml_id2order.put(nodes.get(idx), idx); ((KeyValue) node_root_index_pairs.get(idx)).value = (new Integer( node.getRootGraphIndex())); if (gml_id2order.containsKey(sources.get(idx)) && gml_id2order.containsKey(targets.get(idx))) { String label = (String) edgeLabels.get(idx); String sourceName = (String) nodeLabels.get(gml_id2order .get(sources.get(idx))); String targetName = (String) nodeLabels.get(gml_id2order .get(targets.get(idx)));
HashMap<Integer, String> topicMap = new HashMap<Integer, String>(); HashMap<Integer, OpenIntDoubleHashMap> candidateTopicWordDistribution = new HashMap<Integer, OpenIntDoubleHashMap>(); OpenIntIntHashMap candidateTopicWordNumSum = new OpenIntIntHashMap(); candidateTopicWordNumSum.put(topicIDAll, candidate.getSumCount()); OpenIntIntHashMap topicCountMap = new OpenIntIntHashMap(); topicCountMap.put(randomTopic, topicCountMap.get(randomTopic) + 1); topicSeq[i] = randomTopic; for (int j = 0; j < topicList.size(); ++j) { int topicId = topicList.get(j); // here topicList.get(j) == j int docCount = topicCountMap.get(topicId); if (topicId == currentTopic) { docCount -= 1; int sumWordCount = candidateTopicWordNumSum.get(topicId); int docCount = topicCountMap.get(currentTopic) - 1; topicCountMap.put(currentTopic, docCount); docCount = topicCountMap.get(sampledTopicId) + 1; topicCountMap.put(sampledTopicId, docCount); int topicCount = topicCountMap.get(topicId); double similarity = (topicCount + globalAlpha) / (wordSeq.length + globalAlpha * topicList.size()); similarities.put(topicMap.get(topicId), similarity);
OpenIntIntHashMap originalVarNames = new OpenIntIntHashMap(); originalVarNames.put(r, r); r = r * sign; sourceValues.add(r); IntArrayList sortedVarNames = originalVarNames.keys(); sortedVarNames.sort(); for (int i = 0; i < sortedVarNames.size(); i++) sourceIndices.put(sortedVarNames.get(i), i + 1);
edges = new OpenIntIntHashMap(edgeCount); edges.put(edge.getRootGraphIndex(), 0);
public void swap(int varName1, int varName2) { int index1 = permutation.indexOf(varName1); int index2 = permutation.indexOf(varName2); positionHash.put(index1, varName2); positionHash.put(index2, varName1); permutationHash.put(varName1, index2); permutationHash.put(varName2, index1); permutation.setQuick(index1, varName2); permutation.setQuick(index2, varName1); elementsHashDirty = true; }
public int getOriginalVarName(int varName) { int originalVarName = internalToOriginalMap.get(varName); if (originalVarName == 0) { throw new IllegalArgumentException("Original variable not found for varName=" + varName); } return originalVarName; } }
byte newState[] = new byte[newCapacity]; this.lowWaterMark = chooseLowWaterMark(newCapacity,this.minLoadFactor); this.highWaterMark = chooseHighWaterMark(newCapacity,this.maxLoadFactor); if (oldState[i]==FULL) { int element = oldTable[i]; int index = indexOfInsertion(element); newTable[index]=element; newValues[index]=oldValues[i];
/** * Insert <code>varName</code> before position <code>index</code>. * * Note: This implementation can be slow. To avoid usage of this method remove * the <code>JoinBetweenTiers2</code> implementation of {@link IJoinMethod} from {@link JoinMethods#getMethods()}. */ public void add(int index, int varName) { if (Helper.EnableAssertions) { assertNotContains(varName); } permutation.beforeInsert(index, varName); permutationHash.put(varName, index); for (int i = permutation.size() - 2; i >= index; i--) { int var = positionHash.get(i); int idx = permutationHash.get(var); permutationHash.put(var, idx + 1); positionHash.put(i + 1, var); } positionHash.put(index, varName); elementsHashDirty = true; }
int capacity = initialCapacity; super.setUp(capacity, minLoadFactor, maxLoadFactor); capacity = nextPrime(capacity); if (capacity==0) capacity=1; // open addressing needs at least one FREE slot at any time. this.highWaterMark = chooseHighWaterMark(capacity, this.maxLoadFactor);
for (int i = 0; i < topicWordCountArray.length; ++i) { topicWordDistributionArray[i] = new OpenIntDoubleHashMap(); IntArrayList indexList = topicWordCountArray[i].keys(); int sumLocalCount = 0; for (int j = 0; j < indexList.size(); ++j) { int index = indexList.get(j); int wordCount = topicWordCountArray[i].get(index); sumCount += wordCount; sumLocalCount += wordCount; int wordCount = topicWordCountArray[i].get(index); topicWordDistributionArray[i].put(index, (wordCount + globalBeta) / (sumLocalCount * globalBeta * this.globalWordNum ));
public boolean contains(int varName) { // O(1) return permutationHash.containsKey(varName); }