objects/
mgcohashtable__define.pro
collection
A hash table which can hash any kind of IDL variables. To hash objects, simply make sure each object implements the hashCode method. See the help for the calcHashCode method for details.
Author information
- Author
Michael D. Galloy
Class description for mgcohashtable
Properties
Properties in mgcohashtable
- array_size init
- key_example init
- key_type init
- value_example init
- value_type init
Fields
Fields in mgcohashtable
- arraySize 0L
size of the key and value arrays
- keyArray ptr_new()
pointer to array of keys; type of array is specified by KEY_TYPE field for non-structures and by KEY_EXAMPLE field for structures
- keyExample ptr_new()
pointer to example structure defining the key type
- keyType 0L
SIZE type of keys; if 8 (structures), examine KEY_EXAMPLE to find type of structure
- valueArray ptr_new()
pointer to array of values; type of array is specified VALUE_TYPE field for non-structures and by VALUE_EXAMPLE field for structures
- valueExample ptr_new()
pointer to example structure defining the value type
- valueType 0L
SIZE type of keys; if 8 (structures), examine VALUE_EXAMPLE to find type of structure
Routines
Routines from mgcohashtable__define.pro
result = mgcohashtable::_getHistogram()
Returns an array with the same number of elements as the hash array.
mgcohashtable::print [, lun]
Prints keys and values to a given LUN.
result = mgcohashtable::keys( [count=integral])
Returns an array of the keys of the hash table.
result = mgcohashtable::values( [count=integral])
Returns an array of the values of the hash table.
result = mgcohashtable::_calcHashCode(key)
Calculates the hash code of the given key.
result = mgcohashtable::get(key [, /found])
Finds the value associated with the given key.
mgcohashtable::remove, key [, /found]
Removes the value associated with the given key.
mgcohashtable::put, key, value [, /found]
Puts the key-value pair into the hash table or updates the value for the key if it is already in the hash table.
result = mgcohashtable::count()
Find the number of key-value pairs in the hash table
result = mgcohashtable::isEmpty()
Determines if the hash table is empty.
mgcohashtable::cleanup
Frees hash table resources, but the resources contained by the hash table.
result = mgcohashtable::init( [array_size=integral], key_type=0-15, value_type=0-15, key_example=key type, value_example=value type)
Create a hash table.
mgcohashtable__define
Hash table implementation.
Routine details
top source mgcohashtable::_getHistogramprivate
result = mgcohashtable::_getHistogram()
Returns an array with the same number of elements as the hash array. The value each element of the array is the number of elements in that "bin" of the mgcohashtable. This could be useful in determining the effectiveness of the hash code calculations.
Return value
long array
top source mgcohashtable::print
mgcohashtable::print [, lun]
Prints keys and values to a given LUN. Prints to STDOUT if LUN not given.
Parameters
- lun in optional type=LUN default=-1
logical unit number for output
top source mgcohashtable::keys
result = mgcohashtable::keys( [count=integral])
Returns an array of the keys of the hash table.
Return value
an array of the keys of the hash table or -1 if no keys
Keywords
- count out optional type=integral
number of keys in the hash table
top source mgcohashtable::values
result = mgcohashtable::values( [count=integral])
Returns an array of the values of the hash table.
Return value
an array of the values of the hash table or -1 if no values
Keywords
- count out optional type=integral
number of values in the hash table
top source mgcohashtable::_calcHashCode
result = mgcohashtable::_calcHashCode(key)
Calculates the hash code of the given key. The index of the array element the key's value will be stored in will be the hash code value MOD the array size.
If a hash tbale of object references is desired, then the objects should implement the hashCode method. This function should accept no parameters and return an unsigned long.
This method should not normally be called directly.
If the given default hash function is not doing well (use the _getHistogram method to find out how well it's spreading out the keys), subclass this class and implement a more appropriate hash function.
Return value
hash code (unsigned long integer); 0 if null pointer or object, undefined variable; or an object that does not implement hashCode
Parameters
- key in type=key type
key to find hash code of
top source mgcohashtable::get
result = mgcohashtable::get(key [, /found])
Finds the value associated with the given key.
Return value
the value of the associated key or -1L if not found
Parameters
- key in type=key type
key to look up
Keywords
- found out optional type=boolean
true if value found for given key
top source mgcohashtable::remove
mgcohashtable::remove, key [, /found]
Removes the value associated with the given key.
Parameters
- key in type=key type
key to look up
Keywords
- found out optional type=boolean
true if value found for given key
top source mgcohashtable::put
mgcohashtable::put, key, value [, /found]
Puts the key-value pair into the hash table or updates the value for the key if it is already in the hash table.
Parameters
- key in required type=key type
key to place in the table
- value in required type=value type
value to place in the table
Keywords
- found out optional type=boolean
pass a named variable that is set to true if the key was already in the table and is updated
top source mgcohashtable::count
result = mgcohashtable::count()
Find the number of key-value pairs in the hash table
Return value
the number of key-value pairs in the hash table
top source mgcohashtable::isEmpty
result = mgcohashtable::isEmpty()
Determines if the hash table is empty.
Return value
0 if the table is empty, 1 if it contains any key-value pairs
top source mgcohashtable::cleanup
mgcohashtable::cleanup
Frees hash table resources, but the resources contained by the hash table.
top source mgcohashtable::init
result = mgcohashtable::init( [array_size=integral], key_type=0-15, value_type=0-15, key_example=key type, value_example=value type)
Create a hash table.
Return value
1 if successful; 0 otherwise
Keywords
- array_size in optional type=integral default=101
the size of the hash table; generally a prime is a good choice
- key_type in type=0-15
type code for keys; key_type or key_example must be present
- value_type in type=0-15
type code for values; value_type or key_example must be present
- key_example in type=key type
example of key type; key_type or key_example must be present
- value_example in type=value type
example of value type; value_type or value_example must be present
File attributes
Modification date: | Mon Dec 8 21:40:26 2008 |
Lines: | 258 |
Docformat: | rst rst |