array Class Template Reference

#include <irrArray.h>

Inheritance diagram for array:

StringList

Detailed Description

template<class T>
class irr::core::array< T >

Some features are: Heap sorting, binary search methods, easier debugging.

Public Member Functions


Constructor & Destructor Documentation

array (  )  [inline]

array ( u32  start_count  )  [inline]

Constructs a array and allocates an initial chunk of memory.

Parameters:
start_count,: Amount of elements to allocate.

array ( const array< T > &  other  )  [inline]

~array (  )  [inline]

Destructor. Frees allocated memory, if set_free_when_destroyed was not set to false by the user before.


Member Function Documentation

u32 allocated_size (  )  const [inline]

Returns amount memory allocated.

Returns:
Returns amount of memory allocated. The amount of bytes allocated would be allocated_size() * sizeof(ElementsUsed);

s32 binary_search ( const T &  element,
s32  left,
s32  right 
) [inline]

Performs a binary search for an element, returns -1 if not found. The array will be sorted before the binary search if it is not already sorted.

Parameters:
element,: Element to search for.
left,: First left index
right,: Last right index.
Returns:
Returns position of the searched element if it was found, otherwise -1 is returned.

s32 binary_search ( const T &  element  )  [inline]

Performs a binary search for an element, returns -1 if not found. The array will be sorted before the binary search if it is not already sorted.

Parameters:
element,: Element to search for.
Returns:
Returns position of the searched element if it was found, otherwise -1 is returned.

void clear (  )  [inline]

const T* const_pointer (  )  const [inline]

Returns a const pointer to the array.

Returns:
Pointer to the array.

bool empty (  )  const [inline]

Returns true if array is empty

Returns:
True if the array is empty, false if not.

void erase ( u32  index,
s32  count 
) [inline]

Erases some elements from the array. may be slow, because all elements following after the erased element have to be copied.

Parameters:
index,: Index of the first element to be erased.
count,: Amount of elements to be erased.

void erase ( u32  index  )  [inline]

Erases an element from the array. May be slow, because all elements following after the erased element have to be copied.

Parameters:
index,: Index of element to be erased.

T& getLast (  )  [inline]

const T& getLast (  )  const [inline]

void insert ( const T &  element,
u32  index = 0 
) [inline]

Insert item into array at specified position. Please use this only if you know what you are doing (possible performance loss). The preferred method of adding elements should be push_back().

Parameters:
element,: Element to be inserted
index,: Where position to insert the new element.

s32 linear_reverse_search ( const T &  element  )  const [inline]

Finds an element in linear time, which is very slow. Use binary_search for faster finding. Only works if =operator is implemented.

Parameters:
element,: Element to search for.
Returns:
Returns position of the searched element if it was found, otherwise -1 is returned.

s32 linear_search ( const T &  element  )  const [inline]

Finds an element in linear time, which is very slow. Use binary_search for faster finding. Only works if =operator is implemented.

Parameters:
element,: Element to search for.
Returns:
Returns position of the searched element if it was found, otherwise -1 is returned.

void operator= ( const array< T > &  other  )  [inline]

const T& operator[] ( u32  index  )  const [inline]

T& operator[] ( u32  index  )  [inline]

T* pointer (  )  [inline]

Returns a pointer to the array.

Returns:
Pointer to the array.

void push_back ( const T &  element  )  [inline]

Adds an element at back of array. If the array is to small to add this new element, the array is made bigger.

Parameters:
element,: Element to add at the back of the array.

void push_front ( const T &  element  )  [inline]

Adds an element at the front of the array. If the array is to small to add this new element, the array is made bigger. Please note that this is slow, because the whole array needs to be copied for this.

Parameters:
element,: Element to add at the back of the array.

void reallocate ( u32  new_size  )  [inline]

Reallocates the array, make it bigger or smaller.

Parameters:
new_size,: New size of array.

void set_free_when_destroyed ( bool  f  )  [inline]

Sets if the array should delete the memory it used.

Parameters:
f,: If true, the array frees the allocated memory in its destructor, otherwise not. The default is true.

void set_pointer ( T *  newPointer,
u32  size 
) [inline]

Sets pointer to new array, using this as new workspace.

Parameters:
newPointer,: Pointer to new array of elements.
size,: Size of the new array.

void set_sorted ( bool  _is_sorted  )  [inline]

void set_used ( u32  usedNow  )  [inline]

Sets the size of the array.

Parameters:
usedNow,: Amount of elements now used.

u32 size (  )  const [inline]

Returns size of used array.

Returns:
Size of elements in the array.

void sort (  )  [inline]

Sorts the array using heapsort. There is no additional memory waste and the algorithm performs (O) n log n in worst case.


Generated on Fri Apr 27 14:47:02 2007 for IrrSpintz by  doxygen 1.5.1-p1