A HashTable can hold items of any class. It is indexed by any
item which supports the hashing function. The usual types of index are
as follows:
A hash-table is an array of chains. The hashing function is used to determine which chain the item will appear in -- this chain is then searched to find the item.
The number of chains within a Carapace hash-table is always a power of 2.
The create function is used to create a HashTable
to have 8 chains:
(create HashTable 3)
The table can be initailised by supplying an attribute-value list on construction e.g.
(create HashTable 3 (list (list 1 2) (list 3 4)))
Note that the default number of chains is 8 so the following expression is valid:
(create HashTable)
| property name | property type | description |
|---|---|---|
chains |
Integer | the number of chains within the hash-table -- always a power of 2 |
| method name | description |
|---|---|
set |
set an element within the array |
get |
get an element from the array |
resize |
re-size the hash-table by changing its number of chains |
count |
count the number of items within the table -- only items having a
value not equal to the empty List ()
are counted |
keys |
return the list of keys from the hash-table -- these are not returned in any particular order |
list |
get all the data from the table as a list of attribute/value pairs |
clear |
remove all data from the hash-table |
setSet an element within the hash-table. Any previous value which had the same key is superseded.
Arguments:
| key | Object |
| value | Object |
Return type: the empty List ()
get
Get an element from the hash-table. If there is no such key, the empty
List () is returned.
Arguments:
| key | Object |
Return type: Object
resizeRe-size the hash-table by changing its number of chains. The new number of chains is made to be 2 to the supplied power.
Arguments:
| newSize | Integer |
Return type: the empty List ()
count
Count the number of items within the table -- only items having a
value not equal to the empty List ()
are counted.
Arguments: none
Return type: Integer
keysReturn the list of keys from the hash-table -- these are not returned in any particular order.
Arguments: none
Return type: List
listGet all the data from the table as a list of attribute/value pairs.
Arguments: none
Return type: List
clearRemove all data from the hash-table.
Arguments: none
Return type: the empty List ()
| Contents | Index | Current topic: objects | Related links: built-in objects |