From subsecret
Jump to: navigation, search
Line 6: Line 6:


=Download=
=Download=
abc
JAR also contains source code
 
{| class="wikitable"
!Version
!File
!Description
|-
|1.00
|http://files.subsecret.dk/ColtHashMap100.jar
|Initial release
|}


==Changes to original code==
==Changes to original code==

Revision as of 11:24, 16 June 2013

Extension of Colt HashMap using Generics for storage of Objects

This is based on part of the code from Colt Project: http://acs.lbl.gov/software/colt/ The Colt Project is made before generics was introduced in Java. This means that the HashMap from Colt Project cannot be used as a drop-in replacement for Java's HashMap.

This version contains only the HashMap part of Colt Project (version 1.2.0) and adds the support for generics, so that it can now be used as a drop-in replacement for Java's HashHamp

Download

JAR also contains source code

Version File Description
1.00 http://files.subsecret.dk/ColtHashMap100.jar Initial release

Changes to original code

  • Removed all non-hashmap relevant code
  • Fixed bug where OpenLongObjectHashMap.indexOfValue(...) and OpenIntObjectHashMap.indexOfValue(...) used "==" rather than equals for Object types.
  • Created new interfaces and classes for wrapping Colt Project HashMap in Java's Map<K,V> interface.

Usage

Class Key type Value type
ColtIntHashMap Int Object
ColtIntIntHashMap Int Int
ColtQuickIntIntHashMap Int Int
ColtIntDoubleHashMap Int Double
ColtLongHashMap Long Object
ColtDoubleIntHashMap Double Int

Existing code can easily be changed to use new HashMaps's.

//From
Map<Integer, String> map = new HashMap<Integer,String>();
map.put(3,"test");

//To
Map<Integer, String> map = new ColtIntHashMap<String>();
map.put(3,"test");

//For maximum performance, its necessary to use the original type when putting and retrieving from the map.
Map<Integer, String> map = new ColtIntHashMap<String>();
((ColtIntHashMap<String>)map).put(3,"test");

Benchmark

JVM options: -Xms8g -Xmx8g Insertions: 20 million Removals: 6 million Contains key: 4 million

Benchmark of Integer,Object

JVM 1.6

Map Memory usage (mb) Insertion time (sec.)
Java HashMap
Colt HashMap
Colt (Native) HashMap
Colt (IntInt) HashMap
Colt (Quick IntInt) HashMap

JVM 1.7

Benchmark of Integer,Integer