ok so im trying to create something along the lines of a HashMap except the keys are integers, (I'm not using an array because the integers a quite random)
so i created 2 simple classes. The IntMapEntry is an entry for this map, it contains only an object as the value and an integer as the key. The IntMap (clever name, i know…) is another object which contains a collection of IntMapEntries.
The trouble that i am having, is that while my class is much simpler than HashMap, for some reason it is much slower in every aspect.
I'll start with the constructor for now, because this really confuzes me.
my code for the IntMap constructor is
public IntMap(int size){
entries = new IntMapEntry[size];
}
mean while for hashmap
it's
public HashMap(int initialCapacity, float loadFactor)
250 {
251 if (initialCapacity < 0)
252 throw new IllegalArgumentException("Illegal Capacity: "
253 + initialCapacity);
254 if (! (loadFactor > 0)) // check for NaN too
255 throw new IllegalArgumentException("Illegal Load: " + loadFactor);
256
257 if (initialCapacity == 0)
258 initialCapacity = 1;
259 buckets = new HashEntry[initialCapacity];
260 this.loadFactor = loadFactor;
261 threshold = (int) (initialCapacity * loadFactor);
262 }
now IntMap takes 2,262,578 nanoseconds to construct while HashMap takes 39,112 nano seconds. Quite a difference, no?
So what am i missing? thanks