MGunit documentation

Unit testing for IDL

single page | use frames     summary     class     fields     routine details     file attributes

dist_tools/collection/

mgcohashtable__define.pro

collection

includes main-level program

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.

Examples

Try the main-level example program at the end of this file: IDL> .run mgcohashtable__define

Class description for mgcohashtable

Properties

array_size init
key_type init
value_example init
key_example init
value_type init

Fields

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

keyType 0L

SIZE type of keys; if 8 (structures), examine KEY_EXAMPLE to find type of structure

keyExample ptr_new()

pointer to example structure defining the key type

valueExample ptr_new()

pointer to example structure defining the value type

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

valueType 0L

SIZE type of keys; if 8 (structures), examine VALUE_EXAMPLE to find type of structure

Author information

Author

Michael D. Galloy

Routines

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

topmgcohashtable::_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

topmgcohashtable::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

topmgcohashtable::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

topmgcohashtable::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

topmgcohashtable::_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

topmgcohashtable::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

topmgcohashtable::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

topmgcohashtable::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

topmgcohashtable::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

topmgcohashtable::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

topmgcohashtable::cleanup

mgcohashtable::cleanup

Frees hash table resources, but the resources contained by the hash table.

topmgcohashtable::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

topmgcohashtable__define

mgcohashtable__define

Hash table implementation.

File attributes

Modification date: Wed Apr 22 23:29:03 2009
Lines: 518
Docformat: rst rst