back to index
HashTable
- an associative array that is indexed with Strings
- can be accessed in custom C++ extensions
Inheritance
Object -> HashTable
Properties
numElements - - number of used elements
maxElements - - number of available elements
Methods
int addInt (String _name, int _i) - create new integer entry
int addFloat (String _name, float _f) - create new float entry
int addObject (String _name, Object _o) - create new object (copy) entry
int addObjectRef (String _name, Object _o) - create new object (reference) entry
int addString (String _name, String _s) - create new string (copy) entry
int alloc (int _num) - allocate room for _num entries (locked to prime numbers)
delete (String _name) - delete entry (if exists)
int exists (String _name) - test if entry _name exists
free () - discard all elements
<var> get (String _name) - return hashtable entry _name (reference)
<var> getDeref (String _name) - return hashtable entry _name (value)
String getString () - return String representation of HashTable
int getNumElements () - return number of used elements (numElements)
int getMaxElements () - return number of available elements (maxElements)
String getString () - convert array to string representation
int keysToArray (Object _array) - write keys to _array; return number of keys or 0
int valuesToArray (Object _array) - write values to _array; return number of keys or 0
set (String _key, Value _val) - set/create entry and grab value _val
setInt (String _key, int _val) - set/create integer entry
setFloat (String _key, float _val) - set/create float entry
setObject (String _key, Object _val) - set/create entry which holds a reference to _val
setCopy (String _key, Object _val) - set/create entry which holds a copy of _val
setString (String _key, String _val) - set/create entry which holds a copy of _val
Example
int n=150;
HashTable hash1; hash1.alloc(10000);
HashTable hash2; hash2.alloc(10000);
int i=0;
for(i=0; i<10000; i++) {
hash1["foo_" + i] = i;
}
loop(n) {
String k;
foreach k in hash1
hash2[k] += hash1[k];
}
back to index