You are currently viewing a snapshot of taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to, please file a bug.

All Packages  This Package  Class Hierarchy  Class Search  Index

Class calypso.util.IDMap


An identifier mapper. This provides a 1-1 map between strings and integers where the strings are unique within the map.

public class  IDMap
     extends java.lang.Object
          // Fields 12
     private static final int A;
     private static final int DEFAULT;
     private static final int EMPTY;
     private int fCapacity;
     private int fCount;
     private int[] fHashCodes;
     private int fIndexMask;
     private Object[] fKeys;
     private int fNumStrings;
     private int fShift;
     private String[] fStrings;
     private int[] fValues;

          // Constructors 1
     public IDMap();

          // Methods 11
     private int addString(String);
     private void grow();
     private final int hashCodeForString(String);
     private final int hashCodeForStringBuf(StringBuf);
     public String idToString(int);
     private final boolean keysAreEqual(Object, Object);
     public synchronized int stringBufToID(StringBuf);
     public synchronized String stringBufToString(StringBuf);
     public synchronized int stringToID(String);
     public synchronized String stringToString(String);
     private int tableIndexFor(Object, int);



   private Object[] fKeys


   private int[] fHashCodes


   private int[] fValues


   private String[] fStrings


   private int fNumStrings


   private int fShift


   private int fIndexMask


   private int fCount


   private int fCapacity


   private static final int A

For the multiplicative hash, choose the golden ratio:
     A = ((sqrt(5) - 1) / 2) * (1 << 32)
ala Knuth...


   private static final int EMPTY

We use EMPTY and REMOVED as special markers in the table. If some poor object returns one of these two values as their hashCode, it is wacked to DEFAULT.


   private static final int DEFAULT



   public IDMap() 



   public synchronized int stringToID(String aStr) 

Given a string, find an id for it. If the string is already present return the old id. Otherwise allocate a new one.


   public synchronized int stringBufToID(StringBuf aStrBuf) 

Given a StringBuf, find an id for it. If the string is already present return the old id. Otherwise allocate a new one.


   public synchronized String stringBufToString(StringBuf aStrBuf) 


   public synchronized String stringToString(String aStr) 

If the argument string is already present in the map return the original string object. Otherwise, allocate a new id and return the argument string.


   public String idToString(int aID) 

Given an id, return the string it maps to.


   private int addString(String aString) 

Add string to the end of the internal strings array. Return the index in the array.


   private final int hashCodeForString(String str) 

Provide hashcode for a given key


   private final int hashCodeForStringBuf(StringBuf strBuf) 


   private final boolean keysAreEqual(Object aKey1, 
                                      Object aKey2) 


   private int tableIndexFor(Object aKey, 
                             int aHash) 

Primitive method used internally to find slots in the table. If the key is present in the table, this method will return the index under which it is stored. If the key is not present, then this method will return the index under which it can be put. The caller must look at the hashCode at that index to differentiate between the two possibilities.


   private void grow() 

Grows the table by a factor of 2 (or creates it if necessary). All the REMOVED markers go away and the elements are rehashed into the bigger table.

All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.4