Support Forum       G3D Web Page     
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
G3D::Array< T, MIN_ELEMENTS > Class Template Reference


Dynamic 1D array tuned for performance. More...

Classes

class  DefaultComparator
 Uses < and == to evaluate operator(); this is the default comparator for Array::partition. More...
 

Public Types

typedef ConstIterator const_iterator
 stl porting compatibility helper More...
 
typedef const T * ConstIterator
 G3D C++ STL style const iterator in same style as Iterator. More...
 
typedef int difference_type
 stl porting compatibility helper More...
 
typedef T * Iterator
 
G3D C++ STL style iterator variable. More...
 
typedef Iterator iterator
 stl porting compatibility helper More...
 
typedef int size_type
 stl porting compatibility helper More...
 
typedef T value_type
 stl porting compatibility helper More...
 

Public Member Functions

 Array ()
 Creates a zero length array (no heap allocation occurs until resize). More...
 
 Array (const T &v0)
 Creates an array containing v0. More...
 
 Array (const T &v0, const T &v1)
 Creates an array containing v0 and v1. More...
 
 Array (const T &v0, const T &v1, const T &v2)
 Creates an array containing v0...v2. More...
 
 Array (const T &v0, const T &v1, const T &v2, const T &v3)
 Creates an array containing v0...v3. More...
 
 Array (const T &v0, const T &v1, const T &v2, const T &v3, const T &v4)
 Creates an array containing v0...v4. More...
 
 Array (const T &v0, const T &v1, const T &v2, const T &v3, const T &v4, const T &v5)
 Creates an array containing v0...v5. More...
 
 Array (const T &v0, const T &v1, const T &v2, const T &v3, const T &v4, const T &v5, const T &v6)
 Creates an array containing v0...v6. More...
 
 Array (const T &v0, const T &v1, const T &v2, const T &v3, const T &v4, const T &v5, const T &v6, const T &v7)
 Creates an array containing v0...v7. More...
 
 Array (std::initializer_list< T > args)
 Creates an array containing any number of arguments using curly braces. More...
 
 Array (const Array &other)
 
Copy constructor. More...
 
 Array (const std::vector< T > &other)
 
 ~Array ()
 
Destructor does not delete() the objects if T is a pointer type (e.g. More...
 
void append (const T &value)
 
Add an element to the end of the array. More...
 
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)
 
void append (const T &v1, const T &v2, const T &v3, const T &v4, const T &v5, const T &v6, const T &v7)
 
template<class S >
void append (const Array< S > &array)
 
Append the elements of array. More...
 
void appendPOD (const Array< T > &other)
 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. More...
 
T & back ()
 "The member function returns a reference to the last element of the controlled sequence, which must be non-empty. More...
 
const T & back () const
 "The member function returns a reference to the last element of the controlled sequence, which must be non-empty. More...
 
Iterator begin ()
 
C++ STL style iterator method. More...
 
ConstIterator begin () const
 
int capacity () const
 "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. More...
 
void clear (bool shrink=true)
 
Removes all elements. More...
 
void clearAndSetMemoryManager (const shared_ptr< MemoryManager > &m)
 
bool contains (const T &e) const
 
Returns true if the given element is in the array. More...
 
void copyFrom (const Array< T > &other)
 
void copyPOD (const Array< T > &other)
 Resizes this to match the size of other and then copies the data from other using memcpy. More...
 
ConstIterator end () const
 
C++ STL style iterator method. More...
 
Iterator end ()
 
void fastClear ()
 resize(0, false) More...
 
void fastRemove (int index, bool shrinkIfNecessary=false)
 
Swaps element index with the last element in the array then shrinks the array by one. More...
 
template<class S >
Iterator find (const S &value)
 
Finds an element and returns the iterator to it. More...
 
template<class S >
ConstIterator find (const S &value) const
 
template<class S >
int findIndex (const S &value) const
 
Returns the index of (the first occurance of) an index or -1 if not found. More...
 
T & first ()
 Returns element firstIndex(), performing a check in debug mode to ensure that there is at least one. More...
 
const T & first () const
 
int firstIndex () const
 
T & front ()
 "The member function returns a reference to the first element of the controlled sequence, which must be non-empty. More...
 
const T & front () const
 "The member function returns a reference to the first element of the controlled sequence, which must be non-empty. More...
 
T * getCArray ()
 
The array returned is only valid until the next append() or resize call, or the Array is deallocated. More...
 
const T * getCArray () const
 
The array returned is only valid until the next append() or resize call, or the Array is deallocated. More...
 
void insert (int n, const T &value)
 
Inserts at the specified index and shifts all other elements up by one. More...
 
void invokeDeleteOnAllElements ()
 
Calls delete on all objects[0...size-1] and sets the size to zero. More...
 
const T & last () const
 
Returns the last element, performing a check in debug mode that there is at least one element. More...
 
T & last ()
 Returns element lastIndex() More...
 
int lastIndex () const
 Returns size() - 1 More...
 
int length () const
 
Number of elements in the array. More...
 
template<typename Comparator >
void medianPartition (Array< T > &ltMedian, Array< T > &eqMedian, Array< T > &gtMedian, Array< T > &tempArray, const Comparator &comparator) const
 
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. More...
 
void medianPartition (Array< T > &ltMedian, Array< T > &eqMedian, Array< T > &gtMedian) const
 Computes a median partition using the default comparator and a dynamically allocated temporary working array. More...
 
shared_ptr< MemoryManagermemoryManager () const
 
const T & middle () const
 Returns element middleIndex() More...
 
T & middle ()
 Returns element middleIndex() More...
 
int middleIndex () const
 Returns iFloor(size() / 2), throws an assertion in debug mode if the array is empty. More...
 
T & next ()
 
Pushes a new element onto the end and returns its address. More...
 
T & next (DoNotInitialize dni)
 Returns a pointer to memory for the next element, invoking either its DoNotInitialize constructor for performance, or its default constructor if the array needs to be resized anyway. More...
 
Arrayoperator= (const Array &other)
 
Assignment operator. More...
 
Arrayoperator= (const std::vector< T > &other)
 
T & operator[] (int n)
 
Performs bounds checks in debug mode More...
 
T & operator[] (uint32 n)
 
T & operator[] (size_t n)
 
T & operator[] (uint64 n)
 
const T & operator[] (int n) const
 
Performs bounds checks in debug mode More...
 
const T & operator[] (uint32 n) const
 
const T & operator[] (size_t n) const
 
const T & operator[] (uint64 n) const
 
template<typename Comparator >
void partition (const T &partitionElement, Array< T > &ltArray, Array< T > &eqArray, Array< T > &gtArray, const Comparator &comparator) const
 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. More...
 
void partition (const T &partitionElement, Array< T > &ltArray, Array< T > &eqArray, Array< T > &gtArray) const
 Uses < and == on elements to perform a partition. More...
 
pop (bool shrinkUnderlyingArrayIfNecessary=true)
 
Removes the last element and returns it. More...
 
void pop_back ()
 "The member function removes the last element of the controlled sequence, which must be non-empty." For compatibility with std::vector. More...
 
void popDiscard (bool shrinkUnderlyingArrayIfNecessary=false)
 Pops the last element and discards it without returning anything. More...
 
void push (const T &value)
 
Pushes an element onto the end (appends) More...
 
void push (const Array< T > &array)
 
void push_back (const T &v)
 Alias to provide std::vector compatibility. More...
 
T & randomElement ()
 
const T & randomElement () const
 
void randomize ()
 Redistributes the elements so that the new order is statistically independent of the original order. More...
 
void randomize (Random &rng)
 Redistributes the elements so that the new order is statistically independent of the original order. More...
 
template<class B >
void randomize (Array< B > &b, Random &rng)
 Redistributes the elements so that the new order is statistically independent of the original order. More...
 
void remove (Iterator element, int count=1)
 
Removes count elements from the array referenced either by index or Iterator. More...
 
void remove (int index, int count=1)
 
void removeNulls ()
 Remove all nullptr elements in linear time without affecting order of the other elements. More...
 
void reserve (int n)
 Ensures that future append() calls can grow up to size n without allocating memory. More...
 
void resize (size_t n, bool shrinkIfNecessary=true)
 
void reverse ()
 
Reverse the elements of the array in place. More...
 
template<class S >
int rfindIndex (const S &value) const
 
Returns the index of (the first occurance of) an index or -1 if not found. More...
 
void setAll (const T &value)
 Sets all elements currently in the array to. More...
 
int size () const
 
Number of elements in the array. More...
 
size_t sizeInMemory () const
 Number of bytes used by the array object and the memory allocated for it's data pointer. More...
 
template<class LessThan >
void sort (const LessThan &lessThan)
 
Sort using a specific less-than function, e.g. More...
 
void sort (int direction=SORT_INCREASING)
 
Sorts the array in increasing order using the > or < operator. More...
 
void sortSubArray (int beginIndex, int endIndex, int direction=SORT_INCREASING)
 
Sorts elements beginIndex through and including endIndex. More...
 
void sortSubArray (int beginIndex, int endIndex, bool(*lessThan)(const T &elem1, const T &elem2))
 
template<typename StrictWeakOrdering >
void sortSubArray (int beginIndex, int endIndex, StrictWeakOrdering &lessThan)
 
The StrictWeakOrdering can be either a class that overloads the function call operator() or a function pointer of the form bool (*lessThan)(const T& elem1, const T& elem2) More...
 
void swap (Array< T > &str)
 
"The member function swaps the controlled sequences between *this and str." Note that this is slower than the optimal std implementation. More...
 
void trimToSize ()
 Resize this array to consume exactly the capacity required by its size. More...
 

Static Public Member Functions

static void swap (Array< T, MIN_ELEMENTS > &a, Array< T, MIN_ELEMENTS > &b)
 Exchanges all data between the two arrays, which are required to have a common MemoryManager. More...
 

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

◆ const_iterator

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

stl porting compatibility helper

◆ ConstIterator

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.

◆ difference_type

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

stl porting compatibility helper

◆ Iterator

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.

◆ iterator

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

stl porting compatibility helper

◆ size_type

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

stl porting compatibility helper

◆ value_type

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

stl porting compatibility helper

Constructor & Destructor Documentation

◆ Array() [1/12]

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).

◆ Array() [2/12]

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

Creates an array containing v0.

◆ Array() [3/12]

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.

◆ Array() [4/12]

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.

◆ Array() [5/12]

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.

◆ Array() [6/12]

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.

◆ Array() [7/12]

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,
const T &  v5 
)
inline

Creates an array containing v0...v5.

◆ Array() [8/12]

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,
const T &  v5,
const T &  v6 
)
inline

Creates an array containing v0...v6.

◆ Array() [9/12]

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,
const T &  v5,
const T &  v6,
const T &  v7 
)
inline

Creates an array containing v0...v7.

◆ Array() [10/12]

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

Creates an array containing any number of arguments using curly braces.

For example,

Array<int> {5, 10, 3, 4, 1}

◆ Array() [11/12]

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?

◆ Array() [12/12]

template<class T, size_t MIN_ELEMENTS = 10>
G3D::Array< T, MIN_ELEMENTS >::Array ( const std::vector< T > &  other)
inlineexplicit

◆ ~Array()

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).

Member Function Documentation

◆ append() [1/8]

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.

Referenced by G3D::Spline< UprightFrame >::append(), G3D::Array< G3D::AABox >::append(), G3D::GLFWWindow::appendFileToFileList(), G3D::Array< G3D::AABox >::copyFrom(), G3D::Pathfinder< Node, HashFunc >::findPath(), G3D::ArticulatedModel::getAnimationNames(), G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::getHandles(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::Node::getHandles(), G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::getIntersectingMembers(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::Node::getIntersectingMembers(), G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::getIntersectingMembers(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::getIntersectingMembers(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getKeys(), G3D::Table< String, double >::getKeys(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::getMembers(), G3D::WeakCache< G3D::Sampler, shared_ptr< G3D::GLSamplerObject > >::getValues(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getValues(), G3D::Table< String, double >::getValues(), G3D::FastPointHashGrid< Value, PosFunc >::insert(), G3D::Array< G3D::AABox >::medianPartition(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::operator=(), G3D::Array< G3D::AABox >::partition(), G3D::SmallArray< G3D::Vector4, 8 >::push(), G3D::Array< G3D::AABox >::push(), G3D::AudioDevice::WeakCleanupArray< G3D::Sound >::remember(), G3D::OrderedTable< Key, Value >::set(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::SmallTable(), G3D::Spline< UprightFrame >::Spline(), and G3D::Welder::weld().

◆ append() [2/8]

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::append ( const T &  v1,
const T &  v2 
)
inline

◆ append() [3/8]

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

◆ append() [4/8]

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

◆ append() [5/8]

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

◆ append() [6/8]

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

◆ append() [7/8]

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,
const T &  v7 
)
inline

◆ append() [8/8]

template<class T, size_t MIN_ELEMENTS = 10>
template<class S >
void G3D::Array< T, MIN_ELEMENTS >::append ( const Array< S > &  array)
inline


Append the elements of array.

Cannot be called with this array as an argument.

Can append elements of any array that are implicitly convertable (e.g., pointers to subclass instances) to type T.

◆ appendPOD()

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

Referenced by G3D::Args::setMultiDrawArrays().

◆ back() [1/2]

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.

◆ back() [2/2]

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.

◆ begin() [1/2]

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.

Referenced by G3D::Array< G3D::AABox >::remove().

◆ begin() [2/2]

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

◆ capacity()

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.

Referenced by G3D::Array< G3D::AABox >::trimToSize().

◆ clear()

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::clear ( bool  shrink = true)
inline

◆ clearAndSetMemoryManager()

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::clearAndSetMemoryManager ( const shared_ptr< MemoryManager > &  m)
inline

◆ contains()

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.

Referenced by G3D::SmallArray< G3D::Vector4, 8 >::contains(), and G3D::BlockPoolMemoryManager::free().

◆ copyFrom()

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

◆ copyPOD()

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

◆ end() [1/2]

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.

Referenced by G3D::Array< G3D::AABox >::find(), and G3D::Array< G3D::AABox >::remove().

◆ end() [2/2]

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

◆ fastClear()

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

◆ fastRemove()

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

◆ find() [1/2]

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


Finds an element and returns the iterator to it.

If the element isn't found then returns end().

◆ find() [2/2]

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

◆ findIndex()

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


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

Referenced by G3D::SmallArray< G3D::Vector4, 8 >::findIndex(), and G3D::VideoRecordDialog::setScreenShotFormat().

◆ first() [1/2]

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

◆ first() [2/2]

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

◆ firstIndex()

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

◆ front() [1/2]

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.

◆ front() [2/2]

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.

◆ getCArray() [1/2]

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

◆ getCArray() [2/2]

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.

◆ insert()

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.

◆ invokeDeleteOnAllElements()

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.

Referenced by G3D::BlockPoolMemoryManager::~BlockPoolMemoryManager().

◆ last() [1/2]

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

◆ last() [2/2]

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

Returns element lastIndex()

◆ lastIndex()

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

Returns size() - 1

◆ length()

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

◆ medianPartition() [1/2]

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.

Referenced by G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::makeNode(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::makeNode(), and G3D::Array< G3D::AABox >::medianPartition().

◆ medianPartition() [2/2]

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.

◆ memoryManager()

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

◆ middle() [1/2]

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

◆ middle() [2/2]

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

Returns element middleIndex()

◆ middleIndex()

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.

◆ next() [1/2]

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()

Referenced by G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getCreateEntry(), and G3D::SmallArray< G3D::Vector4, 8 >::next().

◆ next() [2/2]

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

Returns a pointer to memory for the next element, invoking either its DoNotInitialize constructor for performance, or its default constructor if the array needs to be resized anyway.

If T does not have a DoNotInitialize constructor then this will fail at compile time.

◆ operator=() [1/2]

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.

◆ operator=() [2/2]

template<class T, size_t MIN_ELEMENTS = 10>
Array& G3D::Array< T, MIN_ELEMENTS >::operator= ( const std::vector< T > &  other)
inline

◆ operator[]() [1/8]

template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( int  n)
inline


Performs bounds checks in debug mode

◆ operator[]() [2/8]

template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( uint32  n)
inline

◆ operator[]() [3/8]

template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( size_t  n)
inline

◆ operator[]() [4/8]

template<class T, size_t MIN_ELEMENTS = 10>
T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( uint64  n)
inline

◆ operator[]() [5/8]

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

◆ operator[]() [6/8]

template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( uint32  n) const
inline

◆ operator[]() [7/8]

template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( size_t  n) const
inline

◆ operator[]() [8/8]

template<class T, size_t MIN_ELEMENTS = 10>
const T& G3D::Array< T, MIN_ELEMENTS >::operator[] ( uint64  n) const
inline

◆ partition() [1/2]

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 String::compare). For example:
int compare(int A, int B) {
    if (A < B) {
        return 1;
    } else if (A == B) {
        return 0;
    } else {
        return -1;
    }
}

Referenced by G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::makeNode(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::makeNode(), G3D::Array< G3D::AABox >::medianPartition(), and G3D::Array< G3D::AABox >::partition().

◆ partition() [2/2]

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().

◆ pop()

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

◆ pop_back()

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.

◆ popDiscard()

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.

Referenced by G3D::SmallArray< G3D::Vector4, 8 >::popDiscard().

◆ push() [1/2]

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

◆ push() [2/2]

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

◆ push_back()

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.

◆ randomElement() [1/2]

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

◆ randomElement() [2/2]

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

◆ randomize() [1/3]

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.

Referenced by G3D::Array< G3D::AABox >::randomize().

◆ randomize() [2/3]

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

Redistributes the elements so that the new order is statistically independent of the original order.

O(n) time.

◆ randomize() [3/3]

template<class T, size_t MIN_ELEMENTS = 10>
template<class B >
void G3D::Array< T, MIN_ELEMENTS >::randomize ( Array< B > &  b,
Random rng 
)
inline

Redistributes the elements so that the new order is statistically independent of the original order.

O(n) time. Randomizes both arrays in the same way.

◆ remove() [1/2]

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.

Referenced by G3D::OrderedTable< Key, Value >::removeKey().

◆ remove() [2/2]

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

◆ removeNulls()

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

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

◆ reserve()

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

◆ resize()

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::resize ( size_t  n,
bool  shrinkIfNecessary = true 
)
inline

◆ reverse()

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


Reverse the elements of the array in place.

Referenced by G3D::Pathfinder< Node, HashFunc >::findPath().

◆ rfindIndex()

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


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

Searches from the right.

◆ setAll()

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

◆ size()

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


Number of elements in the array.

Referenced by G3D::BlockPoolMemoryManager::alloc(), G3D::Spline< UprightFrame >::append(), G3D::AttributeArray::AttributeArray(), G3D::Array< G3D::AABox >::back(), G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::clearData(), G3D::_internal::PolyLineGeneric< SegmentType, VertexType >::closed(), G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::computeBounds(), G3D::Array< G3D::AABox >::contains(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::containsKey(), G3D::AttributeArray::createInterleaved(), G3D::cyclicCatmullRomSpline(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::deleteKeys(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::deleteValues(), G3D::deserialize(), G3D::_internal::PolyLineGeneric< SegmentType, VertexType >::distance(), G3D::Spline< UprightFrame >::evaluate(), G3D::PathTracer::BufferSet::fastRemove(), G3D::Array< G3D::AABox >::fastRemove(), G3D::OrderedTable< Key, Value >::fastRemoveKey(), G3D::OrderedTable< Key, Value >::findIndexOfValue(), G3D::BlockPoolMemoryManager::freeListNumBlocks(), G3D::Spline< UprightFrame >::getControl(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getCreateEntry(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::getIntersectingMembers(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getKeys(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::getMembers(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getPointer(), G3D::WeakCache< G3D::Sampler, shared_ptr< G3D::GLSamplerObject > >::getValues(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::getValues(), G3D::Args::hasGPUIndexStream(), G3D::Spline< UprightFrame >::hashCode(), G3D::Spline< UprightFrame >::init(), G3D::FastPointHashGrid< Value, PosFunc >::insert(), G3D::PointHashGrid< Value, PosFunc, EqualsFunc >::insert(), G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::insert(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::insert(), G3D::Array< G3D::AABox >::length(), G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::makeNode(), G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::makeNode(), G3D::Array< G3D::AABox >::medianPartition(), G3D::XML::numChildren(), G3D::PhysicsFrameSplineEditor::numControlPoints(), G3D::_internal::PolyLineGeneric< SegmentType, VertexType >::numSegments(), G3D::_internal::PolyLineGeneric< SegmentType, VertexType >::numVertices(), G3D::ConvexPolygon::numVertices(), G3D::ConvexPolygon2D::numVertices(), G3D::Discovery::Server::ok(), G3D::FastPointHashGrid< Value, PosFunc >::Iterator::operator++(), G3D::FastPointHashGrid< Value, PosFunc >::BoxIterator::operator++(), G3D::SmallArray< G3D::Vector4, 8 >::operator=(), G3D::Array< G3D::AABox >::operator=(), G3D::Spline< UprightFrame >::operator==(), G3D::PointHashGrid< Value, PosFunc, EqualsFunc >::PointHashGrid(), G3D::_internal::PolyLineGeneric< SegmentType, VertexType >::PolyLineGeneric(), G3D::Array< G3D::AABox >::randomize(), G3D::receive(), G3D::OrderedTable< Key, Value >::removeKey(), G3D::Array< G3D::AABox >::removeNulls(), G3D::Array< G3D::AABox >::reserve(), G3D::send(), G3D::RenderDevice::sendIndices(), G3D::serialize(), G3D::OrderedTable< Key, Value >::set(), G3D::Map2D< Color1, Color1 >::setAll(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::setSizeHint(), G3D::IconSet::size(), G3D::CPUVertexArray::size(), G3D::OrderedTable< Key, Value >::size(), G3D::Spline< UprightFrame >::size(), G3D::SmallTable< Key, Value, HashFunc, EqualsFunc >::size(), G3D::UprightSplineManipulator::splineSize(), G3D::MeshAlg::toIndexedTriList(), G3D::ArticulatedModel::Mesh::triangleCount(), G3D::Array< G3D::AABox >::trimToSize(), G3D::AttributeArray::update(), G3D::AttributeArray::updateInterleaved(), G3D::_internal::PolyLineGeneric< SegmentType, VertexType >::vertex(), and G3D::ConvexPolygon2D::vertex().

◆ sizeInMemory()

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

◆ sort() [1/2]

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 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 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 );
}

◆ sort() [2/2]

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 ...;
}

◆ sortSubArray() [1/3]

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.

◆ sortSubArray() [2/3]

template<class T, size_t MIN_ELEMENTS = 10>
void G3D::Array< T, MIN_ELEMENTS >::sortSubArray ( int  beginIndex,
int  endIndex,
bool(*)(const T &elem1, const T &elem2)  lessThan 
)
inline

◆ sortSubArray() [3/3]

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 (*lessThan)(const T& elem1, const T& elem2)

◆ swap() [1/2]

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.

◆ swap() [2/2]

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.

◆ trimToSize()

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

documentation generated on Wed Nov 24 2021 08:01:53 using doxygen 1.8.15