Class Hashtable

Object
   |
   +--Hashtable

class Hashtable

This class implements a hashtable, which maps keys to values.


Constructor Summary
Hashtable ()
           
 
Method Summary
 function clear()
           Clears the hashtable so that it contains no keys.
 function containsKey(key)
           Tests if the specified string is a key in the hashtable.
 function containsValue(value)
           Tests if the specified object is a value in the hashtable.
 function get(key)
           Returns the value for the specifies key.
 function isEmpty()
           Tests if the hashtable maps no keys to values.
 function keys()
           Returns an array of the keys in the hashtable.
 function put(key, value)
           Maps the specified key to the specified value in the hashtable.
 function remove(key)
           Removes the key (and its corresponding value) from the hashtable.
 function size()
           Returns the size of the hastable.
 function toArray()
           Returns an array of the values in the hashtable.
 function values()
           Returns the hashtable.

Constructor Detail

Hashtable

function Hashtable()

Method Detail

clear

function clear()
Clears the hashtable so that it contains no keys.


containsKey

function containsKey(key)
Tests if the specified string is a key in the hashtable.

Parameters:
key - Possible key.

Returns:
True if specified string is a key in the hashtable; false otherwise.

containsValue

function containsValue(value)
Tests if the specified object is a value in the hashtable.

Parameters:
value - Possible value.

Returns:
True if specified string is a value in the hashtable; false otherwise.

get

function get(key)
Returns the value for the specifies key.

Parameters:
key - Possible key.

Returns:
The value to which the key is mapped in the hashtable; null otherwise.

isEmpty

function isEmpty()
Tests if the hashtable maps no keys to values.

Returns:
True if the hastable contains keys; false if the hashtable is empty.

keys

function keys()
Returns an array of the keys in the hashtable.

Returns:
An array of the keys in the hashtable.

put

function put(key, value)
Maps the specified key to the specified value in the hashtable.

Parameters:
value - The value to associate with the specified key.

key - The hashtable key.


remove

function remove(key)
Removes the key (and its corresponding value) from the hashtable.

Parameters:
key - The key to remove.


size

function size()
Returns the size of the hastable.

Returns:
The size of the hastable.

toArray

function toArray()
Returns an array of the values in the hashtable.

Returns:
An array of the values in the hashtable.

values

function values()
Returns the hashtable. This routine is usefull to iterate through the hashtable as shown by the next example:
var table = new Hashtable();
var s     = "";

table.put ("key1", "Mary ");
table.put ("key2", "had ");
table.put ("key3", "etc...");

for (var i in table.values())
{
s+=table.values()[i];
}
Running the routine will result in the string s containing "Mary had etc..."

Returns:
The hashtable.