#include <darray.h>
Public Member Functions | |
| DArray () | |
| The default constructor. | |
| DArray (T *_array, size_t _indices) | |
| Initialize the DArray with an existing array. | |
| DArray (DArray const &_array) | |
| Initialize the DArray with an existing array. | |
| DArray (int _newStepSize) | |
| The secondary constructor. | |
| ~DArray () | |
| The destructor. | |
| void | setSize (size_t _newsize) |
| Sets the size of the array. | |
| void | setStepSize (int _newstepsize) |
| Sets the step size used in Grow(). | |
| void | setStepDouble () |
| Sets the step size to double the array size when a Grow() is necessitated. | |
| T | get (size_t _index) const |
| Gets the data at the given index. | |
| void | remove (size_t _index) |
| Removes the data at the given index. | |
| size_t | find (T const &_data) |
| Finds the data in the array. | |
| size_t | insert (T const &_newdata) |
| Inserts data into the array at the first available index. | |
| void | insert (T const &_newdata, size_t _index) |
| Inserts data into the array at the given index. | |
| size_t | used () const |
| Indicates the number of used nodes. | |
| size_t | size () const |
| Indicates the total size of the array. | |
| bool | valid (size_t _index) const |
| Indicates whether a given index is valid. | |
| void | empty () |
| Empties the array but does NOT free any pointers stored in the array. | |
| int | sort (CrissCross::Data::Sorter< T > *_sortMethod) |
| Sorts the array using the provided method. | |
| int | sort (CrissCross::Data::Sorter< T > &_sortMethod) |
| Sorts the array using the provided method. | |
| T & | operator[] (size_t _index) |
| Gets the data at the given index. | |
| T const & | operator[] (size_t _index) const |
| Gets the data at the given index. | |
| size_t | mem_usage () const |
| Returns the overhead caused by the data structure. | |
| void | flush () |
| Empties the array and deletes the data contained in it with the 'delete' operator. | |
| void | flushArray () |
| Empties the array and deletes the data contained in it with the 'delete []' operator. | |
Protected Member Functions | |
| void | grow () |
| Increases the size of the array. | |
| void | rebuildStack () |
| Rebuilds the empty node stack. | |
| void | recount () |
| Recounts the number of used nodes. | |
| size_t | getNextFree () |
| Gets the next empty node. | |
Protected Attributes | |
| int | m_stepSize |
| The size by which to increase the size of the array when there are no more empty nodes. | |
| size_t | m_arraySize |
| The current size of the array. | |
| size_t | m_numUsed |
| The number of used items in the array. | |
| T * | m_array |
| The actual array which stores our data. | |
| char * | m_shadow |
| An array to indicate which nodes in m_array are in use. | |
Private Attributes | |
| DStack< size_t > * | m_emptyNodes |
| A DStack containing indices of empty nodes in the array. | |
| DArray | ( | int | _newStepSize | ) |
The secondary constructor.
Parameter _newStepSize should be larger than 1. A step size of 1 forces the DArray to resize way too often. A step size of -1 is a magic value which makes the DArray double in size on each grow() call (offers a pretty good speedup).
| _newStepSize | The step size to use in grow(). |
| void empty | ( | ) |
Empties the array but does NOT free any pointers stored in the array.
The array must be iterated through and any pointers must be freed manually before calling this.
| size_t find | ( | T const & | _data | ) |
Finds the data in the array.
A return value of -1 means the data couldn't be found.
| _data | The data to find. |
| T get | ( | size_t | _index | ) | const [inline] |
Gets the data at the given index.
| _index | The index of the node to get data from. |
| size_t getNextFree | ( | ) | [protected] |
Gets the next empty node.
Typically can just pop an item off the empty_nodes stack. If there are no other empty nodes remaining, then it will automatically Grow() the array.
| void insert | ( | T const & | _newdata, | |
| size_t | _index | |||
| ) |
Inserts data into the array at the given index.
| _newdata | The data to put into the array. | |
| _index | The index in the array where the data should be put, regardless of existing contents. |
| size_t insert | ( | T const & | _newdata | ) |
Inserts data into the array at the first available index.
| _newdata | The data to put into the array. |
| size_t mem_usage | ( | ) | const |
Returns the overhead caused by the data structure.
| T const& operator[] | ( | size_t | _index | ) | const [inline] |
Gets the data at the given index.
| _index | The index of the node to get data from. |
| T& operator[] | ( | size_t | _index | ) | [inline] |
Gets the data at the given index.
| _index | The index of the node to get data from. |
| void remove | ( | size_t | _index | ) |
Removes the data at the given index.
| _index | The index of the node to clear. |
| void setSize | ( | size_t | _newsize | ) |
Sets the size of the array.
| _newsize | The new array size. |
| void setStepSize | ( | int | _newstepsize | ) |
Sets the step size used in Grow().
Parameter _newStepSize should be larger than 1. A step size of 1 forces the DArray to resize way too often. A step size of -1 is a magic value which makes the DArray double in size on each grow() call (offers a pretty good speedup).
| _newstepsize | The step size to use in grow(). |
| size_t size | ( | ) | const [inline] |
Indicates the total size of the array.
| int sort | ( | CrissCross::Data::Sorter< T > & | _sortMethod | ) |
Sorts the array using the provided method.
| _sortMethod | The method to sort with. |
| int sort | ( | CrissCross::Data::Sorter< T > * | _sortMethod | ) |
Sorts the array using the provided method.
| _sortMethod | The method to sort with. |
| size_t used | ( | ) | const [inline] |
Indicates the number of used nodes.
| bool valid | ( | size_t | _index | ) | const [inline] |
Indicates whether a given index is valid.
Tests whether the index is within the bounds of the array and is an empty node.
| _index | The index to test. |
size_t m_arraySize [protected] |
The current size of the array.
Referenced by DArray< char * >::size(), and DArray< char * >::valid().
DStack<size_t>* m_emptyNodes [private] |
A DStack containing indices of empty nodes in the array.
Vastly speeds up insertions by keeping track of where empty spaces are.
int m_stepSize [protected] |
The size by which to increase the size of the array when there are no more empty nodes.
If set to -1, it will double the size of the array each time the array grows.
1.5.8