首页  

使用int作为key的IntHashMap     所属分类 java 浏览量 1252
使用 int 代替 Integer 作为key  

节省内存  
定位桶查找元素 不需要复杂的hash计算 效率高


    public Object get(int key) {
        Entry tab[] = table;
        int hash = key;
        int index = (hash & 0x7FFFFFFF) % tab.length;
        for (Entry e = tab[index]; e != null; e = e.next) {
            if (e.hash == hash) {
                return e.value;
            }
        }
        return null;
    }
    
    
IntHashMap map = new IntHashMap();
map.put(1, "a");
map.put(2, "b");
		
System.out.println(map.get(1));
System.out.println(map.get(2));

完整代码
https://gitee.com/dyyx/hellocode/blob/master/src/dyyx/fast/IntHashMap.java

上一篇     下一篇
nacos介绍

nacos Java客户端使用

threadlocal实例及原理

netty高性能要点

redis要点整理

从高级程序员到CTO