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.

  • Definition
    • define() - Define suggested number of stored items
    • inquire() - Get current storage capacity
  • Set and query elements
    • count() - Get number of contained integers
    • maxKey() - Get maximum key value
    • allKeys() - Get all key values
    • emptyKey() - Find the first key with no value
    • insert() - Place integer at specified location
    • insertIfAbsent() - Place an integer in the hashtable if the key is not already defined
    • lookup() - Find integer at specified location
    • clear() - Remove all integers
    • initializeIterator() - Prepare to successively visit each integer
    • initializeOrderedIterator() - Monotonically increasing integer key
    • nextItem() - Return the next integer in the sequence
  • General functions
    • getErrorCode() - Return the current error code
    • setName() - Set name
    • getName() - Get name
    • print() - Print content

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

HOOPS_CAE_EXTERN ErrorCode getErrorCode ()

Return the current ErrorCode of the IntHashTable object.

Returns: ErrorCode - The current error code, or NONE if no error.
HOOPS_CAE_EXTERN 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
HOOPS_CAE_EXTERN 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
HOOPS_CAE_EXTERN Status setIntegerParameter (IntegerParameter parameter, int value)

Specify integer parameter parameter ( IntegerParameter ) and value value.

Parameters:
Returns:

Status

HOOPS_CAE_EXTERN 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
HOOPS_CAE_EXTERN 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
HOOPS_CAE_EXTERN 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
HOOPS_CAE_EXTERN Status emptyKey (int *key)

Find the smallest key with no associated value.

Parameters:key[out] Smallest key with no associated value
Returns:Status
HOOPS_CAE_EXTERN 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

HOOPS_CAE_EXTERN 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

HOOPS_CAE_EXTERN 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

HOOPS_CAE_EXTERN Status clear ()

Remove all the integers from the IntHashTable.

Returns:Status
HOOPS_CAE_EXTERN 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
HOOPS_CAE_EXTERN 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
HOOPS_CAE_EXTERN 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
HOOPS_CAE_EXTERN 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
HOOPS_CAE_EXTERN 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

HOOPS_CAE_EXTERN Status print ()

Print the IntHashTable object information to standard output.

Returns:Status