本文整理了Java中com.carrotsearch.hppc.ObjectIntHashMap
类的一些代码示例,展示了ObjectIntHashMap
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectIntHashMap
类的具体详情如下:
包路径:com.carrotsearch.hppc.ObjectIntHashMap
类名称:ObjectIntHashMap
[英]A hash map of Object
to int
, implemented using open addressing with linear probing for collision resolution.
Note: read about important differences between hash and scatter sets.
[中]Object
到int
的哈希映射,使用开放寻址和线性探测实现冲突解决。
注意:阅读important differences between hash and scatter sets。
代码示例来源:origin: org.elasticsearch/elasticsearch
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;
}
代码示例来源:origin: carrotsearch/hppc
/**
* 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;
}
代码示例来源:origin: carrotsearch/hppc
/**
* 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;
}
代码示例来源:origin: carrotsearch/hppc
/**
* {@inheritDoc}
*/
@Override
public int putAll(ObjectIntAssociativeContainer<? extends KType> container) {
final int count = size();
for (ObjectIntCursor<? extends KType> c : container) {
put(c.key, c.value);
}
return size() - count;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
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));
代码示例来源:origin: dremio/dremio-oss
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);
}
代码示例来源:origin: konsoletyper/teavm
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;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
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);
代码示例来源:origin: harbby/presto-connectors
/**
* 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;
}
代码示例来源:origin: mikvor/hashmapTest
@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();
}
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
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);
代码示例来源:origin: org.elasticsearch/elasticsearch
/**
* 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;
}
代码示例来源:origin: mikvor/hashmapTest
@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();
}
}
代码示例来源:origin: apache/drill
public static int getIndex(String timezone) {
return timezoneMap.get(timezone);
}
代码示例来源:origin: carrotsearch/hppc
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();
代码示例来源:origin: org.elasticsearch/elasticsearch
@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);
}
};
代码示例来源:origin: carrotsearch/hppc
/**
* {@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();
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
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
}
代码示例来源:origin: carrotsearch/hppc
/**
* {@inheritDoc}
*/
public boolean isEmpty() {
return size() == 0;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
@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();
}
内容来源于网络,如有侵权,请联系作者删除!