TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Array< T, MIN_ELEMENTS > Class Template Reference

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

Arrayoperator= (const Array &other)
 
Arrayoperator= (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
 
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 > &ltArray, Array< T > &eqArray, Array< T > &gtArray, const Comparator &comparator) const
 
void partition (const T &partitionElement, Array< T > &ltArray, Array< T > &eqArray, Array< T > &gtArray) const
 
template<typename Comparator >
void medianPartition (Array< T > &ltMedian, Array< T > &eqMedian, Array< T > &gtMedian, Array< T > &tempArray, const Comparator &comparator) const
 
void medianPartition (Array< T > &ltMedian, Array< T > &eqMedian, Array< T > &gtMedian) 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
 

Detailed Description

template<class T, size_t MIN_ELEMENTS = 10>
class G3D::Array< T, MIN_ELEMENTS >

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.

See also
G3D::SmallArray

Member Typedef Documentation

template<class T, size_t MIN_ELEMENTS = 10>
typedef ConstIterator G3D::Array< T, MIN_ELEMENTS >::const_iterator

stl porting compatibility helper

template<class T, size_t MIN_ELEMENTS = 10>
typedef const T* G3D::Array< T, MIN_ELEMENTS >::ConstIterator

G3D C++ STL style const iterator in same style as Iterator.

template<class T, size_t MIN_ELEMENTS = 10>
typedef int G3D::Array< T, MIN_ELEMENTS >::difference_type

stl porting compatibility helper

template<class T, size_t MIN_ELEMENTS = 10>
typedef T* G3D::Array< T, MIN_ELEMENTS >::Iterator

G3D C++ STL style iterator variable. Call begin() to get the first iterator, pre-increment (++i) the iterator to get to the next value. Use dereference (*i) to access the element.

template<class T, size_t MIN_ELEMENTS = 10>
typedef Iterator G3D::Array< T, MIN_ELEMENTS >::iterator

stl porting compatibility helper

template<class T, size_t MIN_ELEMENTS = 10>
typedef int G3D::Array< T, MIN_ELEMENTS >::size_type

stl porting compatibility helper

template<class T, size_t MIN_ELEMENTS = 10>
typedef T G3D::Array< T, MIN_ELEMENTS >::value_type

stl porting compatibility helper

Constructor & Destructor Documentation

template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::Array ( )
inline

Creates a zero length array (no heap allocation occurs until resize).

281  : num(0) {
283  }
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
void init(size_t n, const MemoryManager::Ref &m)
Definition: Array.h:112
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::Array ( const T &  v0)
inlineexplicit

Creates an array containing v0.

287  {
289  (*this)[0] = v0;
290  }
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
void init(size_t n, const MemoryManager::Ref &m)
Definition: Array.h:112
template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::Array ( const T &  v0,
const T &  v1 
)
inline

Creates an array containing v0 and v1.

293  {
295  (*this)[0] = v0;
296  (*this)[1] = v1;
297  }
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
void init(size_t n, const MemoryManager::Ref &m)
Definition: Array.h:112
template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::Array ( const T &  v0,
const T &  v1,
const T &  v2 
)
inline

Creates an array containing v0...v2.

300  {
302  (*this)[0] = v0;
303  (*this)[1] = v1;
304  (*this)[2] = v2;
305  }
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
void init(size_t n, const MemoryManager::Ref &m)
Definition: Array.h:112
template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::Array ( const T &  v0,
const T &  v1,
const T &  v2,
const T &  v3 
)
inline

Creates an array containing v0...v3.

308  {
310  (*this)[0] = v0;
311  (*this)[1] = v1;
312  (*this)[2] = v2;
313  (*this)[3] = v3;
314  }
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
void init(size_t n, const MemoryManager::Ref &m)
Definition: Array.h:112
template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::Array ( const T &  v0,
const T &  v1,
const T &  v2,
const T &  v3,
const T &  v4 
)
inline

Creates an array containing v0...v4.

317  {
319  (*this)[0] = v0;
320  (*this)[1] = v1;
321  (*this)[2] = v2;
322  (*this)[3] = v3;
323  (*this)[4] = v4;
324  }
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
void init(size_t n, const MemoryManager::Ref &m)
Definition: Array.h:112
template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::Array ( const Array< T, MIN_ELEMENTS > &  other)
inline

Copy constructor. Copying arrays is slow...perhaps you want to pass a reference or a pointer instead?

331  : num(0) {
332  _copy(other);
333  }
size_t num
Definition: Array.h:105
void _copy(const Array &other)
Definition: Array.h:124
template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::Array ( const std::vector< T > &  other)
inlineexplicit
335  : num(0), data(NULL) {
336  *this = other;
337  }
arena_t NULL
Definition: jemalloc_internal.h:624
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::~Array ( )
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).

389  {
390  // Invoke the destructors on the elements
391  for (size_t i = 0; i < num; ++i) {
392  (data + i)->~T();
393  }
394 
395  m_memoryManager->free(data);
396  // Set to 0 in case this Array is global and gets referenced during app exit
397  data = NULL;
398  num = 0;
399  numAllocated = 0;
400  }
arena_t NULL
Definition: jemalloc_internal.h:624
MemoryManager::Ref m_memoryManager
Definition: Array.h:108
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

Member Function Documentation

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::_copy ( const Array< T, MIN_ELEMENTS > &  other)
inlineprivate
124  {
125  init(other.num, MemoryManager::create());
126  for (size_t i = 0; i < num; ++i) {
127  data[i] = other.data[i];
128  }
129  }
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
void init(size_t n, const MemoryManager::Ref &m)
Definition: Array.h:112
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::append ( const T &  value)
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.

583  {
584 
585  if (num < numAllocated) {
586  // This is a simple situation; just stick it in the next free slot using
587  // the copy constructor.
588  new (data + num) T(value);
589  ++num;
590  } else if (inArray(&value)) {
591  // The value was in the original array; resizing
592  // is dangerous because it may move the value
593  // we have a reference to.
594  T tmp = value;
595  append(tmp);
596  } else {
597  // Here we run the empty initializer where we don't have to, but
598  // this simplifies the computation.
600  data[num - 1] = value;
601  }
602  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
bool inArray(const T *address)
Definition: Array.h:135
const bool DONT_SHRINK_UNDERLYING_ARRAY
Definition: Array.h:43
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
const FieldDescriptor value
Definition: descriptor.h:1522
void append(const T &value)
Definition: Array.h:583
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::append ( const T &  v1,
const T &  v2 
)
inline
605  {
606  if (inArray(&v1) || inArray(&v2)) {
607  // Copy into temporaries so that the references won't break when
608  // the array resizes.
609  T t1 = v1;
610  T t2 = v2;
611  append(t1, t2);
612  } else if (num + 1 < numAllocated) {
613  // This is a simple situation; just stick it in the next free slot using
614  // the copy constructor.
615  new (data + num) T(v1);
616  new (data + num + 1) T(v2);
617  num += 2;
618  } else {
619  // Resize the array. Note that neither value is already in the array.
621  data[num - 2] = v1;
622  data[num - 1] = v2;
623  }
624  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
bool inArray(const T *address)
Definition: Array.h:135
const bool DONT_SHRINK_UNDERLYING_ARRAY
Definition: Array.h:43
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
void append(const T &value)
Definition: Array.h:583
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::append ( const T &  v1,
const T &  v2,
const T &  v3 
)
inline
627  {
628  if (inArray(&v1) || inArray(&v2) || inArray(&v3)) {
629  T t1 = v1;
630  T t2 = v2;
631  T t3 = v3;
632  append(t1, t2, t3);
633  } else if (num + 2 < numAllocated) {
634  // This is a simple situation; just stick it in the next free slot using
635  // the copy constructor.
636  new (data + num) T(v1);
637  new (data + num + 1) T(v2);
638  new (data + num + 2) T(v3);
639  num += 3;
640  } else {
642  data[num - 3] = v1;
643  data[num - 2] = v2;
644  data[num - 1] = v3;
645  }
646  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
bool inArray(const T *address)
Definition: Array.h:135
const bool DONT_SHRINK_UNDERLYING_ARRAY
Definition: Array.h:43
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
void append(const T &value)
Definition: Array.h:583
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::append ( const T &  v1,
const T &  v2,
const T &  v3,
const T &  v4 
)
inline
649  {
650  if (inArray(&v1) || inArray(&v2) || inArray(&v3) || inArray(&v4)) {
651  T t1 = v1;
652  T t2 = v2;
653  T t3 = v3;
654  T t4 = v4;
655  append(t1, t2, t3, t4);
656  } else if (num + 3 < numAllocated) {
657  // This is a simple situation; just stick it in the next free slot using
658  // the copy constructor.
659  new (data + num) T(v1);
660  new (data + num + 1) T(v2);
661  new (data + num + 2) T(v3);
662  new (data + num + 3) T(v4);
663  num += 4;
664  } else {
666  data[num - 4] = v1;
667  data[num - 3] = v2;
668  data[num - 2] = v3;
669  data[num - 1] = v4;
670  }
671  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
bool inArray(const T *address)
Definition: Array.h:135
const bool DONT_SHRINK_UNDERLYING_ARRAY
Definition: Array.h:43
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
void append(const T &value)
Definition: Array.h:583
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::append ( const T &  v1,
const T &  v2,
const T &  v3,
const T &  v4,
const T &  v5 
)
inline
673  {
674  if (inArray(&v1) || inArray(&v2) || inArray(&v3) || inArray(&v4) || inArray(&v5)) {
675  T t1 = v1;
676  T t2 = v2;
677  T t3 = v3;
678  T t4 = v4;
679  T t5 = v5;
680  append(t1, t2, t3, t4, t5);
681  } else if (num + 4 < numAllocated) {
682  // This is a simple situation; just stick it in the next free slot using
683  // the copy constructor.
684  new (data + num) T(v1);
685  new (data + num + 1) T(v2);
686  new (data + num + 2) T(v3);
687  new (data + num + 3) T(v4);
688  new (data + num + 4) T(v5);
689  num += 5;
690  } else {
692  data[num - 5] = v1;
693  data[num - 4] = v2;
694  data[num - 3] = v3;
695  data[num - 2] = v4;
696  data[num - 1] = v5;
697  }
698  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
bool inArray(const T *address)
Definition: Array.h:135
const bool DONT_SHRINK_UNDERLYING_ARRAY
Definition: Array.h:43
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
void append(const T &value)
Definition: Array.h:583
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::append ( const T &  v1,
const T &  v2,
const T &  v3,
const T &  v4,
const T &  v5,
const T &  v6 
)
inline
700  {
701  if (inArray(&v1) || inArray(&v2) || inArray(&v3) || inArray(&v4) || inArray(&v5) || inArray(&v6)) {
702  T t1 = v1;
703  T t2 = v2;
704  T t3 = v3;
705  T t4 = v4;
706  T t5 = v5;
707  T t6 = v6;
708  append(t1, t2, t3, t4, t5, t6);
709  } else if (num + 5 < numAllocated) {
710  // This is a simple situation; just stick it in the next free slot using
711  // the copy constructor.
712  new (data + num) T(v1);
713  new (data + num + 1) T(v2);
714  new (data + num + 2) T(v3);
715  new (data + num + 3) T(v4);
716  new (data + num + 4) T(v5);
717  new (data + num + 5) T(v6);
718  num += 6;
719  } else {
721  data[num - 6] = v1;
722  data[num - 5] = v2;
723  data[num - 4] = v3;
724  data[num - 3] = v4;
725  data[num - 2] = v5;
726  data[num - 1] = v6;
727  }
728  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
bool inArray(const T *address)
Definition: Array.h:135
const bool DONT_SHRINK_UNDERLYING_ARRAY
Definition: Array.h:43
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
void append(const T &value)
Definition: Array.h:583
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::append ( const Array< T > &  array)
inline

Append the elements of array. Cannot be called with this array as an argument.

746  {
747  debugAssert(this != &array);
748  size_t oldNum = num;
749  size_t arrayLength = array.length();
750 
751  resize(num + arrayLength, false);
752 
753  for (size_t i = 0; i < arrayLength; ++i) {
754  data[oldNum + i] = array.data[i];
755  }
756  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
int length() const
Definition: Array.h:438
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::appendPOD ( const Array< T > &  other)
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

366  {
367  const size_t oldSize = num;
368  num += other.num;
369  if (numAllocated < num) {
370  alwaysAssertM(other.data, "non-zero array with no allocated space");
371  T* old = data;
372  data = (T*)m_memoryManager->alloc(sizeof(T) * num);
373  System::memcpy(data, old, sizeof(T) * oldSize);
374  m_memoryManager->free(old);
375  numAllocated = num;
376  }
377  if (other.data) {
378  System::memcpy((data + oldSize), other.data, sizeof(T) * other.num);
379  }
380  }
static void memcpy(void *dst, const void *src, size_t numBytes)
Definition: System.cpp:643
MemoryManager::Ref m_memoryManager
Definition: Array.h:108
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165
template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::back ( )
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.

821  {
822  return (*this)[size()-1];
823  }
int size() const
Definition: Array.h:430
template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::back ( ) const
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.

830  {
831  return (*this)[size()-1];
832  }
int size() const
Definition: Array.h:430
template<class T, size_t MIN_ELEMENTS = 10>
Iterator G3D::Array< T, MIN_ELEMENTS >::begin ( )
inline

C++ STL style iterator method. Returns the first iterator element. Do not change the size of the array while iterating.

233  {
234  return data;
235  }
T * data
Definition: Array.h:103

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
ConstIterator G3D::Array< T, MIN_ELEMENTS >::begin ( ) const
inline
237  {
238  return data;
239  }
T * data
Definition: Array.h:103
template<class T, size_t MIN_ELEMENTS = 10>
int G3D::Array< T, MIN_ELEMENTS >::capacity ( ) const
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.

794  {
795  return (int)numAllocated;
796  }
size_t numAllocated
Definition: Array.h:106

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::clear ( bool  shrink = true)
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.

407  {
408  resize(0, shrink);
409  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::clearAndSetMemoryManager ( const MemoryManager::Ref m)
inline
411  {
412  clear();
413  debugAssert(data == NULL);
414  m_memoryManager = m;
415  }
arena_t NULL
Definition: jemalloc_internal.h:624
MemoryManager::Ref m_memoryManager
Definition: Array.h:108
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
void clear(bool shrink=true)
Definition: Array.h:407

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
static bool __cdecl G3D::Array< T, MIN_ELEMENTS >::compareGT ( const T &  a,
const T &  b 
)
inlinestaticprivate

Only compiled if you use the sort procedure.

141  {
142  return a > b;
143  }

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
bool G3D::Array< T, MIN_ELEMENTS >::contains ( const T &  e) const
inline

Returns true if the given element is in the array.

732  {
733  for (int i = 0; i < size(); ++i) {
734  if ((*this)[i] == e) {
735  return true;
736  }
737  }
738 
739  return false;
740  }
int size() const
Definition: Array.h:430

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::copyFrom ( const Array< T > &  other)
inline
341  {
342  resize(0);
343  append(other);
344  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
void append(const T &value)
Definition: Array.h:583
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::copyPOD ( const Array< T > &  other)
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

348  {
349  if (numAllocated < other.num) {
350  m_memoryManager->free(data);
351  data = NULL;
352  if (other.data) {
353  data = (T*)m_memoryManager->alloc(sizeof(T) * other.num);
354  }
355  numAllocated = other.num;
356  }
357 
358  num = other.num;
359  if (other.data && (num > 0)) {
360  System::memcpy(data, other.data, sizeof(T) * num);
361  }
362  }
static void memcpy(void *dst, const void *src, size_t numBytes)
Definition: System.cpp:643
arena_t NULL
Definition: jemalloc_internal.h:624
MemoryManager::Ref m_memoryManager
Definition: Array.h:108
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
void G3D_DEPRECATED G3D::Array< T, MIN_ELEMENTS >::deleteAll ( )
inline
Deprecated:
988  {
990  }
void invokeDeleteOnAllElements()
Definition: Array.h:980

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
ConstIterator G3D::Array< T, MIN_ELEMENTS >::end ( ) const
inline

C++ STL style iterator method. Returns one after the last valid iterator element.

244  {
245  return data + num;
246  }
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
Iterator G3D::Array< T, MIN_ELEMENTS >::end ( )
inline
248  {
249  return data + num;
250  }
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::fastClear ( )
inline

resize(0, false)

Deprecated:
419  {
420  clear(false);
421  }
void clear(bool shrink=true)
Definition: Array.h:407

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::fastRemove ( int  index,
bool  shrinkIfNecessary = false 
)
inline

Swaps element index with the last element in the array then shrinks the array by one.

446  {
447  debugAssert(index < (int)num);
448  data[index] = data[num - 1];
449  resize(size() - 1, shrinkIfNecessary);
450  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
int size() const
Definition: Array.h:430
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
Iterator G3D::Array< T, MIN_ELEMENTS >::find ( const T &  value)
inline

Finds an element and returns the iterator to it. If the element isn't found then returns end().

1022  {
1023  for (int i = 0; i < num; ++i) {
1024  if (data[i] == value) {
1025  return data + i;
1026  }
1027  }
1028  return end();
1029  }
ConstIterator end() const
Definition: Array.h:244
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
const FieldDescriptor value
Definition: descriptor.h:1522
template<class T, size_t MIN_ELEMENTS = 10>
ConstIterator G3D::Array< T, MIN_ELEMENTS >::find ( const T &  value) const
inline
1031  {
1032  for (int i = 0; i < num; ++i) {
1033  if (data[i] == value) {
1034  return data + i;
1035  }
1036  }
1037  return end();
1038  }
ConstIterator end() const
Definition: Array.h:244
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
const FieldDescriptor value
Definition: descriptor.h:1522
template<class T, size_t MIN_ELEMENTS = 10>
int G3D::Array< T, MIN_ELEMENTS >::findIndex ( const T &  value) const
inline

Returns the index of (the first occurance of) an index or -1 if not found.

1009  {
1010  for (size_t i = 0; i < num; ++i) {
1011  if (data[i] == value) {
1012  return (int)i;
1013  }
1014  }
1015  return -1;
1016  }
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::first ( )
inline

Returns element firstIndex(), performing a check in debug mode to ensure that there is at least one

948  {
949  debugAssertM(num > 0, "Array is empty");
950  return data[0];
951  }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::first ( ) const
inline
953  {
954  debugAssertM(num > 0, "Array is empty");
955  return data[0];
956  }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
int G3D::Array< T, MIN_ELEMENTS >::firstIndex ( ) const
inline
942  {
943  debugAssertM(num > 0, "Array is empty");
944  return 0;
945  }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::front ( )
inline

"The member function returns a reference to the first element of the controlled sequence, which must be non-empty." For compatibility with std::vector.

803  {
804  return (*this)[0];
805  }
template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::front ( ) const
inline

"The member function returns a reference to the first element of the controlled sequence, which must be non-empty." For compatibility with std::vector.

812  {
813  return (*this)[0];
814  }
template<class T, size_t MIN_ELEMENTS = 10>
T* G3D::Array< T, MIN_ELEMENTS >::getCArray ( )
inline

The array returned is only valid until the next append() or resize call, or the Array is deallocated.

256  {
257  return data;
258  }
T * data
Definition: Array.h:103

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
const T* G3D::Array< T, MIN_ELEMENTS >::getCArray ( ) const
inline

The array returned is only valid until the next append() or resize call, or the Array is deallocated.

276  {
277  return data;
278  }
T * data
Definition: Array.h:103
template<class T, size_t MIN_ELEMENTS = 10>
bool G3D::Array< T, MIN_ELEMENTS >::inArray ( const T *  address)
inlineprivate

Returns true iff address points to an element of this array. Used by append.

135  {
136  return (address >= data) && (address < data + num);
137  }
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::init ( size_t  n,
const MemoryManager::Ref m 
)
inlineprivate
Parameters
nNumber of elements
112  {
113  m_memoryManager = m;
114  this->num = 0;
115  this->numAllocated = 0;
116  data = NULL;
117  if (n > 0) {
118  resize(n);
119  } else {
120  data = NULL;
121  }
122  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
arena_t NULL
Definition: jemalloc_internal.h:624
MemoryManager::Ref m_memoryManager
Definition: Array.h:108
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::insert ( int  n,
const T &  value 
)
inline

Inserts at the specified index and shifts all other elements up by one.

456  {
457  // Add space for the extra element
458  resize(num + 1, false);
459 
460  for (size_t i = (size_t)(num - 1); i > (size_t)n; --i) {
461  data[i] = data[i - 1];
462  }
463  data[n] = value;
464  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
const FieldDescriptor value
Definition: descriptor.h:1522
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::invokeDeleteOnAllElements ( )
inline

Calls delete on all objects[0...size-1] and sets the size to zero.

980  {
981  for (size_t i = 0; i < num; ++i) {
982  delete data[i];
983  }
984  resize(0);
985  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::last ( ) const
inline

Returns the last element, performing a check in debug mode that there is at least one element.

923  {
924  debugAssert(num > 0);
926  return data[num - 1];
927  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::last ( )
inline

Returns element lastIndex()

930  {
931  debugAssert(num > 0);
933  return data[num - 1];
934  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
int G3D::Array< T, MIN_ELEMENTS >::lastIndex ( ) const
inline

Returns size() - 1

937  {
938  debugAssertM(num > 0, "Array is empty");
939  return num - 1;
940  }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
int G3D::Array< T, MIN_ELEMENTS >::length ( ) const
inline

Number of elements in the array. (Same as size; this is just here for convenience).

438  {
439  return size();
440  }
int size() const
Definition: Array.h:430

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
template<typename Comparator >
void G3D::Array< T, MIN_ELEMENTS >::medianPartition ( Array< T > &  ltMedian,
Array< T > &  eqMedian,
Array< T > &  gtMedian,
Array< T > &  tempArray,
const Comparator &  comparator 
) const
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.

Parameters
tempArrayused for working scratch space
comparatorsee parition() for a discussion.
1252  {
1253 
1254  ltMedian.fastClear();
1255  eqMedian.fastClear();
1256  gtMedian.fastClear();
1257 
1258  // Handle trivial cases first
1259  switch (size()) {
1260  case 0:
1261  // Array is empty; no parition is possible
1262  return;
1263 
1264  case 1:
1265  // One element
1266  eqMedian.append(first());
1267  return;
1268 
1269  case 2:
1270  {
1271  // Two element array; median is the smaller
1272  int c = comparator(first(), last());
1273 
1274  switch (c) {
1275  case -1:
1276  // first was bigger
1277  eqMedian.append(last());
1278  gtMedian.append(first());
1279  break;
1280 
1281  case 0:
1282  // Both equal to the median
1283  eqMedian.append(first(), last());
1284  break;
1285 
1286  case 1:
1287  // Last was bigger
1288  eqMedian.append(first());
1289  gtMedian.append(last());
1290  break;
1291  }
1292  }
1293  return;
1294  }
1295 
1296  // All other cases use a recursive randomized median
1297 
1298  // Number of values less than all in the current arrays
1299  int ltBoost = 0;
1300 
1301  // Number of values greater than all in the current arrays
1302  int gtBoost = 0;
1303 
1304  // For even length arrays, force the gt array to be one larger than the
1305  // lt array:
1306  // [1 2 3] size = 3, choose half = (s + 1) /2
1307  //
1308  int lowerHalfSize, upperHalfSize;
1309  if (isEven(size())) {
1310  lowerHalfSize = size() / 2;
1311  upperHalfSize = lowerHalfSize + 1;
1312  } else {
1313  lowerHalfSize = upperHalfSize = (size() + 1) / 2;
1314  }
1315  const T* xPtr = NULL;
1316 
1317  // Maintain pointers to the arrays; we'll switch these around during sorting
1318  // to avoid copies.
1319  const Array<T>* source = this;
1320  Array<T>* lt = &ltMedian;
1321  Array<T>* eq = &eqMedian;
1322  Array<T>* gt = &gtMedian;
1323  Array<T>* extra = &tempArray;
1324 
1325  while (true) {
1326  // Choose a random element -- choose the middle element; this is theoretically
1327  // suboptimal, but for loosly sorted array is actually the best strategy
1328 
1329  xPtr = &(source->middle());
1330  if (source->size() == 1) {
1331  // Done; there's only one element left
1332  break;
1333  }
1334  const T& x = *xPtr;
1335 
1336  // Note: partition (fast) clears the arrays for us
1337  source->partition(x, *lt, *eq, *gt, comparator);
1338 
1339  int L = lt->size() + ltBoost + eq->size();
1340  int U = gt->size() + gtBoost + eq->size();
1341  if ((L >= lowerHalfSize) &&
1342  (U >= upperHalfSize)) {
1343 
1344  // x must be the partition median
1345  break;
1346 
1347  } else if (L < lowerHalfSize) {
1348 
1349  // x must be smaller than the median. Recurse into the 'gt' array.
1350  ltBoost += lt->size() + eq->size();
1351 
1352  // The new gt array will be the old source array, unless
1353  // that was the this pointer (i.e., unless we are on the
1354  // first iteration)
1355  Array<T>* newGt = (source == this) ? extra : const_cast<Array<T>*>(source);
1356 
1357  // Now set up the gt array as the new source
1358  source = gt;
1359  gt = newGt;
1360 
1361  } else {
1362 
1363  // x must be bigger than the median. Recurse into the 'lt' array.
1364  gtBoost += gt->size() + eq->size();
1365 
1366  // The new lt array will be the old source array, unless
1367  // that was the this pointer (i.e., unless we are on the
1368  // first iteration)
1369  Array<T>* newLt = (source == this) ? extra : const_cast<Array<T>*>(source);
1370 
1371  // Now set up the lt array as the new source
1372  source = lt;
1373  lt = newLt;
1374  }
1375  }
1376 
1377  // Now that we know the median, make a copy of it (since we're about to destroy the array that it
1378  // points into).
1379  T median = *xPtr;
1380  xPtr = NULL;
1381 
1382  // Partition the original array (note that this fast clears for us)
1383  partition(median, ltMedian, eqMedian, gtMedian, comparator);
1384  }
void fastClear()
Definition: Array.h:419
const T & last() const
Definition: Array.h:923
arena_t NULL
Definition: jemalloc_internal.h:624
int comparator(const void *ke1, const void *ke2)
Definition: WatcherKqueue.cpp:28
bool isEven(int num)
Definition: g3dmath.h:794
int size() const
Definition: Array.h:430
void partition(const T &partitionElement, Array< T > &ltArray, Array< T > &eqArray, Array< T > &gtArray, const Comparator &comparator) const
Definition: Array.h:1194
T & first()
Definition: Array.h:948
G3D::int16 x
Definition: Vector2int16.h:37
void append(const T &value)
Definition: Array.h:583

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::medianPartition ( Array< T > &  ltMedian,
Array< T > &  eqMedian,
Array< T > &  gtMedian 
) const
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.

1394  {
1395 
1396  Array<T> temp;
1397  medianPartition(ltMedian, eqMedian, gtMedian, temp, DefaultComparator());
1398  }
void medianPartition(Array< T > &ltMedian, Array< T > &eqMedian, Array< T > &gtMedian, Array< T > &tempArray, const Comparator &comparator) const
Definition: Array.h:1247
template<class T, size_t MIN_ELEMENTS = 10>
MemoryManager::Ref G3D::Array< T, MIN_ELEMENTS >::memoryManager ( ) const
inline
423  {
424  return m_memoryManager;
425  }
MemoryManager::Ref m_memoryManager
Definition: Array.h:108

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::middle ( ) const
inline

Returns element middleIndex()

965  {
966  debugAssertM(num > 0, "Array is empty");
967  return data[num >> 1];
968  }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::middle ( )
inline

Returns element middleIndex()

971  {
972  debugAssertM(num > 0, "Array is empty");
973  return data[num >> 1];
974  }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
int G3D::Array< T, MIN_ELEMENTS >::middleIndex ( ) const
inline

Returns iFloor(size() / 2), throws an assertion in debug mode if the array is empty

959  {
960  debugAssertM(num > 0, "Array is empty");
961  return num >> 1;
962  }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::next ( )
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()

762  {
763  resize(num + 1, false);
764  return last();
765  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
const T & last() const
Definition: Array.h:923
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
Array& G3D::Array< T, MIN_ELEMENTS >::operator= ( const Array< T, MIN_ELEMENTS > &  other)
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.

191  {
192  resize(other.num);
193  for (int i = 0; i < (int)num; ++i) {
194  data[i] = other[i];
195  }
196  return *this;
197  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
Array& G3D::Array< T, MIN_ELEMENTS >::operator= ( const std::vector< T > &  other)
inline
199  {
200  resize(other.size());
201  for (size_t i = 0; i < num; ++i) {
202  data[i] = other[i];
203  }
204  return *this;
205  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( int  n)
inline

Performs bounds checks in debug mode

868  {
869  debugAssertM((n >= 0) && (n < (int)num),
870  format("Array index out of bounds. n = %d, size() = %d", (int)n, (int)num));
872  return data[n];
873  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( uint32  n)
inline
875  {
876  debugAssertM(n < (uint32)num, format("Array index out of bounds. n = %d, size() = %d",
877  (int)n, (int)num));
878  return data[n];
879  }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
uint32_t uint32
Definition: Define.h:150
T * data
Definition: Array.h:103
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( uint64  n)
inline
881  {
882  debugAssertM(n < (uint64)num, format("Array index out of bounds. n = %d, size() = %d", (int)n, (int)num));
883  return data[n];
884  }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
uint64_t uint64
Definition: Define.h:149
T * data
Definition: Array.h:103
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( int  n) const
inline

Performs bounds checks in debug mode

889  {
890  debugAssert((n >= 0) && (n < (int)num));
891  debugAssert(data != NULL);
892  return data[n];
893  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( uint32  n) const
inline
895  {
896  debugAssert((n < (uint32)num));
898  return data[n];
899  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssert(exp)
Definition: debugAssert.h:160
uint32_t uint32
Definition: Define.h:150
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( uint64  n) const
inline
901  {
902  debugAssert((n < (uint64)num));
904  return data[n];
905  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssert(exp)
Definition: debugAssert.h:160
uint64_t uint64
Definition: Define.h:149
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
template<typename Comparator >
void G3D::Array< T, MIN_ELEMENTS >::partition ( const T &  partitionElement,
Array< T > &  ltArray,
Array< T > &  eqArray,
Array< T > &  gtArray,
const Comparator &  comparator 
) const
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.

Parameters
comparatorA 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;
    }
}
1199  {
1200 
1201  // Make sure all arrays are independent
1202  debugAssert(&ltArray != this);
1203  debugAssert(&eqArray != this);
1204  debugAssert(&gtArray != this);
1205  debugAssert(&ltArray != &eqArray);
1206  debugAssert(&ltArray != &gtArray);
1207  debugAssert(&eqArray != &gtArray);
1208 
1209  // Clear the arrays
1210  ltArray.fastClear();
1211  eqArray.fastClear();
1212  gtArray.fastClear();
1213 
1214  // Form a table of buckets for lt, eq, and gt
1215  Array<T>* bucket[3] = {&ltArray, &eqArray, &gtArray};
1216 
1217  for (size_t i = 0; i < num; ++i) {
1218  int c = comparator(partitionElement, data[i]);
1219  debugAssertM(c >= -1 && c <= 1, "Comparator returned an illegal value.");
1220 
1221  // Insert into the correct bucket, 0, 1, or 2
1222  bucket[c + 1]->append(data[i]);
1223  }
1224  }
void fastClear()
Definition: Array.h:419
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
int comparator(const void *ke1, const void *ke2)
Definition: WatcherKqueue.cpp:28
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::partition ( const T &  partitionElement,
Array< T > &  ltArray,
Array< T > &  eqArray,
Array< T > &  gtArray 
) const
inline

Uses < and == on elements to perform a partition. See partition().

1233  {
1234 
1235  partition(partitionElement, ltArray, eqArray, gtArray, typename Array<T>::DefaultComparator());
1236  }
void partition(const T &partitionElement, Array< T > &ltArray, Array< T > &eqArray, Array< T > &gtArray, const Comparator &comparator) const
Definition: Array.h:1194
template<class T, size_t MIN_ELEMENTS = 10>
T G3D::Array< T, MIN_ELEMENTS >::pop ( bool  shrinkUnderlyingArrayIfNecessary = true)
inline

Removes the last element and returns it. By default, shrinks the underlying array.

837  {
838  debugAssert(num > 0);
839  T temp = data[num - 1];
840  resize(num - 1, shrinkUnderlyingArrayIfNecessary);
841  return temp;
842  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::pop_back ( )
inline

"The member function removes the last element of the controlled sequence, which must be non-empty." For compatibility with std::vector.

785  {
786  pop();
787  }
T pop(bool shrinkUnderlyingArrayIfNecessary=true)
Definition: Array.h:837
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::popDiscard ( bool  shrinkUnderlyingArrayIfNecessary = false)
inline

Pops the last element and discards it without returning anything. Faster than pop. By default, does not shrink the underlying array.

846  {
847  debugAssert(num > 0);
848  resize(num - 1, shrinkUnderlyingArrayIfNecessary);
849  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
#define debugAssert(exp)
Definition: debugAssert.h:160
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::push ( const T &  value)
inline

Pushes an element onto the end (appends)

770  {
771  append(value);
772  }
const FieldDescriptor value
Definition: descriptor.h:1522
void append(const T &value)
Definition: Array.h:583

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::push ( const Array< T > &  array)
inline
774  {
775  append(array);
776  }
void append(const T &value)
Definition: Array.h:583
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::push_back ( const T &  v)
inline

Alias to provide std::vector compatibility

779  {
780  push(v);
781  }
void push(const T &value)
Definition: Array.h:770

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::randomElement ( )
inline
907  {
908  debugAssert(num > 0);
910  return data[iRandom(0, (int)num - 1)];
911  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
int iRandom(int low, int hi)
Definition: g3dmath.cpp:110
template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::randomElement ( ) const
inline
913  {
914  debugAssert(num > 0);
916  return data[iRandom(0, num - 1)];
917  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssert(exp)
Definition: debugAssert.h:160
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
int iRandom(int low, int hi)
Definition: g3dmath.cpp:110
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::randomize ( )
inline

Redistributes the elements so that the new order is statistically independent of the original order. O(n) time.

1405  {
1406  T temp;
1407 
1408  for (int i = size() - 1; i >= 0; --i) {
1409  int x = iRandom(0, i);
1410 
1411  temp = data[i];
1412  data[i] = data[x];
1413  data[x] = temp;
1414  }
1415  }
T * data
Definition: Array.h:103
int size() const
Definition: Array.h:430
G3D::int16 x
Definition: Vector2int16.h:37
int iRandom(int low, int hi)
Definition: g3dmath.cpp:110
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::realloc ( size_t  oldNum)
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.

151  {
152  T* oldData = data;
153 
154  // The allocation is separate from the constructor invocation because we don't want
155  // to pay for the cost of constructors until the newly allocated
156  // elements are actually revealed to the application. They
157  // will be constructed in the resize() method.
158 
159  data = (T*)m_memoryManager->alloc(sizeof(T) * numAllocated);
160  alwaysAssertM(data, "Memory manager returned NULL: out of memory?");
161 
162  // Call the copy constructors
163  {const size_t N = G3D::min(oldNum, numAllocated);
164  const T* end = data + N;
165  T* oldPtr = oldData;
166  for (T* ptr = data; ptr < end; ++ptr, ++oldPtr) {
167 
168  // Use placement new to invoke the constructor at the location
169  // that we determined. Use the copy constructor to make the assignment.
170  const T* constructed = new (ptr) T(*oldPtr);
171 
172  (void)constructed;
173  debugAssertM(constructed == ptr,
174  "new returned a different address than the one provided by Array.");
175  }}
176 
177  // Call destructors on the old array (if there is no destructor, this will compile away)
178  {const T* end = oldData + oldNum;
179  for (T* ptr = oldData; ptr < end; ++ptr) {
180  ptr->~T();
181  }}
182 
183  m_memoryManager->free(oldData);
184  }
ConstIterator end() const
Definition: Array.h:244
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
T min(const T &x, const T &y)
Definition: g3dmath.h:305
MemoryManager::Ref m_memoryManager
Definition: Array.h:108
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::remove ( Iterator  element,
int  count = 1 
)
inline

Removes count elements from the array referenced either by index or Iterator.

1044  {
1045  debugAssert((element >= begin()) && (element < end()));
1046  debugAssert((count > 0) && (element + count) <= end());
1047  Iterator last = end() - count;
1048 
1049  while(element < last) {
1050  element[0] = element[count];
1051  ++element;
1052  }
1053 
1054  resize(num - count);
1055  }
T * Iterator
Definition: Array.h:214
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
ConstIterator end() const
Definition: Array.h:244
const T & last() const
Definition: Array.h:923
Iterator begin()
Definition: Array.h:233
#define debugAssert(exp)
Definition: debugAssert.h:160
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::remove ( int  index,
int  count = 1 
)
inline
1057  {
1058  debugAssert((index >= 0) && (index < (int)num));
1059  debugAssert((count > 0) && (index + count <= (int)num));
1060 
1061  remove(begin() + index, count);
1062  }
Iterator begin()
Definition: Array.h:233
#define debugAssert(exp)
Definition: debugAssert.h:160
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::removeNulls ( )
inline

Remove all NULL elements in linear time without affecting order of the other elements.

1433  {
1434  int nextNull = 0;
1435  for (int i = 0; i < size(); ++i) {
1436  if (notNull(data[i])) {
1437  if (i > nextNull) {
1438  // Move value i down to squeeze out NULLs
1439  data[nextNull] = data[i];
1440  }
1441  ++nextNull;
1442  }
1443  }
1444 
1445  resize(nextNull, false);
1446  }
bool notNull(const Pointer< T > &p)
Definition: Pointer.h:350
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
T * data
Definition: Array.h:103
int size() const
Definition: Array.h:430
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::reserve ( int  n)
inline

Ensures that future append() calls can grow up to size n without allocating memory.

1419  {
1420  debugAssert(n >= size());
1421  const int oldSize = size();
1422  resize(n);
1423  resize(oldSize, false);
1424  }
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
#define debugAssert(exp)
Definition: debugAssert.h:160
int size() const
Definition: Array.h:430

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::resize ( size_t  n,
bool  shrinkIfNecessary = true 
)
inline
Parameters
shrinkIfNecessaryif false, memory will never be reallocated when the array shrinks. This makes resizing much faster but can waste memory. Default = true.
See also
clear, trimToSize
490  {
491  alwaysAssertM(n < 0xFFFFFFFF, "This implementation does not support arrays with more than 2^32 elements, although the size in memory may be larger.");
492  if (num == n) {
493  return;
494  }
495 
496  size_t oldNum = num;
497  num = n;
498 
499  // Call the destructors on newly hidden elements if there are any
500  for (size_t i = num; i < oldNum; ++i) {
501  (data + i)->~T();
502  }
503 
504  // Once allocated, always maintain MIN_ELEMENTS elements or 32 bytes, whichever is higher.
505  const size_t minSize = G3D::max(MIN_ELEMENTS, (size_t)(MIN_BYTES / sizeof(T)));
506 
507  if ((MIN_ELEMENTS == 0) && (MIN_BYTES == 0) && (n == 0) && shrinkIfNecessary) {
508  // Deallocate the array completely
509  numAllocated = 0;
510  m_memoryManager->free(data);
511  data = NULL;
512  return;
513  }
514 
515  if (num > numAllocated) {
516  // Grow the underlying array
517 
518  if (numAllocated == 0) {
519  // First allocation; grow to exactly the size requested to avoid wasting space.
520  numAllocated = n;
521  debugAssert(oldNum == 0);
522  realloc(oldNum);
523  } else {
524 
525  if (num < minSize) {
526  // Grow to at least the minimum size
527  numAllocated = minSize;
528 
529  } else {
530 
531  // Increase the underlying size of the array. Grow aggressively
532  // up to 64k, less aggressively up to 400k, and then grow relatively
533  // slowly (1.5x per resize) to avoid excessive space consumption.
534  //
535  // These numbers are tweaked according to performance tests.
536 
537  double growFactor = 3.0f;
538 
539  size_t oldSizeBytes = numAllocated * sizeof(T);
540  if (oldSizeBytes > 10000000) {
541  // Conserve memory more tightly above 10 MB
542  growFactor = 1.2f;
543  } else if (oldSizeBytes > 400000) {
544  // Avoid bloat above 400k
545  growFactor = 1.5f;
546  } else if (oldSizeBytes > 64000) {
547  // This is what std:: uses at all times
548  growFactor = 2.0f;
549  }
550 
551  numAllocated = (num - numAllocated) + (size_t)(numAllocated * growFactor);
552 
553  if (numAllocated < minSize) {
554  numAllocated = minSize;
555  }
556  }
557 
558  realloc(oldNum);
559  }
560 
561  } else if ((num <= numAllocated / 3) && shrinkIfNecessary && (num > minSize)) {
562  // Shrink the underlying array
563 
564  // Only copy over old elements that still remain after resizing
565  // (destructors were called for others if we're shrinking)
566  realloc(min(num, oldNum));
567 
568  }
569 
570  // Call the constructors on newly revealed elements.
571  // Do not use parens because we don't want the intializer
572  // invoked for POD types.
573  for (size_t i = oldNum; i < num; ++i) {
574  new (data + i) T;
575  }
576  }
arena_t NULL
Definition: jemalloc_internal.h:624
T max(const T &x, const T &y)
Definition: g3dmath.h:320
T min(const T &x, const T &y)
Definition: g3dmath.h:305
MemoryManager::Ref m_memoryManager
Definition: Array.h:108
#define debugAssert(exp)
Definition: debugAssert.h:160
size_t numAllocated
Definition: Array.h:106
T * data
Definition: Array.h:103
static const size_t MIN_BYTES
Definition: Array.h:100
size_t num
Definition: Array.h:105
void realloc(size_t oldNum)
Definition: Array.h:151
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::reverse ( )
inline

Reverse the elements of the array in place.

1067  {
1068  T temp;
1069 
1070  size_t n2 = num / 2;
1071  for (size_t i = 0; i < n2; ++i) {
1072  temp = data[num - 1 - i];
1073  data[num - 1 - i] = data[i];
1074  data[i] = temp;
1075  }
1076  }
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
int G3D::Array< T, MIN_ELEMENTS >::rfindIndex ( const T &  value) const
inline

Returns the index of (the first occurance of) an index or -1 if not found. Searches from the right.

996  {
997  for (int i = num -1 ; i >= 0; --i) {
998  if (data[i] == value) {
999  return i;
1000  }
1001  }
1002  return -1;
1003  }
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
const FieldDescriptor value
Definition: descriptor.h:1522
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::setAll ( const T &  value)
inline

Sets all elements currently in the array to

Parameters
value
467  {
468  for (size_t i = 0; i < num; ++i) {
469  data[i] = value;
470  }
471  }
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
const FieldDescriptor value
Definition: descriptor.h:1522
template<class T, size_t MIN_ELEMENTS = 10>
int G3D::Array< T, MIN_ELEMENTS >::size ( ) const
inline

Number of elements in the array.

430  {
431  return (int)num;
432  }
size_t num
Definition: Array.h:105
template<class T, size_t MIN_ELEMENTS = 10>
size_t G3D::Array< T, MIN_ELEMENTS >::sizeInMemory ( ) const
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

1428  {
1429  return sizeof(Array<T>) + (sizeof(T) * numAllocated);
1430  }
size_t numAllocated
Definition: Array.h:106
template<class T, size_t MIN_ELEMENTS = 10>
template<class LessThan >
void G3D::Array< T, MIN_ELEMENTS >::sort ( const LessThan &  lessThan)
inline

Sort using a specific less-than function, e.g.:

bool __cdecl myLT(const MyClass& elem1, const MyClass& elem2) {
return elem1.x < elem2.x;
}

Note that for pointer arrays, the const must come after the class name, e.g., Array<MyClass*> uses:

bool __cdecl myLT(MyClass*const& elem1, MyClass*const& elem2) {
return elem1->x < elem2->x;
}

or a functor, e.g.,

bool
less_than_functor::operator()( const double& lhs, const double& rhs ) const
{
return( lhs < rhs? true : false );
}
1109  {
1110  // Using std::sort, which according to http://www.open-std.org/JTC1/SC22/WG21/docs/D_4.cpp
1111  // was 2x faster than qsort for arrays around size 2000 on intel core2 with gcc
1112  std::sort(data, data + num, lessThan);
1113  }
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105

+ Here is the caller graph for this function:

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::sort ( int  direction = SORT_INCREASING)
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:

bool T::operator>(const T& other) const {
return ...;
}
bool T::operator<(const T& other) const {
return ...;
}
1128  {
1129  if (direction == SORT_INCREASING) {
1130  std::sort(data, data + num);
1131  } else {
1132  std::sort(data, data + num, compareGT);
1133  }
1134  }
T * data
Definition: Array.h:103
size_t num
Definition: Array.h:105
const int SORT_INCREASING
Definition: Array.h:46
static bool __cdecl compareGT(const T &a, const T &b)
Definition: Array.h:141
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::sortSubArray ( int  beginIndex,
int  endIndex,
int  direction = SORT_INCREASING 
)
inline

Sorts elements beginIndex through and including endIndex.

1139  {
1140  if (direction == SORT_INCREASING) {
1141  std::sort(data + beginIndex, data + endIndex + 1);
1142  } else {
1143  std::sort(data + beginIndex, data + endIndex + 1, compareGT);
1144  }
1145  }
T * data
Definition: Array.h:103
const int SORT_INCREASING
Definition: Array.h:46
static bool __cdecl compareGT(const T &a, const T &b)
Definition: Array.h:141
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::sortSubArray ( int  beginIndex,
int  endIndex,
bool(__cdecl *lessThan)(const T &elem1, const T &elem2)   
)
inline
1147  {
1148  std::sort(data + beginIndex, data + endIndex + 1, lessThan);
1149  }
T * data
Definition: Array.h:103
template<class T, size_t MIN_ELEMENTS = 10>
template<typename StrictWeakOrdering >
void G3D::Array< T, MIN_ELEMENTS >::sortSubArray ( int  beginIndex,
int  endIndex,
StrictWeakOrdering &  lessThan 
)
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)

1156  {
1157  std::sort(data + beginIndex, data + endIndex + 1, lessThan);
1158  }
T * data
Definition: Array.h:103
template<class T, size_t MIN_ELEMENTS = 10>
static void G3D::Array< T, MIN_ELEMENTS >::swap ( Array< T, MIN_ELEMENTS > &  a,
Array< T, MIN_ELEMENTS > &  b 
)
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.

265  {
266  alwaysAssertM(a.memoryManager() == b.memoryManager(), "The arrays are required to have the same memory manager");
267  std::swap(a.data, b.data);
268  std::swap(a.num, b.num);
269  std::swap(a.numAllocated, b.numAllocated);
270  }
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::swap ( Array< T > &  str)
inline

"The member function swaps the controlled sequences between *this and str." Note that this is slower than the optimal std implementation.

For compatibility with std::vector.

858  {
859  Array<T> temp = str;
860  str = *this;
861  *this = temp;
862  }
template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::trimToSize ( )
inline

Resize this array to consume exactly the capacity required by its size.

See also
clear, resize, capacity, size
476  {
477  if (size() != capacity()) {
478  size_t oldNum = numAllocated;
479  numAllocated = size();
480  realloc(oldNum);
481  }
482  }
int capacity() const
Definition: Array.h:794
size_t numAllocated
Definition: Array.h:106
int size() const
Definition: Array.h:430
void realloc(size_t oldNum)
Definition: Array.h:151

Member Data Documentation

template<class T, size_t MIN_ELEMENTS = 10>
T* G3D::Array< T, MIN_ELEMENTS >::data
private

0...num-1 are initialized elements, num...numAllocated-1 are not

template<class T, size_t MIN_ELEMENTS = 10>
MemoryManager::Ref G3D::Array< T, MIN_ELEMENTS >::m_memoryManager
private
template<class T, size_t MIN_ELEMENTS = 10>
const size_t G3D::Array< T, MIN_ELEMENTS >::MIN_BYTES = 32
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.

template<class T, size_t MIN_ELEMENTS = 10>
size_t G3D::Array< T, MIN_ELEMENTS >::num
private
template<class T, size_t MIN_ELEMENTS = 10>
size_t G3D::Array< T, MIN_ELEMENTS >::numAllocated
private

The documentation for this class was generated from the following file: