Java源码示例:com.carrotsearch.hppc.BitMixer

示例1
/**
 * Returns the hash of a {@link Map} object created by
 * {@link org.elasticsearch.common.xcontent.XContentHelper#convertToMap(BytesReference, boolean)} by traversing
 * nested {@link Map} and {@link List} objects.
 * <br>
 * The hash is used by {@link solutions.siren.join.action.coordinate.model.FilterJoinNode} to compute a unique
 * cache id. This method should not be used outside this scope.
 * <br>
 * The hash is computed in a similar way than in {@link java.util.AbstractMap}, i.e.,
 * the sum of the hash codes of each entry in the map. The difference is that we are mixing bits of
 * the hash codes of the entry's key and value to improve the distribution of their hash value. A similar technique
 * is used in hppc's {@link com.carrotsearch.hppc.ObjectObjectHashMap#hashCode()}.
 *
 * @see <a href="https://github.com/sirensolutions/siren-join/issues/112">Issue #112</a>
 */
public static int hashCode(Map map) {
  int h = 0;
  Iterator<Map.Entry<Object, Object>> i = map.entrySet().iterator();
  while (i.hasNext()) {
    Map.Entry<Object, Object> entry = i.next();
    if (entry.getValue() instanceof Map) {
      h += BitMixer.mix32(entry.getKey().hashCode()) ^ BitMixer.mix32(hashCode((Map) entry.getValue()));
    }
    else if (entry.getValue() instanceof List) {
      h += BitMixer.mix32(entry.getKey().hashCode()) ^ BitMixer.mix32(hashCode((List) entry.getValue()));
    }
    else {
      h += BitMixer.mix32(entry.getKey().hashCode()) ^ BitMixer.mix32(entry.hashCode());
    }
  }
  return h;
}
 
示例2
private static int hashCode(List list) {
  int h = 1;
  for (int i = 0; i < list.size(); i++) {
    Object e = list.get(i);
    if (e instanceof List) {
      h = 31 * h + BitMixer.mix32(hashCode((List) e));
    }
    else if (e instanceof Map) {
      h = 31 * h + BitMixer.mix32(hashCode((Map) e));
    }
    else {
      h = 31 * h + BitMixer.mix32(list.get(i).hashCode());
    }
  }
  return h;
}
 
示例3
@Override
public long valueAt(int index) {
    return BitMixer.mix64(values.valueAt(index));
}
 
示例4
@Override
public long valueAt(int index) {
    return BitMixer.mix64(java.lang.Double.doubleToLongBits(values.valueAt(index)));
}
 
示例5
private static int rehash(int hash) {
    return BitMixer.mix32(hash);
}
 
示例6
static long hash(long value) {
    // Don't use the value directly. Under some cases eg dates, it could be that the low bits don't carry much value and we would like
    // all bits of the hash to carry as much value
    return BitMixer.mix64(value);
}
 
示例7
@Override
long hash(Object val) {
    return BitMixer.mix64(DataTypes.LONG.value(val));
}
 
示例8
@Override
long hash(Object val) {
    return BitMixer.mix64(java.lang.Double.doubleToLongBits(DataTypes.DOUBLE.value(val)));
}