HTM SpatialIndex Class Reference

template class ValVec

Dynamic array of arbitrary values This is a template for a general-purpose dynamic array

Public Fields

size_t increment_
Linear growth increment */
T* vector_
dynamic array of values */

Public Methods

~ValVec ( void )
Destructor
ValVec ( size_t capacity = 0, size_t increment = 0 )
Default constructor
ValVec ( const T &fill, size_t capacity, size_t increment )
Alternate constructor
ValVec ( const ValVec& )
Copy constructor
ValVec& operator = ( const ValVec& )
Assignment/copy operator
const T& operator () ( size_t index ) const
Efficient array operator (const version): no bounds checking
T& operator () ( size_t index )
Efficient array operator (non-const version): no bounds checking
const T& operator [] ( size_t index ) const
Bounds-checking array operator (const version): throws sxBoundsError
T& operator [] ( size_t index )
Bounds-checking array operator (non-const version): throws sxBoundsError
T& at ( size_t index )
Bounds-adjusting array operator
size_t length ( void ) const
Returns current occupied length of array
size_t append ( const T& )
Efficiently insert given element at end of array
size_t insert ( size_t count, size_t offset = 0 )
Insert new array elements
size_t cut ( size_t count, size_t offset = 0 )
Remove array elements
void remove ( size_t offset )
Removes the element specified by offset
size_t keep ( size_t count )
Cut but keep capacity
T& fill ( void )
Return the fill value, defining it if necessary
bool fillExists ( void ) const
Returns true if the fill value is defined
void unsetFill ( void )
Undefine and destroy the current fill value
void clear ( void )
Reset every value to the fill value
void sort ( int (*compar)(const void*, const void*) )
Do a qsort

Documentation

Dynamic array of arbitrary values This is a template for a general-purpose dynamic array. The array grows automatically as needed, but reallocation occurs only when the length exceeds the capacity. The capacity is increased in large blocks, the size of which may be optimized. A fill value may be defined, in which case it is used to initialize new elements of the array, but not new capacity. Which is to say that initialization is deferred until the array grows into its capacity. The public data member, increment_, specifies the amount by which the capacity is increased during reallocation. By default, increment_ is zero, which causes the capacity to double upon each reallocation. A non-zero increment_ is simply added to the capacity upon each reallocation. The capacity is extended by this amount or by whatever greater amount is necessary to accommodate the new length of the array.
~ValVec( void )
Destructor

ValVec( size_t capacity = 0, size_t increment = 0 )
Default constructor. optionally specify initial capacity and reallocation increment.

ValVec( const T &fill, size_t capacity, size_t increment )
Alternate constructor. define a fill value in addition to the parameters of the default constructor. class T must have well-defined copy semantics. The fill value does not exist unless it is defined.

ValVec( const ValVec& )
Copy constructor. The initial capacity is the current capacity of the duplicated array.

ValVec& operator =( const ValVec& )
Assignment/copy operator. does not decrease the capacity.

const T& operator ()( size_t index ) const
Efficient array operator (const version): no bounds checking

T& operator ()( size_t index )
Efficient array operator (non-const version): no bounds checking

const T& operator []( size_t index ) const
Bounds-checking array operator (const version): throws sxBoundsError

T& operator []( size_t index )
Bounds-checking array operator (non-const version): throws sxBoundsError

T& at( size_t index )
Bounds-adjusting array operator. Returns the array element at the specified index, extending the array as necessary to bring it within bounds. The fill value, if defined, is the initializer for any new elements.

size_t length( void ) const
Returns current occupied length of array

size_t append( const T& )
Efficiently insert given element at end of array. Avoids redundant initialization of new array element, except for when a reallocation is required. Returns the new length.

size_t insert( size_t count, size_t offset = 0 )
Insert new array elements. Count specifies the number of new elements, and offset specifies where in the array to insert them. By default the new elements are appended. The fill value, if defined, is the initializer for the new elements. offset refers to the end of the array: the first new element is located at index (length - offset). Returns the new length. Throws sxBoundsError if offset is greater than length.

size_t cut( size_t count, size_t offset = 0 )
Remove array elements. count specifies the number of elements to remove, and offset specifies which elements to remove. By default elements are removed from the end of the array. The unused capacity grows by this amount. offset refers to the end of the array: the first removed element is located at index (length - offset - count). Returns the new length. Throws sxBoundsError if (offset+count) is greater than length.

void remove( size_t offset )
Removes the element specified by offset. This is basically a wrapper for the cut method cut(1, length-offset-1)

size_t keep( size_t count )
Cut but keep capacity. Just like the cut method, it resets the length of the vector by count, but it always starts from the end. The elements, however are not deleted and rebuilt with the default, but rather left as they are for the user to reuse.

T& fill( void )
Return the fill value, defining it if necessary. If the fill value is not defined, a default value is created using the default constructor for class T. The returned object is an lvalue, to which a new fill value may be assigned.

bool fillExists( void ) const
Returns true if the fill value is defined

void unsetFill( void )
Undefine and destroy the current fill value. (if it is defined)

void clear( void )
Reset every value to the fill value. If no fill is defined, nothing is done!

void sort( int (*compar)(const void*, const void*) )
Do a qsort

size_t increment_
Linear growth increment */

T* vector_
dynamic array of values */


This class has no child classes.

alphabetic index hierarchy of classes


© Copyright The Johns Hopkins University 1999, All Rights Reserved.
Peter Z. Kunszt,

generated by doc++