GPL_DynamicArray
GPL_DynamicArray
gpl
1998 12-05
CLASS
GPL_DynamicArray - C++ dynamic array template
SYNOPSIS
GPL_DynamicArray<data_type> darray(block_size);
Class GPL_DynamicArray is an array that expands and contracts to
fit the number of elements in the array. Compression (collapsing the
array to fill empty slots in the middle) is not automatic. However, new
elements will go into empty slots in the middle if there are any. The
array is reduced in size when block_size or more pointers are free
at the end of the array.
GPL_DynamicArray is really an array of pointers to some object
type.
Removal of an element does not destroy the element object itself. Only
the pointer to it in the array is removed. Space for element objects
must be cleaned up by the calling code.
CONSTRUCTOR
GPL_DynamicArray(long block_size)
Construct a dynamic array of pointers to type data_type
with a dynamic sizing grain size of block_size.
MEMBER FUNCTIONS
long GetSize()
Return the current size of the array. The returned size is the size of
the array in terms of valid object space, not allocated space. In other
words, the returned size is the highest valid object index plus one.
There may be invalid indices in the middle of the array, and there may
be invalid indices at the end of the array (beyond the size returned
from GetSize()).
data_type *Swap(long index, data_type *entry)
Replace an object in the array with another object. The argument entry
specifies the new object to put in the array at index.
The old object pointer is returned.
data_type *Set(long index, data_type *entry)
Set an object pointer in the array.
The argument entry specifies the object to add.
The argument index specifies the index to use. The array is enlarged if
necessary to accomadate the request.
The previous entry for location index is return, which is NULL if
there was no previous entry.
data_type *Add(long *index, data_type *entry)
Add an object pointer to the array. The argument entry
specifies the object to add. The index is automatically selected and returned
as the argument index.
On success the pointer to the object is returned, otherwise NULL
is returned.
index Add(data_type *entry)
Add an object pointer to the array. The argument entry
specifies the object to add. The index is automatically selected and
returned. On failure -1 is returned.
data_type *Remove(long index)
Remove the object pointer at index
and return the pointer.
data_type *Get(long index)
Return a pointer to the object at index.
long FirstFreeIndex()
Return the index of the lowest avaiable slot.