Back to index

moin  1.9.0~rc2
Public Member Functions | Protected Member Functions | Private Attributes
Acme.IntHashtable Class Reference

A Hashtable that uses ints as the keys. More...

Collaboration diagram for Acme.IntHashtable:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 IntHashtable (int initialCapacity, float loadFactor)
 Constructs a new, empty hashtable with the specified initial.
 IntHashtable (int initialCapacity)
 Constructs a new, empty hashtable with the specified initial.
 IntHashtable ()
 Constructs a new, empty hashtable. A default capacity and load factor.
int size ()
 Returns the number of elements contained in the hashtable.
boolean isEmpty ()
 Returns true if the hashtable contains no elements.
synchronized Enumeration keys ()
 Returns an enumeration of the hashtable's keys.
synchronized Enumeration elements ()
 Returns an enumeration of the elements. Use the Enumeration methods.
synchronized boolean contains (Object value)
 Returns true if the specified object is an element of the hashtable.
synchronized boolean containsKey (int key)
 Returns true if the collection contains an element for the key.
synchronized Object get (int key)
 Gets the object associated with the specified key in the.
Object get (Object okey)
 A get method that takes an Object, for compatibility with.
synchronized Object put (int key, Object value)
 Puts the specified element into the hashtable, using the specified.
Object put (Object okey, Object value)
 A put method that takes an Object, for compatibility with.
synchronized Object remove (int key)
 Removes the element corresponding to the key. Does nothing if the.
Object remove (Object okey)
 A remove method that takes an Object, for compatibility with.
synchronized void clear ()
 Clears the hash table so that it has no more elements in it.
synchronized Object clone ()
 Creates a clone of the hashtable. A shallow copy is made,.
synchronized String toString ()
 Converts to a rather lengthy String.

Protected Member Functions

void rehash ()
 Rehashes the content of the table into a bigger table.

Private Attributes

IntHashtableEntry table []
 The hash table data.
int count
 The total number of entries in the hash table.
int threshold
 Rehashes the table when count exceeds this threshold.
float loadFactor
 The load factor for the hashtable.

Detailed Description

A Hashtable that uses ints as the keys.

Definition at line 23 of file IntHashtable.java.


Constructor & Destructor Documentation

Acme.IntHashtable.IntHashtable ( int  initialCapacity,
float  loadFactor 
) [inline]

Constructs a new, empty hashtable with the specified initial.

Definition at line 47 of file IntHashtable.java.

       {
       if ( initialCapacity <= 0 || loadFactor <= 0.0 )
           throw new IllegalArgumentException();
       this.loadFactor = loadFactor;
       table = new IntHashtableEntry[initialCapacity];
       threshold = (int) ( initialCapacity * loadFactor );
       }

Here is the caller graph for this function:

Acme.IntHashtable.IntHashtable ( int  initialCapacity) [inline]

Constructs a new, empty hashtable with the specified initial.

Definition at line 59 of file IntHashtable.java.

       {
       this( initialCapacity, 0.75f );
       }

Constructs a new, empty hashtable. A default capacity and load factor.

Definition at line 67 of file IntHashtable.java.

       {
       this( 101, 0.75f );
       }

Here is the caller graph for this function:


Member Function Documentation

synchronized void Acme.IntHashtable.clear ( ) [inline]

Clears the hash table so that it has no more elements in it.

Definition at line 289 of file IntHashtable.java.

       {
       IntHashtableEntry tab[] = table;
       for ( int index = tab.length; --index >= 0; )
           tab[index] = null;
       count = 0;
       }
synchronized Object Acme.IntHashtable.clone ( ) [inline]

Creates a clone of the hashtable. A shallow copy is made,.

Definition at line 300 of file IntHashtable.java.

       {
       try
           {
           IntHashtable t = (IntHashtable) super.clone();
           t.table = new IntHashtableEntry[table.length];
           for ( int i = table.length ; i-- > 0 ; )
              t.table[i] = ( table[i] != null ) ?
                  (IntHashtableEntry) table[i].clone() : null;
           return t;
           }
       catch ( CloneNotSupportedException e)
           {
           // This shouldn't happen, since we are Cloneable.
           throw new InternalError();
           }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

synchronized boolean Acme.IntHashtable.contains ( Object  value) [inline]

Returns true if the specified object is an element of the hashtable.

Definition at line 105 of file IntHashtable.java.

       {
       if ( value == null )
           throw new NullPointerException();
       IntHashtableEntry tab[] = table;
       for ( int i = tab.length ; i-- > 0 ; )
           {
           for ( IntHashtableEntry e = tab[i] ; e != null ; e = e.next )
              {
              if ( e.value.equals( value ) )
                  return true;
              }
           }
       return false;
       }

Here is the caller graph for this function:

synchronized boolean Acme.IntHashtable.containsKey ( int  key) [inline]

Returns true if the collection contains an element for the key.

Definition at line 124 of file IntHashtable.java.

       {
       IntHashtableEntry tab[] = table;
       int hash = key;
       int index = ( hash & 0x7FFFFFFF ) % tab.length;
       for ( IntHashtableEntry e = tab[index] ; e != null ; e = e.next )
           {
           if ( e.hash == hash && e.key == key )
              return true;
           }
       return false;
       }

Here is the call graph for this function:

synchronized Enumeration Acme.IntHashtable.elements ( ) [inline]

Returns an enumeration of the elements. Use the Enumeration methods.

Definition at line 94 of file IntHashtable.java.

       {
       return new IntHashtableEnumerator( table, false );
       }

Here is the caller graph for this function:

synchronized Object Acme.IntHashtable.get ( int  key) [inline]

Gets the object associated with the specified key in the.

Definition at line 143 of file IntHashtable.java.

       {
       IntHashtableEntry tab[] = table;
       int hash = key;
       int index = ( hash & 0x7FFFFFFF ) % tab.length;
       for ( IntHashtableEntry e = tab[index] ; e != null ; e = e.next )
           {
           if ( e.hash == hash && e.key == key )
              return e.value;
           }
       return null;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Object Acme.IntHashtable.get ( Object  okey) [inline]

A get method that takes an Object, for compatibility with.

Definition at line 158 of file IntHashtable.java.

       {
       if ( ! ( okey instanceof Integer ) )
           throw new InternalError( "key is not an Integer" );
       Integer ikey = (Integer) okey;
       int key = ikey.intValue();
       return get( key );
       }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean Acme.IntHashtable.isEmpty ( ) [inline]

Returns true if the hashtable contains no elements.

Definition at line 79 of file IntHashtable.java.

       {
       return count == 0;
       }
synchronized Enumeration Acme.IntHashtable.keys ( ) [inline]

Returns an enumeration of the hashtable's keys.

Definition at line 86 of file IntHashtable.java.

       {
       return new IntHashtableEnumerator( table, true );
       }

Here is the caller graph for this function:

synchronized Object Acme.IntHashtable.put ( int  key,
Object  value 
) [inline]

Puts the specified element into the hashtable, using the specified.

Definition at line 204 of file IntHashtable.java.

       {
       // Make sure the value is not null.
       if ( value == null )
           throw new NullPointerException();

       // Makes sure the key is not already in the hashtable.
       IntHashtableEntry tab[] = table;
       int hash = key;
       int index = ( hash & 0x7FFFFFFF ) % tab.length;
       for ( IntHashtableEntry e = tab[index] ; e != null ; e = e.next )
           {
           if ( e.hash == hash && e.key == key )
              {
              Object old = e.value;
              e.value = value;
              return old;
              }
           }

       if ( count >= threshold )
           {
           // Rehash the table if the threshold is exceeded.
           rehash();
           return put( key, value );
           } 

       // Creates the new entry.
       IntHashtableEntry e = new IntHashtableEntry();
       e.hash = hash;
       e.key = key;
       e.value = value;
       e.next = tab[index];
       tab[index] = e;
       ++count;
       return null;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Object Acme.IntHashtable.put ( Object  okey,
Object  value 
) [inline]

A put method that takes an Object, for compatibility with.

Definition at line 244 of file IntHashtable.java.

       {
       if ( ! ( okey instanceof Integer ) )
           throw new InternalError( "key is not an Integer" );
       Integer ikey = (Integer) okey;
       int key = ikey.intValue();
       return put( key, value );
       }

Here is the call graph for this function:

void Acme.IntHashtable.rehash ( ) [inline, protected]

Rehashes the content of the table into a bigger table.

Definition at line 170 of file IntHashtable.java.

       {
       int oldCapacity = table.length;
       IntHashtableEntry oldTable[] = table;

       int newCapacity = oldCapacity * 2 + 1;
       IntHashtableEntry newTable[] = new IntHashtableEntry[newCapacity];

       threshold = (int) ( newCapacity * loadFactor );
       table = newTable;

       for ( int i = oldCapacity ; i-- > 0 ; )
           {
           for ( IntHashtableEntry old = oldTable[i] ; old != null ; )
              {
              IntHashtableEntry e = old;
              old = old.next;

              int index = ( e.hash & 0x7FFFFFFF ) % newCapacity;
              e.next = newTable[index];
              newTable[index] = e;
              }
           }
       }

Here is the caller graph for this function:

synchronized Object Acme.IntHashtable.remove ( int  key) [inline]

Removes the element corresponding to the key. Does nothing if the.

Definition at line 257 of file IntHashtable.java.

       {
       IntHashtableEntry tab[] = table;
       int hash = key;
       int index = ( hash & 0x7FFFFFFF ) % tab.length;
       for ( IntHashtableEntry e = tab[index], prev = null ; e != null ; prev = e, e = e.next )
           {
           if ( e.hash == hash && e.key == key )
              {
              if ( prev != null )
                  prev.next = e.next;
              else
                  tab[index] = e.next;
              --count;
              return e.value;
              }
           }
       return null;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Object Acme.IntHashtable.remove ( Object  okey) [inline]

A remove method that takes an Object, for compatibility with.

Definition at line 279 of file IntHashtable.java.

       {
       if ( ! ( okey instanceof Integer ) )
           throw new InternalError( "key is not an Integer" );
       Integer ikey = (Integer) okey;
       int key = ikey.intValue();
       return remove( key );
       }

Here is the call graph for this function:

Here is the caller graph for this function:

int Acme.IntHashtable.size ( ) [inline]

Returns the number of elements contained in the hashtable.

Definition at line 73 of file IntHashtable.java.

       {
       return count;
       }

Here is the caller graph for this function:

synchronized String Acme.IntHashtable.toString ( ) [inline]

Converts to a rather lengthy String.

Definition at line 319 of file IntHashtable.java.

       {
       int max = size() - 1;
       StringBuffer buf = new StringBuffer();
       Enumeration k = keys();
       Enumeration e = elements();
       buf.append( "{" );

       for ( int i = 0; i <= max; ++i )
           {
           String s1 = k.nextElement().toString();
           String s2 = e.nextElement().toString();
           buf.append( s1 + "=" + s2 );
           if ( i < max )
              buf.append( ", " );
           }
       buf.append( "}" );
       return buf.toString();
       }

Here is the call graph for this function:


Member Data Documentation

int Acme.IntHashtable.count [private]

The total number of entries in the hash table.

Definition at line 29 of file IntHashtable.java.

The load factor for the hashtable.

Definition at line 35 of file IntHashtable.java.

The hash table data.

Definition at line 26 of file IntHashtable.java.

Rehashes the table when count exceeds this threshold.

Definition at line 32 of file IntHashtable.java.


The documentation for this class was generated from the following file: