public ObjectIntHashMap<String> nodesPerAttributesCounts(String attributeName) { ObjectIntHashMap<String> nodesPerAttributesCounts = nodesPerAttributeNames.get(attributeName); if (nodesPerAttributesCounts != null) { return nodesPerAttributesCounts; } nodesPerAttributesCounts = new ObjectIntHashMap<>(); for (RoutingNode routingNode : this) { String attrValue = routingNode.node().getAttributes().get(attributeName); nodesPerAttributesCounts.addTo(attrValue, 1); } nodesPerAttributeNames.put(attributeName, nodesPerAttributesCounts); return nodesPerAttributesCounts; }
/** * Return true if all keys of some other container exist in this container. * Equality comparison is performed with this object's {@link #equals(Object, Object)} * method. */ protected boolean equalElements(ObjectIntHashMap<?> other) { if (other.size() != size()) { return false; } for (ObjectIntCursor<?> c : other) { KType key = (KType) c.key; if (!containsKey(key) || !((get(key)) == (c.value))) { return false; } } return true; }
/** * Creates a hash map from two index-aligned arrays of key-value pairs. */ public static <KType> ObjectIntHashMap<KType> from(KType[] keys, int[] values) { if (keys.length != values.length) { throw new IllegalArgumentException("Arrays of keys and values must have an identical length."); } ObjectIntHashMap<KType> map = new ObjectIntHashMap<>(keys.length); for (int i = 0; i < keys.length; i++) { map.put(keys[i], values[i]); } return map; }
ObjectIntHashMap<String> shardPerAttribute = new ObjectIntHashMap<>(); for (ShardRouting assignedShard : allocation.routingNodes().assignedShards(shardRouting.shardId())) { if (assignedShard.started() || assignedShard.initializing()) { shardPerAttribute.addTo(routingNode.node().getAttributes().get(awarenessAttribute), 1); if (!node.nodeId().equals(nodeId)) { shardPerAttribute.putOrAdd(allocation.routingNodes().node(nodeId).node().getAttributes().get(awarenessAttribute), 0, -1); shardPerAttribute.addTo(node.node().getAttributes().get(awarenessAttribute), 1); shardPerAttribute.addTo(node.node().getAttributes().get(awarenessAttribute), 1); int numberOfAttributes = nodesPerAttribute.size(); List<String> fullValues = forcedAwarenessAttributes.get(awarenessAttribute); if (fullValues != null) { for (String fullValue : fullValues) { if (!shardPerAttribute.containsKey(fullValue)) { numberOfAttributes++; int currentNodeCount = shardPerAttribute.get(node.node().getAttributes().get(awarenessAttribute));
private void releaseViewExpansionToken(ViewExpansionToken token) { final String viewOwner = token.viewOwner; if (Objects.equals(queryUser, viewOwner)) { // If the token owner and queryUser are same, no need to track the token release. return; } Preconditions.checkState(userTokens.containsKey(token.viewOwner), "Given user doesn't exist in User Token store. Make sure token for this user is obtained first."); final int userTokenCount = userTokens.get(viewOwner); if (userTokenCount == 1) { // Remove the user from collection, when there are no more tokens issued to the user. userTokens.remove(viewOwner); } else { userTokens.put(viewOwner, userTokenCount - 1); } logger.debug("Released view expansion token issued for user '{}'", viewOwner); }
private List<Instruction> sortInstructions(Collection<Instruction> instructions, BasicBlock block) { ObjectIntMap<Instruction> indexes = new ObjectIntHashMap<>(); int index = 0; for (Instruction instruction : block) { indexes.put(instruction, index++); } List<Instruction> sortedInstructions = new ArrayList<>(instructions); sortedInstructions.sort(Comparator.comparing(insn -> indexes.getOrDefault(insn, -1))); return sortedInstructions; }
if (count > 0 && (keySlot = seenSurfaceForms.indexOf(surface)) >= 0) { surfaceIndex = seenSurfaceForms.indexGet(keySlot); SurfaceFormAndPayload surfaceFormAndPayload = surfaceFormsAndPayload[surfaceIndex]; if (encodedWeight >= surfaceFormAndPayload.weight) { surfaceIndex = count++; surfaceCopy = BytesRef.deepCopyOf(surface); seenSurfaceForms.put(surfaceCopy, surfaceIndex);
/** * If <code>key</code> exists, <code>putValue</code> is inserted into the map, * otherwise any existing value is incremented by <code>additionValue</code>. * * @param key * The key of the value to adjust. * @param putValue * The value to put if <code>key</code> does not exist. * @param incrementValue * The value to add to the existing value if <code>key</code> exists. * @return Returns the current value associated with <code>key</code> (after * changes). */ @Override public int putOrAdd(KType key, int putValue, int incrementValue) { assert assigned < mask + 1; if (containsKey(key)) { putValue = get(key); putValue = (int) (((putValue) + (incrementValue))); } put(key, putValue); return putValue; }
@Override public int test() { final ObjectIntHashMap<Integer> m_map = new ObjectIntHashMap<>( m_keys.length / 2 + 1, m_fillFactor ); int add = 0, remove = 0; while ( add < m_keys.length ) { m_map.put( m_keys[ add ], add ); ++add; m_map.put( m_keys[ add ], add ); ++add; m_map.remove( m_keys[ remove++ ] ); } return m_map.size(); } }
if (!viewOwner.equals(queryUser)) { if (userTokens.containsKey(viewOwner)) { totalTokens += userTokens.get(viewOwner); } else { if (userTokens.size() == maxChainedUserHops) { final String errMsg = String.format("Cannot issue token for view expansion as issuing the token exceeds the " + userTokens.put(viewOwner, totalTokens);
/** * Releases an index commit that acquired by {@link #acquireIndexCommit(boolean)}. * * @return true if the snapshotting commit can be clean up. */ synchronized boolean releaseCommit(final IndexCommit snapshotCommit) { final IndexCommit releasingCommit = ((SnapshotIndexCommit) snapshotCommit).delegate; assert snapshottedCommits.containsKey(releasingCommit) : "Release non-snapshotted commit;" + "snapshotted commits [" + snapshottedCommits + "], releasing commit [" + releasingCommit + "]"; final int refCount = snapshottedCommits.addTo(releasingCommit, -1); // release refCount assert refCount >= 0 : "Number of snapshots can not be negative [" + refCount + "]"; if (refCount == 0) { snapshottedCommits.remove(releasingCommit); } // The commit can be clean up only if no pending snapshot and it is neither the safe commit nor last commit. return refCount == 0 && releasingCommit.equals(safeCommit) == false && releasingCommit.equals(lastCommit) == false; }
@Override public int test() { final ObjectIntHashMap<Integer> m_map = new ObjectIntHashMap<>( m_keys.length, m_fillFactor ); for ( int i = 0; i < m_keys.length; ++i ) m_map.put( m_keys[ i ], i ); for ( int i = 0; i < m_keys2.length; ++i ) m_map.put( m_keys2[ i ], i ); return m_map.size(); } }
public static int getIndex(String timezone) { return timezoneMap.get(timezone); }
final int before = size(); if (other.size() >= size() && other instanceof ObjectLookupContainer<?>) { if (hasEmptyKey) { if (!((existing = keys[slot]) == null) && other.contains(existing)) { shiftConflictingKeys(slot); } else { slot++; this.remove((KType) c.value); return before - size();
@Override public int put(V key, int value) { if (key == null) { throw new IllegalArgumentException("Map key must not be null"); } return super.put(key, value); } };
/** * {@inheritDoc} */ @Override public int removeAll(ObjectIntPredicate<? super KType> predicate) { final int before = size(); final int mask = this.mask; if (hasEmptyKey) { if (predicate.apply(null, values[mask + 1])) { hasEmptyKey = false; values[mask + 1] = 0; } } final KType[] keys = (KType[]) this.keys; final int[] values = this.values; for (int slot = 0; slot <= mask;) { KType existing; if (!((existing = keys[slot]) == null) && predicate.apply(existing, values[slot])) { // Shift, do not increment slot. shiftConflictingKeys(slot); } else { slot++; } } return before - size(); }
private int getFieldIndex(final String name, final InstructionModifier mv) { if (!fieldMap.containsKey(name)) { throw new IllegalArgumentException(String.format( "Unknown name '%s' on line %d.", name, mv.getLastLineNumber())); } return fieldMap.get(name); // using lget() is not thread-safe }
/** * {@inheritDoc} */ public boolean isEmpty() { return size() == 0; }
@Override public synchronized void onCommit(List<? extends IndexCommit> commits) throws IOException { final int keptPosition = indexOfKeptCommits(commits, globalCheckpointSupplier.getAsLong()); lastCommit = commits.get(commits.size() - 1); safeCommit = commits.get(keptPosition); for (int i = 0; i < keptPosition; i++) { if (snapshottedCommits.containsKey(commits.get(i)) == false) { deleteCommit(commits.get(i)); } } updateRetentionPolicy(); }