idllib

Personal IDL library for M. Galloy

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

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

Inheritance

Properties

count get
array_size init
key_type get init
value_example init
key_example init
value_type get init

Author information

Author

Michael D. Galloy

Routines

result = mgcohashtable::_overloadBracketsRightSide(isRange, ss1, ss2, ss3, ss4, ss5, ss6, ss7, ss8)

Allows hash table access with brackets.

mgcohashtable::_overloadBracketsLeftSide, objref, value, isRange, ss1, ss2, ss3, ss4, ss5, ss6, ss7, ss8

Allows setting values of the array list by array index.

result = mgcohashtable::_overloadPlus(left, right)

Concatenate two hash tables.

mgcohashtable::_findKeyPos, key [, hcode] [, keyIndex]

Helper method to find the position of a key.

result = mgcohashtable::_findNextKey(key [, /done])

Finds the next key in the hash, if present.

result = mgcohashtable::_overloadForeach(value [, key])

Allows an array list to be used in a FOREACH loop.

result = mgcohashtable::_overloadPrint()

Returns the elements to print.

result = mgcohashtable::_overloadHelp(varname)

Returns a string describing the array list.

result = mgcohashtable::_overloadSize()

Returns the number of elements in the array list.

mgcohashtable::getProperty, key_type=key_type, value_type=value_type, count=count
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 [, default=any] [, /found])

Finds the value associated with the given key.

result = mgcohashtable::setdefault(key [, default=any])

Finds the value associated with the given key, but sets the value for the key to default if the key is not found.

mgcohashtable::remove [, key] [, /all] [, /found]

Removes the value associated with the given key.

mgcohashtable::update, hashtable

Adds all the keys of hashtable to the this hash table (replacing values in this hash table if they are in present in hashtable).

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

result = mgcohashtable::_overloadBracketsRightSide(isRange, ss1, ss2, ss3, ss4, ss5, ss6, ss7, ss8)

Allows hash table access with brackets.

Return value

elements of the same type as the array list

Parameters

isRange
ss1
ss2
ss3
ss4
ss5
ss6
ss7
ss8

Examples

Try:

IDL> h = obj_new('MGcoHashTable', key_type=7, value_type=4) IDL> h->put, 'Boulder', 72.0 IDL> print, h['Boulder'] 72.0000

top source mgcohashtable::_overloadBracketsLeftSide

mgcohashtable::_overloadBracketsLeftSide, objref, value, isRange, ss1, ss2, ss3, ss4, ss5, ss6, ss7, ss8

Allows setting values of the array list by array index.

Parameters

objref
value
isRange
ss1
ss2
ss3
ss4
ss5
ss6
ss7
ss8

Examples

Try:

IDL> h = obj_new('MGcoHashTable', key_type=7, value_type=4) IDL> h['Boulder'] = 72.0 IDL> print, h['Boulder'] 72.0000

top source mgcohashtable::_overloadPlus

result = mgcohashtable::_overloadPlus(left, right)

Concatenate two hash tables.

Return value

MGcoHashTable object

Parameters

left
right

top source mgcohashtable::_findKeyPos

mgcohashtable::_findKeyPos, key [, hcode] [, keyIndex]

Helper method to find the position of a key.

Parameters

key in required type=key type

key to find position of

hcode out optional type=long

hash code of the key

keyIndex out optional type=long

index within list at hash code

top source mgcohashtable::_findNextKey

result = mgcohashtable::_findNextKey(key [, /done])

Finds the next key in the hash, if present.

Return value

next key, or -1L if last key

Parameters

key in required type=key type or undefined

key to "increment"

Keywords

done out optional type=boolean

set to a named variable to return if a next key is present, 0 if it is and if not, i.e., done

top source mgcohashtable::_overloadForeach

result = mgcohashtable::_overloadForeach(value [, key])

Allows an array list to be used in a FOREACH loop.

Return value

1 if there is an item to return, 0 if not

Parameters

value out required type=list type

value to return as the loop

key in out optional type=undefined/long

key is undefined for first element, otherwise the index of the last element returned

top source mgcohashtable::_overloadPrint

result = mgcohashtable::_overloadPrint()

Returns the elements to print. Called by PRINT to determine what should be displayed.

Return value

array of elements of the type of the array list

top source mgcohashtable::_overloadHelp

result = mgcohashtable::_overloadHelp(varname)

Returns a string describing the array list. Called by the HELP routine.

Return value

string

Parameters

varname in required type=string

name of the variable to use when outputting help information

top source mgcohashtable::_overloadSize

result = mgcohashtable::_overloadSize()

Returns the number of elements in the array list. Called by SIZE to retrieve information about the size of the variable.

Return value

long

top source mgcohashtable::getProperty

mgcohashtable::getProperty, key_type=key_type, value_type=value_type, count=count

Keywords

key_type
value_type
count

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 [, default=any] [, /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

default in optional type=any

value to return if key is not present

found out optional type=boolean

true if value found for given key

top source mgcohashtable::setdefault

result = mgcohashtable::setdefault(key [, default=any])

Finds the value associated with the given key, but sets the value for the key to default if the key is not found.

Return value

the value of the associated key or -1L if not found

Parameters

key in type=key type

key to look up

Keywords

default in optional type=any

value to return and set the value for the key if key is not present

top source mgcohashtable::remove

mgcohashtable::remove [, key] [, /all] [, /found]

Removes the value associated with the given key.

Parameters

key in optional type=key type

key to look up; not needed if ALL is set

Keywords

all in optional type=boolean

set to remove all key-value pairs

found out optional type=boolean

true if value found for given key

top source mgcohashtable::update

mgcohashtable::update, hashtable

Adds all the keys of hashtable to the this hash table (replacing values in this hash table if they are in present in hashtable).

Parameters

hashtable in required type=MGcoHashTable

MGcoHashTable to update this hash table with

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

top source mgcohashtable__define

mgcohashtable__define

Hash table implementation.

File attributes

Modification date: Mon Nov 29 18:32:28 2010
Lines: 865
Docformat: rst rst
Personal library of Michael Galloy
Contact me if you have enhancement requests or bug fixes.