JFCML - JFC/Swing
XML Markup Language

com.metasolutions.util
Class SimpleHashMap

java.lang.Object
  extended by com.metasolutions.util.SimpleHashMap
All Implemented Interfaces:
Serializable

public class SimpleHashMap
extends Object
implements Serializable

An optimized HashMap which is not part of the Collections Framework. This HashMap has been designed for execution speed over all other concerns. This HashMap uses a "power of 2" implementation with a singly-linked collision list. This implemenation uses 0 divisions, 1 multiplication in the constructor, and 1 multiplication per rehash() operation.

The HashMap can be futher optimized by using hashcodes instead of keys. This is an admittedly dangerous operation: the array returned from getKeys() would be missing keys if they were not specified in a put() operation. As a rule of thumb, if you would need to use a getKeys() or getHashCodes() operation, you should fill the map with all keys, or all hashcodes, respectively. Note that getHashCodes will always return all hashcodes, whether keys or hashcodes were used.

This implementation is thread-safe, but it should be noted that the Collection classes provided in the new java.util.concurrent package will undoubtedly be a superior solution for multithreaded applications.

Version:
0.9 May 29, 2005
Author:
Shawn Curry
See Also:
Serialized Form

Constructor Summary
SimpleHashMap()
           
SimpleHashMap(int cap)
           
 
Method Summary
 void clear()
           
 Object get(int hash)
           
 Object get(Object key)
           
 int[] getHashCodes()
           
 Object[] getKeys()
           
 Object put(int hash, Object value)
           
 Object put(Object key, Object value)
           
 Object remove(int hash)
           
 Object remove(Object key)
           
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleHashMap

public SimpleHashMap()

SimpleHashMap

public SimpleHashMap(int cap)
Method Detail

clear

public void clear()

size

public int size()

put

public Object put(Object key,
                  Object value)

put

public Object put(int hash,
                  Object value)

get

public Object get(Object key)

get

public Object get(int hash)

remove

public Object remove(Object key)

remove

public Object remove(int hash)

getHashCodes

public int[] getHashCodes()

getKeys

public Object[] getKeys()

SourceForge.net
java.net

Copyright 2004-2005 Shawn Curry, http://jfcml.sourceforge.net
Licensed under the Academic Free License version 2.1