一致性哈希算法实现(java)

发布时间 2023-09-24 19:15:48作者: cs7

代码基本实现

未完待续...........

 

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));
    }