Integer Vectors

Overview

The IntVector class is designed to hold an arbitrarily large, extensible series of integer numbers. The class functions allow the user to set and query individual integer numbers in a vector using an integer index key. The integer numbers are guaranteed to be contiguous in memory with respect to the integer index key.

Once a IntVector object is instanced, an approximate number of integers to be stored may be defined using define(). This allocates an internal array for the storage of integer values. As integer values are set the IntVector module will adjust memory as required. The actual maximum index referenced or defined may be determined by calling inquire(). The individual integers are addressed by an index which is greater than or equal to zero. The validity of the zero index may be toggled using setIntegerParameter().

Integer values are initially zero. Integer values may be set by calling set(). A integer value may be returned for a given index using get(). The total number of nonzero integer values contained in the vector may be found by calling count().

The index of each nonzero integer value in the vector may be returned with an “iterator” construct. The pair of methods initializeIterator() and nextItem() are used to visit each nonzero value using a loop. Call the first method before the body of the loop to prepare the IntVector object for the iteration. Within the loop body, call nextItem(). It will return the index to the next nonzero value each time it is called. It will return an index of -1 when all of the nonzero values have been processed.

Class Members Descriptions

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

class IntVector

Integer Vectors.

Public Types

enum class IntegerParameter

Integer parameters for IntVector.

Values:

enumerator INCLUDE_ZERO

Validity of zero index.

Public Functions

ErrorCode getErrorCode()

Return the current ErrorCode of the IntVector object.

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

Suggest the maximum index to be stored in the IntVector. This is used to allocate the initial array of storage which is used to hold the vector. If an index is accessed greater than this initial estimate, storage space is dynamically expanded to hold the extra integer values. This function clears any previously set values to zero.

See Also inquire()

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

Parameters:length – Estimated maximum index addressed
Returns:Status
Status inquire(int *maxIndex)

Find the current maximum set or appended index of the IntVector. The returned value will be -1 if no values are set.

See Also define()

Parameters:maxIndex[out] Maximum index
Returns:Status
Status setIntegerParameter(IntegerParameter parameter, int value)

Set vector operation parameters. The IntegerParameter parameter is an integer boolean value which toggles the validity of the zero index. The value of index zero is not changed by this operation. By default the zero index is not valid.

Parameters:
  • parameter IntegerParameter of parameter to set
  • value – Specifies the integer value that type will be set to
Returns:

Status

Status count(int *itemCount)

Get the number of nonzero values contained in the vector. If index zero is a valid index then the count will include the value of index zero.

Parameters:itemCount[out] Number of nonzero integer values
Returns:Status
Status set(int index, int item)

Set the value specified by index. All unset values are initially set to zero. The vector automatically expands the required storage to hold the set values.

See Also get()

Errors
  • VALUE is generated if an improper index is specified.
  • MEMORY is generated if storage was unable to be allocated.

Parameters:
  • index – Index of set value
  • item – Integer value
Returns:

Status

Status expand(int index)

Expand the storage of the vector to hold at least the specified index.

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

Parameters:index – Index to expand to
Returns:Status
Status append(int item)

Set the value at the index after the last set or appended value.

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

Parameters:item – Integer value
Returns:Status
Status get(int index, int *item)

Get the value at the specified index.

See Also set()

Parameters:
  • index – Index of value
  • item[out] Integer value
Returns:

Status

Status increment(int index, int item)

Increment the value specified by index by the given value.

Errors
  • VALUE is generated if an improper index is specified.
  • MEMORY is generated if storage was unable to be allocated.

Parameters:
  • index – Index of incremented value
  • item – Increment value
Returns:

Status

Status clear()

Reinitialize the vector of integers. The maximum defined index is reset so that any appended values using append() will be placed at the starting index specified by setIntegerParameter() . The integer values are effectively set to zero.

Returns:Status
Status initializeIterator()

Initiate the iteration for sequential access to each nonzero value in the vector. Each call of nextItem() will return the index of the next value from the vector. After every nonzero value has been visited, nextItem() will return an index of -1 until the iteration is restarted using initializeIterator() .

See Also nextItem()

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

Get the index and value of the next nonzero value in the vector. Returns an index of -1 when all values have been visited.

See Also initializeIterator()

Parameters:
  • index[out] Index of next nonzero value
  • item[out] Integer value
Returns:

Status

Status match(IntVector *intvec, int *flag)

Check for matching IntVector objects. The order and values of the contents must be identical for a match to occur.

Parameters:
  • intvecIntVector object to check against
  • flag[out] Matching Flag
Returns:

Status

Status copy(IntVector *from)

Make a copy of an IntVector object. The private data from the source object is copied to this object. Any previous private data in this object is lost.

Parameters:fromIntVector object to copy from
Returns:Status
Status print()

Print the IntVector object information to standard output.

Returns:Status
Status unique(int item)

Set the value at the index after the last set or appended value only if the value is not already present in the vector.

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

Parameters:item – Integer value
Returns:Status
Status getStartingIndex(int *index)

Get the starting index of the IntVector object.

Parameters:index[out] Starting index
Returns:Status