com.carrotsearch.hppc.ObjectIntHashMap.hashKey()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中com.carrotsearch.hppc.ObjectIntHashMap.hashKey()方法的一些代码示例,展示了ObjectIntHashMap.hashKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectIntHashMap.hashKey()方法的具体详情如下:
包路径:com.carrotsearch.hppc.ObjectIntHashMap
类名称:ObjectIntHashMap
方法名:hashKey

ObjectIntHashMap.hashKey介绍

[英]Returns a hash code for the given key.

The default implementation mixes the hash of the key with #keyMixerto differentiate hash order of keys between hash containers. Helps alleviate problems resulting from linear conflict resolution in open addressing.

The output from this function should evenly distribute keys across the entire integer range.
[中]返回给定密钥的哈希代码。
默认实现将密钥的散列与#keymixer混合,以区分散列容器之间密钥的散列顺序。有助于缓解开放寻址中线性冲突解决带来的问题。
此函数的输出应在整个整数范围内均匀分布关键点。

代码示例

代码示例来源:origin: carrotsearch/hppc

final int idealSlot = hashKey(existing);
final int shift = (slot - idealSlot) & mask;
if (shift >= distance) {

代码示例来源:origin: carrotsearch/hppc

/**
 * {@inheritDoc}
 */
@Override
public int get(KType key) {
 if (((key) == null)) {
  return hasEmptyKey ?  values[mask + 1] : 0;
 } else {
  final KType[] keys = (KType[]) this.keys;
  final int mask = this.mask;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    return  values[slot];
   }
   slot = (slot + 1) & mask;
  }
  return 0;
 }
}

代码示例来源:origin: carrotsearch/hppc

/**
 * {@inheritDoc}
 */
@Override
public int getOrDefault(KType key, int defaultValue) {
 if (((key) == null)) {
  return hasEmptyKey ?  values[mask + 1] : defaultValue;
 } else {
  final KType[] keys = (KType[]) this.keys;
  final int mask = this.mask;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    return  values[slot];
   }
   slot = (slot + 1) & mask;
  }
  return defaultValue;
 }
}

代码示例来源:origin: carrotsearch/hppc

/**
 * {@inheritDoc}
 */
@Override
public boolean containsKey(KType key) {
 if (((key) == null)) {
  return hasEmptyKey;
 } else {
  final KType[] keys = (KType[]) this.keys;
  final int mask = this.mask;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    return true;
   }
   slot = (slot + 1) & mask;
  }    
  return false;
 }
}

代码示例来源:origin: carrotsearch/hppc

/**
 * {@inheritDoc}
 */
@Override
public int indexOf(KType key) {
 final int mask = this.mask;
 if (((key) == null)) {
  return hasEmptyKey ? mask + 1 : ~(mask + 1);
 } else {
  final KType[] keys = (KType[]) this.keys;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    return slot;
   }
   slot = (slot + 1) & mask;
  }
  return ~slot;
 }
}

代码示例来源:origin: carrotsearch/hppc

/**
 * Rehash from old buffers to new buffers. 
 */
protected void rehash(KType[] fromKeys, int[] fromValues) {
 assert fromKeys.length == fromValues.length &&
     HashContainers.checkPowerOfTwo(fromKeys.length - 1);
 
 // Rehash all stored key/value pairs into the new buffers.
 final KType[] keys = (KType[]) this.keys;
 final int[] values =  this.values;
 final int mask = this.mask;
 KType existing;
 // Copy the zero element's slot, then rehash everything else.
 int from = fromKeys.length - 1;
 keys[keys.length - 1] = fromKeys[from];
 values[values.length - 1] = fromValues[from];
 while (--from >= 0) {
  if (!((existing = fromKeys[from]) == null)) {
   int slot = hashKey(existing) & mask;
   while (!((keys[slot]) == null)) {
    slot = (slot + 1) & mask;
   }
   keys[slot] = existing;
   values[slot] = fromValues[from];
  }
 }
}

代码示例来源:origin: carrotsearch/hppc

/**
 * {@inheritDoc}
 */
@Override
public int remove(KType key) {
 final int mask = this.mask;
 if (((key) == null)) {
  hasEmptyKey = false;
  int previousValue =  values[mask + 1];
  values[mask + 1] = 0;
  return previousValue;
 } else {
  final KType[] keys = (KType[]) this.keys;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    final int previousValue =  values[slot];
    shiftConflictingKeys(slot);
    return previousValue;
   }
   slot = (slot + 1) & mask;
  }
  return 0;
 }
}

代码示例来源:origin: carrotsearch/hppc

} else {
 final KType[] keys = (KType[]) this.keys;
 int slot = hashKey(key) & mask;

代码示例来源:origin: harbby/presto-connectors

final int idealSlot = hashKey(existing);
final int shift = (slot - idealSlot) & mask;
if (shift >= distance) {

代码示例来源:origin: harbby/presto-connectors

/**
 * {@inheritDoc}
 */
@Override
public int get(KType key) {
 if (((key) == null)) {
  return hasEmptyKey ?  values[mask + 1] : 0;
 } else {
  final KType[] keys = (KType[]) this.keys;
  final int mask = this.mask;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    return  values[slot];
   }
   slot = (slot + 1) & mask;
  }
  return 0;
 }
}

代码示例来源:origin: harbby/presto-connectors

/**
 * {@inheritDoc}
 */
@Override
public int indexOf(KType key) {
 final int mask = this.mask;
 if (((key) == null)) {
  return hasEmptyKey ? mask + 1 : ~(mask + 1);
 } else {
  final KType[] keys = (KType[]) this.keys;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    return slot;
   }
   slot = (slot + 1) & mask;
  }
  return ~slot;
 }
}

代码示例来源:origin: harbby/presto-connectors

/**
 * {@inheritDoc}
 */
@Override
public int getOrDefault(KType key, int defaultValue) {
 if (((key) == null)) {
  return hasEmptyKey ?  values[mask + 1] : defaultValue;
 } else {
  final KType[] keys = (KType[]) this.keys;
  final int mask = this.mask;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    return  values[slot];
   }
   slot = (slot + 1) & mask;
  }
  return defaultValue;
 }
}

代码示例来源:origin: harbby/presto-connectors

/**
 * {@inheritDoc}
 */
@Override
public boolean containsKey(KType key) {
 if (((key) == null)) {
  return hasEmptyKey;
 } else {
  final KType[] keys = (KType[]) this.keys;
  final int mask = this.mask;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    return true;
   }
   slot = (slot + 1) & mask;
  }    
  return false;
 }
}

代码示例来源:origin: harbby/presto-connectors

/**
 * Rehash from old buffers to new buffers. 
 */
protected void rehash(KType[] fromKeys, int[] fromValues) {
 assert fromKeys.length == fromValues.length &&
     HashContainers.checkPowerOfTwo(fromKeys.length - 1);
 
 // Rehash all stored key/value pairs into the new buffers.
 final KType[] keys = (KType[]) this.keys;
 final int[] values =  this.values;
 final int mask = this.mask;
 KType existing;
 // Copy the zero element's slot, then rehash everything else.
 int from = fromKeys.length - 1;
 keys[keys.length - 1] = fromKeys[from];
 values[values.length - 1] = fromValues[from];
 while (--from >= 0) {
  if (!((existing = fromKeys[from]) == null)) {
   int slot = hashKey(existing) & mask;
   while (!((keys[slot]) == null)) {
    slot = (slot + 1) & mask;
   }
   keys[slot] = existing;
   values[slot] = fromValues[from];
  }
 }
}

代码示例来源:origin: harbby/presto-connectors

/**
 * {@inheritDoc}
 */
@Override
public int remove(KType key) {
 final int mask = this.mask;
 if (((key) == null)) {
  hasEmptyKey = false;
  int previousValue =  values[mask + 1];
  values[mask + 1] = 0;
  return previousValue;
 } else {
  final KType[] keys = (KType[]) this.keys;
  int slot = hashKey(key) & mask;
  KType existing;
  while (!((existing = keys[slot]) == null)) {
   if (this.equals(existing,  key)) {
    final int previousValue =  values[slot];
    shiftConflictingKeys(slot);
    return previousValue;
   }
   slot = (slot + 1) & mask;
  }
  return 0;
 }
}

代码示例来源:origin: harbby/presto-connectors

} else {
 final KType[] keys = (KType[]) this.keys;
 int slot = hashKey(key) & mask;

相关文章