private double dot(SparseIntVector other) { double ret = 0; SparseIntVector baseVector = null; SparseIntVector streamVector = null; if(this.size() >= other.size()) { baseVector = new SparseIntVector(this); streamVector = other; } else { baseVector = new SparseIntVector(other); streamVector = this; } ObjectIterator<Int2IntMap.Entry> iter = streamVector.hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while(iter.hasNext()) { entry = iter.next(); if(baseVector.hashMap.containsKey(entry.getIntKey())) { ret += baseVector.hashMap.get(entry.getIntKey()) * entry.getIntValue(); } } return ret; }
@Override public void serialize(ByteBuf buf) { super.serialize(buf); part.serialize(buf); if(taskIndexToClockMap != null) { buf.writeInt(taskIndexToClockMap.size()); ObjectIterator<Int2IntMap.Entry> iter = taskIndexToClockMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry item; while(iter.hasNext()) { item = iter.next(); buf.writeInt(item.getIntKey()); buf.writeInt(item.getIntValue()); } } else { buf.writeInt(0); } }
private String toString(Int2IntOpenHashMap clocVec) { if(clocVec == null) { return "NULL"; } StringBuilder sb = new StringBuilder(); ObjectIterator<Int2IntMap.Entry> iter = clocVec.int2IntEntrySet().fastIterator(); Int2IntMap.Entry item ; while(iter.hasNext()) { item = iter.next(); sb.append(item.getIntKey()); sb.append(":"); sb.append(item.getIntValue()); sb.append(";"); } return sb.toString(); }
private void refreshMinClock() { if (taskIndexToClockMap.size() < taskNum) { minClock = 0; return; } int min = Integer.MAX_VALUE; for (Int2IntMap.Entry entry : taskIndexToClockMap.int2IntEntrySet()) { if (entry.getIntValue() < min) { min = entry.getIntValue(); } } if (minClock < min) { minClock = min; } }
/** * Set clock vector * @param clockVec clock vector */ public void setClockVec(Int2IntOpenHashMap clockVec) { try { lock.writeLock().lock(); ObjectIterator<Int2IntMap.Entry> iter = clockVec.int2IntEntrySet().fastIterator(); Int2IntMap.Entry item; while(iter.hasNext()) { item = iter.next(); if(!taskIndexToClockMap.containsKey(item.getIntKey()) || (taskIndexToClockMap.containsKey(item.getIntKey()) && taskIndexToClockMap.get(item.getIntKey()) < item.getIntValue())) { taskIndexToClockMap.put(item.getIntKey(), item.getIntValue()); } } refreshMinClock(); } finally { lock.writeLock().unlock(); } }
/** * Adjust clock values * @param taskToMatrixClocks taskId->(matrixId->clock) map */ public void adjustClocks(Int2ObjectOpenHashMap<Int2IntOpenHashMap> taskToMatrixClocks) { ObjectIterator<Int2ObjectMap.Entry<Int2IntOpenHashMap>> taskIter = taskToMatrixClocks.int2ObjectEntrySet().fastIterator(); Int2ObjectMap.Entry<Int2IntOpenHashMap> taskEntry = null; int taskId = 0; Int2IntOpenHashMap matrixIdToClockMap = null; ObjectIterator<Int2IntMap.Entry> matrixIter = null; Int2IntMap.Entry matrixEntry = null; while(taskIter.hasNext()) { taskEntry = taskIter.next(); taskId = taskEntry.getIntKey(); matrixIdToClockMap = taskEntry.getValue(); matrixIter = matrixIdToClockMap.int2IntEntrySet().fastIterator(); while (matrixIter.hasNext()) { matrixEntry = matrixIter.next(); updateClock(matrixEntry.getIntKey(), taskId, matrixEntry.getIntValue()); } } }
@Override public void writeTo(DataOutputStream output) throws IOException { try { lock.readLock().lock(); super.writeTo(output); output.writeInt(hashMap.size()); ObjectIterator<Int2IntMap.Entry> iter = hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); output.writeInt(entry.getIntKey()); output.writeInt(entry.getIntValue()); } } finally { lock.readLock().unlock(); } }
@Override public void serialize(ByteBuf buf) { try { lock.readLock().lock(); super.serialize(buf); buf.writeInt(hashMap.size()); ObjectIterator<Int2IntMap.Entry> iter = hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); buf.writeInt(entry.getIntKey()); buf.writeInt(entry.getIntValue()); } } finally { lock.readLock().unlock(); } }
/** * Merge this sparse int vector split to a index/value array * @param indexes index array * @param values value array * @param startPos write start position of the index/value array * @param len write length */ public void mergeTo(int[] indexes, int[] values, int startPos, int len) { try { lock.readLock().lock(); int writeLen = len < hashMap.size() ? len : hashMap.size(); if (writeLen == 0) { return; } int index = 0; ObjectIterator<Int2IntMap.Entry> iter = hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); indexes[startPos + index] = entry.getIntKey(); values[startPos + index] = entry.getIntValue(); index++; if (index == writeLen) { return; } } } finally { lock.readLock().unlock(); } }
private static Int2IntMap mergeParams(int[] params){ if(params==null||params.length==0){ CUSTOM_PARAMS.clear(); CUSTOM_PARAMS.putAll(DEFAULT_PARAMS); }else{ if(params.length%2!=0) throw new IllegalArgumentException("Params need to have x*2 elements!"); CUSTOM_PARAMS.clear(); CUSTOM_PARAMS.putAll(DEFAULT_PARAMS); for(int i=0, j=params.length/2;i<j;i++){ int i1=i*2; CUSTOM_PARAMS.put(params[i1], params[i1+1]); } } return CUSTOM_PARAMS; }
private void fillSeenPositions(Collection<DexMethod> invokes) { for (DexMethod method : invokes) { DexType[] parameters = method.proto.parameters.values; int arity = parameters.length; int positions = computePositionsFor(method.proto, target, targetProtoCache, substituions); if (positions != 0) { Int2IntMap positionsMap = seenPositions.computeIfAbsent(method.name, k -> { Int2IntMap result = new Int2IntOpenHashMap(); result.defaultReturnValue(NOT_FOUND); return result; }); int value = 0; int previous = positionsMap.get(arity); if (previous != NOT_FOUND) { value = previous; } value |= positions; positionsMap.put(arity, value); } } }
private static void renderLine(int regen, boolean low, int yTexture, int maxHealth, int maxExtraHearts, int current, int absorption, Gui gui, boolean highlight) { GlStateManager.pushMatrix(); Int2IntMap map = new Int2IntArrayMap(); if (low) { for (int i = 0; i < (maxHealth + maxExtraHearts); i++) map.put(i, EventHandler.rand.nextInt(2)); } renderMax(regen, map, maxHealth, yTexture, gui, highlight); if (maxExtraHearts > 0) { //for absorption if (maxHealth != 0) { GlStateManager.translate(2 + 9 * maxHealth, 0, 0); } renderMax(regen - maxHealth, map, maxExtraHearts, yTexture, gui, false); //Do not highlight absorption } GlStateManager.popMatrix(); GlStateManager.translate(0, 0, 1); renderCurrentHealth(regen, map, current, yTexture, gui); if (absorption > 0) { int offset = maxHealth * 9 + (maxHealth == 0 ? 0 : 2); GlStateManager.translate(offset, 0, 0); renderAbsorption(regen - maxHealth, map, absorption, yTexture, gui); } }
/** */ public Table countByCategory() { Table t = new Table("Column: " + name()); CategoryColumn categories = new CategoryColumn("Category"); IntColumn counts = new IntColumn("Count"); Int2IntMap valueToCount = new Int2IntOpenHashMap(); for (int next : values) { if (valueToCount.containsKey(next)) { valueToCount.put(next, valueToCount.get(next) + 1); } else { valueToCount.put(next, 1); } } for (Map.Entry<Integer, Integer> entry : valueToCount.int2IntEntrySet()) { categories.add(lookupTable.get(entry.getKey())); counts.append(entry.getValue()); } t.addColumn(categories); t.addColumn(counts); return t; }
private Int2IntMap getFasterIntersectionMap(int uidx) { Int2IntOpenHashMap intersectionMap = new Int2IntOpenHashMap(); intersectionMap.defaultReturnValue(0); IntIterator iidxs = data.getUidxIidxs(uidx); while (iidxs.hasNext()) { IntIterator vidxs = data.getIidxUidxs(iidxs.nextInt()); while (vidxs.hasNext()) { intersectionMap.addTo(vidxs.nextInt(), 1); } } intersectionMap.remove(uidx); return intersectionMap; }
@Override public final int findBestId(Predicate<WorldObject> predicate, World world) { int bestId = -1; int bestRelationshipValue = Integer.MIN_VALUE; for(Int2IntMap.Entry entry : idsToValue.int2IntEntrySet()) { int id = entry.getIntKey(); int relationshipValue = entry.getIntValue(); // id may not exist in world because it's filtered out by // WorldFacade, for example being invisible if (world.exists(id)) { WorldObject person = world.findWorldObjectById(id); if (relationshipValue > bestRelationshipValue && predicate.test(person)) { bestRelationshipValue = relationshipValue; bestId = id; } } } return bestId; }
@Override public final int findWorstId(World world) { int worstId = -1; int worstRelationshipValue = Integer.MAX_VALUE; for(Int2IntMap.Entry entry : idsToValue.int2IntEntrySet()) { int id = entry.getIntKey(); int relationshipValue = entry.getIntValue(); if (relationshipValue < worstRelationshipValue) { worstRelationshipValue = relationshipValue; worstId = id; } } return worstId; }
@Override public final int findBestId(Predicate<WorldObject> predicate, Comparator<WorldObject> comparator, World world) { WorldObject bestPerson = null; for(Int2IntMap.Entry entry : idsToValue.int2IntEntrySet()) { int id = entry.getIntKey(); // id may not exist in world because it's filtered out by // WorldFacade, for example being invisible if (world.exists(id)) { WorldObject person = world.findWorldObjectById(id); if (predicate.test(person)) { if (bestPerson == null || comparator.compare(bestPerson, person) < 0) { bestPerson = person; } } } } if (bestPerson != null) { return bestPerson.getProperty(Constants.ID); } else { return -1; } }
@Override public void serializeNBT(NBTTagCompound nbt) { nbt.setString(ModNBTTag.DOMAIN_USER_NAME, this.userName); nbt.setInteger(ModNBTTag.DOMAIN_USER_FLAGS, this.privilegeFlags); if(!this.activeBuilds.isEmpty()) { int[] buildData = new int[this.activeBuilds.size() * 2]; int i = 0; for(Int2IntMap.Entry entry : this.activeBuilds.int2IntEntrySet()) { buildData[i++] = entry.getIntKey(); buildData[i++] = entry.getIntValue(); } nbt.setIntArray(ModNBTTag.BUILD_ID, buildData); } }
@Override public void removeNode(int n) { Int2IntMap adMap = adjacencyMap.get(n); // Remove edges adMap.values().stream().forEach((e) -> this.removeEdge(e)); // Remove refs adMap.keySet() .stream() .forEach( (neigh) -> adjacencyMap.get(neigh).remove(n) ); super.removeNode(n); adjacencyMap.remove(n); }
@Override public void removeNode(int n) { Int2IntMap inMap = inAdjacencyMap.get(n); Int2IntMap outMap = outAdjacencyMap.get(n); // Remove edges inMap.values().stream().forEach((e) -> this.removeEdge(e)); outMap.values().stream().forEach((e) -> this.removeEdge(e)); // Remove refs inMap.keySet() .stream() .forEach( (neigh) -> outAdjacencyMap.get(neigh).remove(n) ); outMap.keySet() .stream() .forEach( (neigh) -> inAdjacencyMap.get(neigh).remove(n) ); super.removeNode(n); inAdjacencyMap.remove(n); outAdjacencyMap.remove(n); }
@Nonnull @Override public Iterator<GroupKey> iterator() { return new Iterator<GroupKey>() { private final ObjectIterator<Int2IntMap.Entry> _iterator = _rawKeyToGroupIdMap.int2IntEntrySet().fastIterator(); private final GroupKey _groupKey = new GroupKey(); @Override public boolean hasNext() { return _iterator.hasNext(); } @Override public GroupKey next() { Int2IntMap.Entry entry = _iterator.next(); _groupKey._groupId = entry.getIntValue(); _groupKey._stringKey = getGroupKey(entry.getIntKey()); return _groupKey; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
@Override public TIntVector filter(int x) { SparseIntVector vector = new SparseIntVector(dim); vector.setMatrixId(matrixId).setRowId(rowId).setClock(clock); ObjectIterator<Int2IntMap.Entry> iter = hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); int value = entry.getIntValue(); if (Math.abs(value) > x) { vector.set(entry.getIntKey(), value); } } return vector; }
@Override public TIntVector times(int x) { SparseIntVector vector = new SparseIntVector(this); ObjectIterator<Int2IntMap.Entry> iter = vector.hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while(iter.hasNext()) { entry.setValue(entry.getIntValue() * x); } return vector; }
@Override public TIntVector timesBy(int x) { ObjectIterator<Int2IntMap.Entry> iter = hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while(iter.hasNext()) { entry = iter.next(); entry.setValue(entry.getIntValue() * x); } return this; }
private SparseIntVector plusBy(SparseIntVector other) { ObjectIterator<Int2IntMap.Entry> iter = other.hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); this.hashMap.addTo(entry.getIntKey(), entry.getIntValue()); } return this; }
private SparseIntVector plusBy(SparseIntVector other, int x) { ObjectIterator<Int2IntMap.Entry> iter = other.hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); this.hashMap.addTo(entry.getIntKey(), entry.getIntValue() * x); } return this; }
@Override public long nonZeroNumber() { long ret = 0; if (hashMap != null) { ObjectIterator<Int2IntMap.Entry> iter = this.hashMap.int2IntEntrySet().fastIterator(); while (iter.hasNext()) { if (iter.next().getIntValue() != 0) { ret++; } } } return ret; }
@Override public double squaredNorm() { ObjectIterator<Int2IntMap.Entry> iter = hashMap.int2IntEntrySet().iterator(); double sum = 0; while (iter.hasNext()) { double v = iter.next().getIntValue(); sum += v * v; } return sum; }
private double dot(SparseIntVector other) { double ret = 0.0; ObjectIterator<Int2IntMap.Entry> iter = other.hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); ret += entry.getIntValue() * values[entry.getIntKey()]; } return ret; }
private TIntVector plusBy(SparseIntVector other) { ObjectIterator<Int2IntMap.Entry> iter = other.hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); values[entry.getIntKey()] += entry.getIntValue(); } return this; }
private TIntVector plusBy(SparseIntVector other, int x) { ObjectIterator<Int2IntMap.Entry> iter = other.hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); values[entry.getIntKey()] += entry.getIntValue() * x; } return this; }
private TIntVector plus(SparseIntVector other) { DenseIntVector vector = new DenseIntVector(this); ObjectIterator<Int2IntMap.Entry> iter = other.hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); vector.values[entry.getIntKey()] += entry.getIntValue(); } return vector; }
private TIntVector plus(SparseIntVector other, int x) { DenseIntVector vector = new DenseIntVector(this); ObjectIterator<Int2IntMap.Entry> iter = other.hashMap.int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); vector.values[entry.getIntKey()] += entry.getIntValue() * x; } return vector; }
@Override public void serialize(ByteBuf buf) { super.serialize(buf); buf.writeInt(split.size()); LOG.debug("double size = " + split.size()); ObjectIterator<Int2IntMap.Entry> iter = split.getIndexToValueMap().int2IntEntrySet().fastIterator(); Int2IntMap.Entry entry = null; while (iter.hasNext()) { entry = iter.next(); buf.writeInt(entry.getIntKey()); buf.writeInt(entry.getIntValue()); } }
public boolean union(CustomHashMap other){ boolean modified = false; for(Int2IntMap.Entry otherEntry : other.int2IntEntrySet()){ if(!this.containsKey(otherEntry.getIntKey())){ this.put(otherEntry.getIntKey(), otherEntry.getIntValue()); modified = true; } } return modified; }
@Override public int[] generateValues(final int x, final int z, final int sizeX, final int sizeZ) { final int gridX = x - 1; final int gridZ = z - 1; final int gridSizeX = sizeX + 2; final int gridSizeZ = sizeZ + 2; final int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); final int[] finalValues = new int[sizeX * sizeZ]; for (int i = 0; i < sizeZ; i++) { for (int j = 0; j < sizeX; j++) { // This applies biome large edges using Von Neumann neighborhood final int centerVal = values[(j + 1 + ((i + 1) * gridSizeX))]; int val = centerVal; for (final Entry<Int2IntMap, IntList> entry : EDGES.entrySet()) { final Int2IntMap map = entry.getKey(); if (map.containsKey(centerVal)) { final int upperVal = values[(j + 1 + (i * gridSizeX))]; final int lowerVal = values[(j + 1 + ((i + 2) * gridSizeX))]; final int leftVal = values[(j + ((i + 1) * gridSizeX))]; final int rightVal = values[(j + 2 + ((i + 1) * gridSizeX))]; if (((entry.getValue() == null) && (! map.containsKey(upperVal) || ! map.containsKey(lowerVal) || ! map.containsKey(leftVal) || ! map.containsKey(rightVal))) || ((entry.getValue() != null) && (entry.getValue().contains(upperVal) || entry.getValue().contains(lowerVal) || entry.getValue().contains(leftVal) || entry.getValue().contains(rightVal)))) { val = map.get(centerVal); break; } } } finalValues[(j + (i * sizeX))] = val; } } return finalValues; }
@Override public int[] generateValues(final int x, final int z, final int sizeX, final int sizeZ) { final int gridX = x - 1; final int gridZ = z - 1; final int gridSizeX = sizeX + 2; final int gridSizeZ = sizeZ + 2; final int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); final int[] finalValues = new int[sizeX * sizeZ]; for (int i = 0; i < sizeZ; i++) { for (int j = 0; j < sizeX; j++) { // This applies biome thin edges using Von Neumann neighborhood final int centerVal = values[(j + 1 + ((i + 1) * gridSizeX))]; int val = centerVal; for (final Entry<Int2IntMap, IntList> entry : EDGES.entrySet()) { final Int2IntMap map = entry.getKey(); if (map.containsKey(centerVal)) { final int upperVal = values[(j + 1 + (i * gridSizeX))]; final int lowerVal = values[(j + 1 + ((i + 2) * gridSizeX))]; final int leftVal = values[(j + ((i + 1) * gridSizeX))]; final int rightVal = values[(j + 2 + ((i + 1) * gridSizeX))]; if (((entry.getValue() == null) && ((! OCEANS.contains(upperVal) && ! map.containsKey(upperVal)) || (! OCEANS.contains(lowerVal) && ! map.containsKey(lowerVal)) || (! OCEANS.contains(leftVal) && ! map.containsKey(leftVal)) || (! OCEANS.contains(rightVal) && ! map.containsKey(rightVal)))) || ((entry.getValue() != null) && ((! OCEANS.contains(upperVal) && ! entry.getValue().contains(upperVal)) || (! OCEANS.contains(lowerVal) && ! entry.getValue().contains(lowerVal)) || (! OCEANS.contains(leftVal) && ! entry.getValue().contains(leftVal)) || (! OCEANS.contains(rightVal) && ! entry.getValue().contains(rightVal))))) { val = map.get(centerVal); break; } } } finalValues[(j + (i * sizeX))] = val; } } return finalValues; }
private Int2IntMap getIntersectionMap(int idx1) { Int2IntOpenHashMap intersectionMap = new Int2IntOpenHashMap(); intersectionMap.defaultReturnValue(0); data.getUidxPreferences(idx1) .forEach(ip -> data.getIidxPreferences(ip.v1) .forEach(up -> intersectionMap.addTo(up.v1, 1))); intersectionMap.remove(idx1); return intersectionMap; }
@Override public final int getSumOfAllValues() { int sumOfAllValues = 0; for(Int2IntMap.Entry entry : idsToValue.int2IntEntrySet()) { sumOfAllValues += entry.getIntValue(); } return sumOfAllValues; }