简体   繁体   English

Java HashObjObjMap <K, V> vs HashMap <K, V>

[英]Java HashObjObjMap<K, V> vs HashMap<K, V>

What is the difference between Koloboke HashObjObj<K, V> and Java util HashMap<K, V> ? Koloboke HashObjObj<K, V>和Java util HashMap<K, V>什么区别?

I am aware of the performance that Koloboke provides but there might be instances that K/V turn out to be a Integer/Long. 我知道Koloboke所提供的性能,但可能会发现K / V确实是Integer / Long。 Generally if known HashLongObjMap would be recommended but what happens when K/V come in as generics. 通常,如果推荐使用已知的HashLongObjMap ,但是当K / V作为泛型进入时会发生什么。 From what I understand using HashLongObjMap uses long primitive as the key but what are the differences that come in when HashObjObjMap<Long, V> is used? 据我了解,使用HashLongObjMap使用long原语作为键,但是使用HashObjObjMap<Long, V>有什么区别?

Eg: 例如:

HashLongObjMap<V> map1 = HashLongObjMaps.newImmutableMap();

Vs VS

HashObjObjMap<K, V> map2 = HashObjObjMaps.newImmutableMap();

The difference between HashObjObjMap and java.util.HashMap is algorithm and itnernal memory layout. HashObjObjMapjava.util.HashMap之间的区别是算法和行程内存布局。 HashObjObjMap is an open-addressing hash table with linear probing, storing keys and values in the same flat Object[] array, in interspersed order: [key1, value1, key2, value2, ...]. HashObjObjMap是一个带有线性探测的开放式哈希表,将键和值以散列的顺序存储在同一平面Object[]数组中:[key1,value1,key2,value2,...]。 Entry objects don't exist, they are created only when required by Map API (ie entrySet() iteration). Entry对象不存在,仅在Map API需要时(即entrySet()迭代)创建它们。 HashMap is a hash table with separate chaining, keys and values are stored in separate Entry objects. HashMap是具有单独链接的哈希表,键和值存储在单独的Entry对象中。

HashLongObjMap stores keys as primitive long s, HashObjObjMap has ordinary Object keys. HashLongObjMap将键存储为原始long ,而HashObjObjMap具有普通的Object键。

HashObjObjMap<Long, V> cannot call HashLongObjMap internally because they have slightly different contract, eg the latter cannot hold null key. HashObjObjMap<Long, V>无法HashLongObjMap内部调用HashLongObjMap因为它们的合同略有不同,例如后者不能持有null键。 Also I don't see much sense in it, if you need long keys you should just explicitly use HashLongObjMap yourself instead of HashObjObjMap and relying on some implicit "optimizations". 同样,我也没有多大意义,如果您需要long键,则应该自己显式使用HashLongObjMap而不是HashObjObjMap并依靠一些隐式的“优化”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM