在google/guava@GitHub中, Hashing类实现了一致的 hashing@wiki。该方法consistentHash
需要一个HashCode
对象:
public static int consistentHash(HashCode hashCode, int buckets) {
return consistentHash(hashCode.padToLong(), buckets);
}
我正在实现一个原型分布式键值存储,并希望通过自定义Row
键和Column
键对键空间进行分区。
public int locateNodeIndexFor(Row r, Column c, int buckets) {
HashCode hashCode = // How to generate a HashCode based on @param r and @param c?
return Hashing.consistentHash(hashCode, buckets);
}
这里 class Row
(和 class Column
)只是一个String
字段的包装器,并且有自己的hashCode()
方法。我的问题是如何HashCode
根据@param r 和@param c生成alocateNodeIndexFor
以便调用Hashing#consistentHash
?