![]() |
TrinityCore
|
Dynamic 1D array tuned for performance. More...
#include <Array.h>
Classes | |
| class | DefaultComparator |
Public Types | |
| typedef T * | Iterator |
| typedef const T * | ConstIterator |
| typedef Iterator | iterator |
| typedef ConstIterator | const_iterator |
| typedef T | value_type |
| typedef int | size_type |
| typedef int | difference_type |
Public Member Functions | |
| Array & | operator= (const Array &other) |
| Array & | operator= (const std::vector< T > &other) |
| Iterator | begin () |
| ConstIterator | begin () const |
| ConstIterator | end () const |
| Iterator | end () |
| T * | getCArray () |
| const T * | getCArray () const |
| Array () | |
| Array (const T &v0) | |
| Array (const T &v0, const T &v1) | |
| Array (const T &v0, const T &v1, const T &v2) | |
| Array (const T &v0, const T &v1, const T &v2, const T &v3) | |
| Array (const T &v0, const T &v1, const T &v2, const T &v3, const T &v4) | |
| Array (const Array &other) | |
| Array (const std::vector< T > &other) | |
| void | copyFrom (const Array< T > &other) |
| void | copyPOD (const Array< T > &other) |
| void | appendPOD (const Array< T > &other) |
| ~Array () | |
| void | clear (bool shrink=true) |
| void | clearAndSetMemoryManager (const MemoryManager::Ref &m) |
| void | fastClear () |
| MemoryManager::Ref | memoryManager () const |
| int | size () const |
| int | length () const |
| void | fastRemove (int index, bool shrinkIfNecessary=false) |
| void | insert (int n, const T &value) |
| void | setAll (const T &value) |
| void | trimToSize () |
| void | resize (size_t n, bool shrinkIfNecessary=true) |
| void | append (const T &value) |
| void | append (const T &v1, const T &v2) |
| void | append (const T &v1, const T &v2, const T &v3) |
| void | append (const T &v1, const T &v2, const T &v3, const T &v4) |
| void | append (const T &v1, const T &v2, const T &v3, const T &v4, const T &v5) |
| void | append (const T &v1, const T &v2, const T &v3, const T &v4, const T &v5, const T &v6) |
| bool | contains (const T &e) const |
| void | append (const Array< T > &array) |
| T & | next () |
| void | push (const T &value) |
| void | push (const Array< T > &array) |
| void | push_back (const T &v) |
| void | pop_back () |
| int | capacity () const |
| T & | front () |
| const T & | front () const |
| T & | back () |
| const T & | back () const |
| T | pop (bool shrinkUnderlyingArrayIfNecessary=true) |
| void | popDiscard (bool shrinkUnderlyingArrayIfNecessary=false) |
| void | swap (Array< T > &str) |
| T & | operator[] (int n) |
| T & | operator[] (uint32 n) |
| T & | operator[] (uint64 n) |
| const T & | operator[] (int n) const |
| const T & | operator[] (uint32 n) const |
| const T & | operator[] (uint64 n) const |
| T & | randomElement () |
| const T & | randomElement () const |
| const T & | last () const |
| T & | last () |
| int | lastIndex () const |
| int | firstIndex () const |
| T & | first () |
| const T & | first () const |
| int | middleIndex () const |
| const T & | middle () const |
| T & | middle () |
| void | invokeDeleteOnAllElements () |
| void G3D_DEPRECATED | deleteAll () |
| int | rfindIndex (const T &value) const |
| int | findIndex (const T &value) const |
| Iterator | find (const T &value) |
| ConstIterator | find (const T &value) const |
| void | remove (Iterator element, int count=1) |
| void | remove (int index, int count=1) |
| void | reverse () |
| template<class LessThan > | |
| void | sort (const LessThan &lessThan) |
| void | sort (int direction=SORT_INCREASING) |
| void | sortSubArray (int beginIndex, int endIndex, int direction=SORT_INCREASING) |
| void | sortSubArray (int beginIndex, int endIndex, bool(__cdecl *lessThan)(const T &elem1, const T &elem2)) |
| template<typename StrictWeakOrdering > | |
| void | sortSubArray (int beginIndex, int endIndex, StrictWeakOrdering &lessThan) |
| template<typename Comparator > | |
| void | partition (const T &partitionElement, Array< T > <Array, Array< T > &eqArray, Array< T > >Array, const Comparator &comparator) const |
| void | partition (const T &partitionElement, Array< T > <Array, Array< T > &eqArray, Array< T > >Array) const |
| template<typename Comparator > | |
| void | medianPartition (Array< T > <Median, Array< T > &eqMedian, Array< T > >Median, Array< T > &tempArray, const Comparator &comparator) const |
| void | medianPartition (Array< T > <Median, Array< T > &eqMedian, Array< T > >Median) const |
| void | randomize () |
| void | reserve (int n) |
| size_t | sizeInMemory () const |
| void | removeNulls () |
Static Public Member Functions | |
| static void | swap (Array< T, MIN_ELEMENTS > &a, Array< T, MIN_ELEMENTS > &b) |
Private Member Functions | |
| void | init (size_t n, const MemoryManager::Ref &m) |
| void | _copy (const Array &other) |
| bool | inArray (const T *address) |
| void | realloc (size_t oldNum) |
Static Private Member Functions | |
| static bool __cdecl | compareGT (const T &a, const T &b) |
Private Attributes | |
| T * | data |
| size_t | num |
| size_t | numAllocated |
| MemoryManager::Ref | m_memoryManager |
Static Private Attributes | |
| static const size_t | MIN_BYTES = 32 |
Dynamic 1D array tuned for performance.
Objects must have a default constructor (constructor that takes no arguments) in order to be used with this template. You will get the error "no appropriate default constructor found" if they do not.
Do not use with objects that overload placement operator new, since the speed of Array is partly due to pooled allocation.
Array is highly optimized compared to std::vector. Array operations are less expensive than on std::vector and for large amounts of data, Array consumes only 1.5x the total size of the data, while std::vector consumes 2.0x. The default array takes up zero heap space. The first resize (or append) operation grows it to a reasonable internal size so it is efficient to append to small arrays.
Then Array needs to copy data internally on a resize operation it correctly invokes copy constructors of the elements (the MSVC6 implementation of std::vector uses realloc, which can create memory leaks for classes containing references and pointers). Array provides a guaranteed safe way to access the underlying data as a flat C array – Array::getCArray. Although (T*)std::vector::begin() can be used for this purpose, it is not guaranteed to succeed on all platforms.
To serialize an array, see G3D::serialize.
The template parameter MIN_ELEMENTS indicates the smallest number of elements that will be allocated. The default of 10 is designed to avoid the overhead of repeatedly allocating the array as it grows from 1, to 2, and so on. If you are creating a lot of small Arrays, however, you may want to set this smaller to reduce the memory cost. Once the array has been allocated, it will never deallocate the underlying array unless MIN_ELEMENTS is set to 0, MIN_BYTES is 0, and the array is empty.
Do not subclass an Array.
| typedef ConstIterator G3D::Array< T, MIN_ELEMENTS >::const_iterator |
stl porting compatibility helper
| typedef const T* G3D::Array< T, MIN_ELEMENTS >::ConstIterator |
G3D C++ STL style const iterator in same style as Iterator.
| typedef int G3D::Array< T, MIN_ELEMENTS >::difference_type |
stl porting compatibility helper
| typedef T* G3D::Array< T, MIN_ELEMENTS >::Iterator |
| typedef Iterator G3D::Array< T, MIN_ELEMENTS >::iterator |
stl porting compatibility helper
| typedef int G3D::Array< T, MIN_ELEMENTS >::size_type |
stl porting compatibility helper
| typedef T G3D::Array< T, MIN_ELEMENTS >::value_type |
stl porting compatibility helper
|
inline |
Creates a zero length array (no heap allocation occurs until resize).
|
inlineexplicit |
Creates an array containing v0.
|
inline |
Creates an array containing v0 and v1.
|
inline |
Creates an array containing v0...v2.
|
inline |
Creates an array containing v0...v3.
|
inline |
Creates an array containing v0...v4.
|
inline |
Copy constructor. Copying arrays is slow...perhaps you want to pass a reference or a pointer instead?
|
inlineexplicit |
|
inline |
Destructor does not delete() the objects if T is a pointer type (e.g. T = int*) instead, it deletes the pointers themselves and leaves the objects. Call deleteAll if you want to dealocate the objects referenced. Do not call deleteAll if T is not a pointer type (e.g. do call Array<Foo*>::deleteAll, do not call Array<Foo>::deleteAll).
|
inlineprivate |
Here is the caller graph for this function:
|
inline |
Add an element to the end of the array. Will not shrink the underlying array under any circumstances. It is safe to append an element that is already in the array.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Append the elements of array. Cannot be called with this array as an argument.
|
inline |
Resizes this to just barely match the size of other + itself and then copies the data to the end of the array from other using memcpy. This is only safe for POD types
|
inline |
"The member function returns a reference to the last element of the controlled sequence, which must be non-empty." For compatibility with std::vector.
|
inline |
"The member function returns a reference to the last element of the controlled sequence, which must be non-empty." For compatibility with std::vector.
|
inline |
C++ STL style iterator method. Returns the first iterator element. Do not change the size of the array while iterating.
Here is the caller graph for this function:
|
inline |
|
inline |
"The member function returns the storage currently allocated to hold the controlled sequence, a value at least as large as size()" For compatibility with std::vector.
Here is the caller graph for this function:
|
inline |
Removes all elements. Use resize(0, false) or fastClear if you want to remove all elements without deallocating the underlying array so that future append() calls will be faster.
Here is the caller graph for this function:
|
inline |
Here is the caller graph for this function:
|
inlinestaticprivate |
|
inline |
Returns true if the given element is in the array.
Here is the caller graph for this function:
|
inline |
|
inline |
Resizes this to match the size of other and then copies the data from other using memcpy. This is only safe for POD types
|
inline |
Here is the caller graph for this function:
|
inline |
C++ STL style iterator method. Returns one after the last valid iterator element.
Here is the caller graph for this function:
|
inline |
|
inline |
resize(0, false)
Here is the caller graph for this function:
|
inline |
Swaps element index with the last element in the array then shrinks the array by one.
Here is the caller graph for this function:
|
inline |
Finds an element and returns the iterator to it. If the element isn't found then returns end().
|
inline |
|
inline |
Returns the index of (the first occurance of) an index or -1 if not found.
Here is the caller graph for this function:
|
inline |
Returns element firstIndex(), performing a check in debug mode to ensure that there is at least one
Here is the caller graph for this function:
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprivate |
Returns true iff address points to an element of this array. Used by append.
Here is the caller graph for this function:
|
inlineprivate |
| n | Number of elements |
Here is the caller graph for this function:
|
inline |
Inserts at the specified index and shifts all other elements up by one.
|
inline |
Calls delete on all objects[0...size-1] and sets the size to zero.
Here is the caller graph for this function:
|
inline |
Returns the last element, performing a check in debug mode that there is at least one element.
Here is the caller graph for this function:
|
inline |
Returns element lastIndex()
|
inline |
Returns size() - 1
|
inline |
Number of elements in the array. (Same as size; this is just here for convenience).
Here is the caller graph for this function:
|
inline |
Paritions the array into those below the median, those above the median, and those elements equal to the median in expected O(n) time using quickselect. If the array has an even number of different elements, the median for partition purposes is the largest value less than the median.
| tempArray | used for working scratch space |
| comparator | see parition() for a discussion. |
Here is the caller graph for this function:
|
inline |
Computes a median partition using the default comparator and a dynamically allocated temporary working array. If the median is not in the array, it is chosen to be the largest value smaller than the true median.
|
inline |
Here is the caller graph for this function:
|
inline |
|
inline |
Returns element middleIndex()
|
inline |
Returns iFloor(size() / 2), throws an assertion in debug mode if the array is empty
|
inline |
Pushes a new element onto the end and returns its address. This is the same as A.resize(A.size() + 1, false); A.last()
Here is the caller graph for this function:
|
inline |
Assignment operator. Will be private in a future release because this is slow and can be invoked by accident by novice C++ programmers. If you really want to copy an Array, use the explicit copy constructor.
|
inline |
|
inline |
Performs bounds checks in debug mode
|
inline |
|
inline |
|
inline |
Performs bounds checks in debug mode
|
inline |
|
inline |
|
inline |
The output arrays are resized with fastClear() so that if they are already of the same size as this array no memory is allocated during partitioning.
| comparator | A function, or class instance with an overloaded operator() that compares two elements of type T and returns 0 if they are equal, -1 if the second is smaller, and 1 if the first is smaller (i.e., following the conventions of std::string::compare). For example: |
int compare(int A, int B) {
if (A < B) {
return 1;
} else if (A == B) {
return 0;
} else {
return -1;
}
}
Here is the caller graph for this function:
|
inline |
Uses < and == on elements to perform a partition. See partition().
|
inline |
Removes the last element and returns it. By default, shrinks the underlying array.
Here is the caller graph for this function:
|
inline |
"The member function removes the last element of the controlled sequence, which must be non-empty." For compatibility with std::vector.
|
inline |
Pops the last element and discards it without returning anything. Faster than pop. By default, does not shrink the underlying array.
Here is the caller graph for this function:
|
inline |
Pushes an element onto the end (appends)
Here is the caller graph for this function:
|
inline |
|
inline |
Alias to provide std::vector compatibility
Here is the caller graph for this function:
|
inline |
|
inline |
|
inline |
Redistributes the elements so that the new order is statistically independent of the original order. O(n) time.
|
inlineprivate |
Allocates a new array of size numAllocated (not a parameter to the method) and then copies at most oldNum elements from the old array to it. Destructors are called for oldNum elements of the old array.
Here is the caller graph for this function:
|
inline |
Removes count elements from the array referenced either by index or Iterator.
Here is the caller graph for this function:
|
inline |
|
inline |
Remove all NULL elements in linear time without affecting order of the other elements.
|
inline |
Ensures that future append() calls can grow up to size n without allocating memory.
Here is the caller graph for this function:
|
inline |
| shrinkIfNecessary | if false, memory will never be reallocated when the array shrinks. This makes resizing much faster but can waste memory. Default = true. |
|
inline |
Reverse the elements of the array in place.
Here is the caller graph for this function:
|
inline |
Returns the index of (the first occurance of) an index or -1 if not found. Searches from the right.
|
inline |
Sets all elements currently in the array to
| value |
|
inline |
Number of elements in the array.
|
inline |
Number of bytes used by the array object and the memory allocated for it's data pointer. Does not include the memory of objects pointed to by objects in the data array
|
inline |
Sort using a specific less-than function, e.g.:
Note that for pointer arrays, the const must come after the class name, e.g., Array<MyClass*> uses:
or a functor, e.g.,
Here is the caller graph for this function:
|
inline |
Sorts the array in increasing order using the > or < operator. To invoke this method on Array<T>, T must override those operator. You can overide these operators as follows:
|
inline |
Sorts elements beginIndex through and including endIndex.
|
inline |
|
inline |
The StrictWeakOrdering can be either a class that overloads the function call operator() or a function pointer of the form bool (__cdecl *lessThan)(const T& elem1, const T& elem2)
|
inlinestatic |
Exchanges all data between the two arrays, which are required to have a common MemoryManager. This is a convenient way to avoid large array copies when handing off data without involving reference counting or manual memory management. Beware that pointers or references into the arrays will access memory in the other array after the swap.
|
inline |
|
inline |
Resize this array to consume exactly the capacity required by its size.
|
private |
0...num-1 are initialized elements, num...numAllocated-1 are not
|
private |
|
staticprivate |
Once the array has been allocated, it will never deallocate the underlying array unless MIN_ELEMENTS is set to 0, MIN_BYTES is 0, and the array is empty.
|
private |
|
private |
1.8.8