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.
- Definition
- Set and query values
append()- Append value at end of vectorclear()- Clear all integers to zerocount()- Get number of nonzero integersmatch()- Check for matching objectsinitializeIterator()- Prepare to successively visit each nonzeronextItem()- Return the index of the next nonzeroset()- Set a integer value at an indexget()- Get a integer value at an indexsetIntegerParameter()- Set integer vector operation parametersexpand()- Expand to a given indexunique()- Append value at end of vector if not already presentgetStartingIndex()- Get the starting index of a IntVector objectincrement()- Increment a integer value at an index
- General functions
getErrorCode()- Return the current error codeprint()- Print object informationcopy()- copy a IntVector
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
Public Functions
-
ErrorCode
getErrorCode() Return the current
ErrorCodeof the IntVector object.Returns: ErrorCode- The current error code, orNONEif 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
-
MEMORYis 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 –
IntegerParameterof parameter to set - value – Specifies the integer value that type will be set to
Returns: - parameter –
-
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
Parameters: - index – Index of set value
- item – Integer value
Returns:
-
Status
expand(int index) Expand the storage of the vector to hold at least the specified index.
- Errors
-
MEMORYis 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
-
MEMORYis 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
increment(int index, int item) Increment the value specified by index by the given value.
- Errors
Parameters: - index – Index of incremented value
- item – Increment value
Returns:
-
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 bysetIntegerParameter(). 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 usinginitializeIterator().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
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: Returns:
-
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: from – IntVector object to copy from Returns: Status
-
ErrorCode