一致性哈希算法实现(java)
代码基本实现
未完待续...........
public static void main(String[] args) {
TreeMap<Integer,String> hashNodes = new TreeMap<>();
hashNodes.put(1,"1.1.1.1");
hashNodes.put(4,"1.1.1.2");
hashNodes.put(7,"1.1.1.3");
hashNodes.put(8,"1.2.2.2");
hashNodes.put(11,"1.2.2.3");
SortedMap<Integer, String> sortedMap = hashNodes.tailMap(2);
Integer firstKey = sortedMap.firstKey();
System.out.println(firstKey);
System.out.println(sortedMap.get(firstKey));
}

浙公网安备 33010602011771号