Integer Hashtable

Overview

The IntHashTable class holds a collection of integers which are identified by integer key values. The IntHashTable object may expand to contain an increasing number of integers. It also supports “iterator” functions, which are used to successively visit each integer stored in the hashtable.

Once a IntHashTable is instanced, an approximate number of integers to be stored may be defined using define(). As integers are inserted IntHashTable class will expand its internal storage as required. The method inquire() returns the number of integers which may be managed by the presently allocated storage.

Each new integer is placed in the hashtable using insert(). The total number of integers contained in the hashtable may be found by calling count(). An integer with a specified integer key may be retrieved using lookup(). The method clear() removes all integers from the hashtable. The maximum key used to store any integer may be queried using maxKey(). All keys may be queried using allKeys(). In this case the number of keys returned will be equal to the number of keys returned by count().

Each integer in the hashtable may be processed with an “iterator” construct. The pair of methods initializeIterator() and nextItem() are used to visit each key/integer pair using a loop. Call the first method before the body of the loop to prepare the IntHashTable object for the iteration. Within the loop body, call nextItem(). It will return an integer key and an integer value each time it is called. It will return a zero value when all the integers have been processed. Use initializeOrderedIterator() to visit the integers in monotonically increasing key value.

Class Members Descriptions

The currently available IntHashTable enumerations and functions are described in detail in this section.

class IntHashTable

Integer Hashtable.

Public Types

enum class IntegerParameter

Integer parameter types.

Values:

enumerator UNDEFINED

Undefined value.

Public Functions

ErrorCode getErrorCode()

Return the current ErrorCode of the IntHashTable object.

Returns: ErrorCode - The current error code, or NONE if no error.
Status define(int capacity)

Suggest a number of elements to be stored in the IntHashTable. This is used to allocate the initial array of storage which is used to hold each integer/integer pair. If the number of inserted elements is eventually greater than this initial estimate, storage space will be dynamically expanded to hold the extra integers. This function removes any previously entered integers.

See Also inquire()

Errors
MEMORY is generated if new storage was unable to be allocated.

Parameters:capacity – Estimated number of integers to be held
Returns:Status
Status inquire(int *capacity)

Find the number of integers which may be managed with the presently allocated storage.

See Also define()

Parameters:capacity[out] Number of integers that may be managed
Returns:Status
Status setIntegerParameter(IntegerParameter parameter, int value)

Specify integer parameter parameter ( IntegerParameter ) and value value.

Parameters:
Returns:

Status

Status count(int *itemCount)

Get the number of integers which have been inserted and not yet removed.

Parameters:itemCount[out] Number of integers held in the IntHashTable object
Returns:Status
Status maxKey(int *key)

Get the maximum key value used to store current integers in the IntHashTable.

See Also allKeys()

Parameters:key[out] Maximum key value
Returns:Status
Status allKeys(int keys[])

Get all key values used to store current integers in the IntHashTable. The number of key values returned will be equal to the number of keys returned by count() .

See Also maxKey() , count()

Parameters:keys[out] Array of all keys
Returns:Status
Status emptyKey(int *key)

Find the smallest key with no associated value.

Parameters:key[out] Smallest key with no associated value
Returns:Status
Status insert(int key, int item)

Place the integer value in the IntHashTable object. Associate the integer key with this new integer, and replace any integer which may have been previously associated with this same key.

See Also insertIfAbsent() , lookup()

Errors
  • MEMORY is generated if new storage was unable to be allocated.
  • VALUE is generated if item is zero.

Parameters:
  • key – Integer key value
  • item – Integer value, non zero
Returns:

Status

Status insertIfAbsent(int key, int item, int *oldItem)

Place the integer value in the IntHashTable object. Associate the integer key with this new integer only if no value was previously associated with this same key. If a value was already associated with this key, oldItem returns a value different from zero.

See Also insert()

Errors
  • MEMORY is generated if new storage was unable to be allocated.
  • VALUE is generated if item is zero.

Parameters:
  • key – Integer key value
  • item – Integer value, non zero
  • oldItem[out] Previous integer value associated with key
Returns:

Status

Status lookup(int key, int *item)

Get the integer value associated with the specified key. Returns a zero value if no integer has been entered with this key.

See Also insert()

Parameters:
  • key – Integer key of the desired integer
  • item[out] Integer associated with key
Returns:

Status

Status clear()

Remove all the integers from the IntHashTable.

Returns:Status
Status setName(const char *name)

Set the name of the IntHashTable object. The name has a size limit of MAX_IDENTIFIER_NAME_LENGTH characters.

See Also getName()

Parameters:name – Name to be set
Returns:Status
Status getName(char name[])

Retrieve the name of the IntHashTable object. The name has a size limit of MAX_IDENTIFIER_NAME_LENGTH characters.

See Also setName()

Parameters:name[out] Name of the IntHashTable object
Returns:Status
Status initializeIterator()

Initiate the iteration for sequential access to each integer in the hash table. Each call of nextItem() will return a new item from the hash table together with its associated key. These key/value pairs are visited in arbitrary order. After every integer has been visited, nextItem() will return a key of zero and a zero value until the iteration is restarted using initializeIterator() or initializeOrderedIterator() .

See Also initializeOrderedIterator() , nextItem()

Returns:Status
Status initializeOrderedIterator()

Initiate the iteration for sequential access to each integer in numerical order of the hash table key. Each call of nextItem() will return a new item from the hash table together with its associated key in numerical order. After every integer has been visited, nextItem() will return a key of zero and a zero value.

See Also initializeIterator() , nextItem()

Returns:Status
Status nextItem(int *key, int *item)

Get the next item from the hash table together with its associated key. Returns a key of zero and a zero value when all integers have been visited.

See Also initializeIterator() , initializeOrderedIterator()

Parameters:
  • key[out] Integer key
  • item[out] Integer value
Returns:

Status

Status print()

Print the IntHashTable object information to standard output.

Returns:Status