Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

TLArray< T, _OP > Class Template Reference

Dynamic array template. More...

#include <tlarray.h>

Inheritance diagram for TLArray< T, _OP >:

Inheritance graph
[legend]
Collaboration diagram for TLArray< T, _OP >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TLArray (const _OP &op=_OP())
 Create empty array.

virtual ~TLArray ()
 Destroy array clearing it.

bool IsEmpty () const
 Is the array empty? Runtime O(1).

size_t NElem () const
 Get number of elements in array:.

T & operator[] (size_t idx)
 Get element with passed index as reference.

const T & operator[] (size_t idx) const
 See non-const version.

void clear (bool keep_memory=0)
 Clear the whole array. Never free it if keep_memory is set.

int insert (const T &e, size_t idx)
 Insert element into the array.

int remove (size_t idx)
 Remove element with passed index.

int assign (const T &e, size_t idx)
 Assign element with passed index.

template<typename K> ssize_t LinSearch (const K &key, size_t sidx=0)
 Perform linear search in array.

template<typename K> ssize_t BinSearch (const K &key)
 Perform binary search in array.


Public Attributes

_OP OP

Protected Member Functions

T & array (size_t idx)
 Use this for array subscript if you want a reference:.

T * arrayP (size_t idx)
 Use this for array subscript if you want a pointer:.

virtual void _realloc (size_t new_asize)
 Perform reallocation operation to change array size.

void _free ()
 Free the array memory.

size_t _get_downsize ()
 Get new size of array when shrinking the array.

void _downsize ()
 Perform array shrinking if necessary.

void _upsize1 ()
 Perform array growth by one element.

void _clearall ()
 Clear all elements in the array using OP.clr().


Protected Attributes

size_t asize
 Number of allocated array elements.

size_t nelem
 Array size (number of elements).

char * _array
 Array memory; use array(idx) for subscript.


Private Member Functions

 TLArray (const TLArray &)
 Do not use.

void operator= (const TLArray &)
 Do not use.


Detailed Description

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
class TLArray< T, _OP >

Dynamic array template.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
Implements dynamic array which automatically grows or shrinks.

This class can be used to implement array-based heaps and stacks but also directly for arrays.

Attention:
Be aware that the array internally uses one allocated memory chunk and hence needs to re-allocate in order to grow and shrink. This has 2 consequences: WHAT TO USE FOR <T>: (Standard text from tlbtree.h:) This class is probably most useful for T being a simple type (integer, unique pointers to a class or small data-only structures). You may use any POD type or any struct/class which is a "plain data type" (PDT; see defop.h) and even for "complex data types" as long as you can provide the required operator plugin OP and it has a working default constructor and a working copy constructor (both for temporaries).
Thread safety: The complete must be protected by a mutex for all "write" operations.

This class is NOT "C++-safe", i.e. do not use the assignment operator or the copy constructor (these are private).

Definition at line 65 of file tlarray.h.


Constructor & Destructor Documentation

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
TLArray< T, _OP >::TLArray const TLArray< T, _OP > &   )  [private]
 

Do not use.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
TLArray< T, _OP >::TLArray const _OP &  op = _OP()  )  [inline]
 

Create empty array.

Definition at line 131 of file tlarray.h.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
virtual TLArray< T, _OP >::~TLArray  )  [inline, virtual]
 

Destroy array clearing it.

Definition at line 133 of file tlarray.h.


Member Function Documentation

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
void TLArray< T, _OP >::_clearall  )  [inline, protected]
 

Clear all elements in the array using OP.clr().

Reimplemented in TLArrayHeap< T, _OP >, and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >.

Definition at line 118 of file tlarray.h.

Referenced by TLArray< RJumpEntry, RJumpEntry_Operators >::clear(), and TLArray< RJumpEntry, RJumpEntry_Operators >::~TLArray().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
void TLArray< T, _OP >::_downsize  )  [inline, protected]
 

Perform array shrinking if necessary.

Definition at line 106 of file tlarray.h.

Referenced by TLSortedArray< T, _OP >::remove(), and TLArray< RJumpEntry, RJumpEntry_Operators >::remove().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
void TLArray< T, _OP >::_free  )  [inline, protected]
 

Free the array memory.

Definition at line 93 of file tlarray.h.

Referenced by TLArray< RJumpEntry, RJumpEntry_Operators >::clear(), TLArray< RJumpEntry, RJumpEntry_Operators >::~TLArray(), and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::~TLArrayHeap().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
size_t TLArray< T, _OP >::_get_downsize  )  [inline, protected]
 

Get new size of array when shrinking the array.

Definition at line 99 of file tlarray.h.

Referenced by TLArray< RJumpEntry, RJumpEntry_Operators >::_downsize().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
virtual void TLArray< T, _OP >::_realloc size_t  new_asize  )  [inline, protected, virtual]
 

Perform reallocation operation to change array size.

Reimplemented in TLArrayHeap< T, _OP >, and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >.

Definition at line 87 of file tlarray.h.

Referenced by TLArray< RJumpEntry, RJumpEntry_Operators >::_downsize(), and TLArray< RJumpEntry, RJumpEntry_Operators >::_upsize1().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
void TLArray< T, _OP >::_upsize1  )  [inline, protected]
 

Perform array growth by one element.

Definition at line 112 of file tlarray.h.

Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::insert(), and TLArray< RJumpEntry, RJumpEntry_Operators >::insert().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
T& TLArray< T, _OP >::array size_t  idx  )  [inline, protected]
 

Use this for array subscript if you want a reference:.

Definition at line 80 of file tlarray.h.

Referenced by TLArray< RJumpEntry, RJumpEntry_Operators >::assign(), TLSortedArray< T, _OP >::CheckOrder(), TLSortedArray< T, _OP >::GetInsertIdx(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::heap(), TLArray< RJumpEntry, RJumpEntry_Operators >::insert(), TLArray< RJumpEntry, RJumpEntry_Operators >::LinSearch(), TLArray< RJumpEntry, RJumpEntry_Operators >::operator[](), TLSortedArray< T, _OP >::remove(), TLArray< RJumpEntry, RJumpEntry_Operators >::remove(), and TLSortedArray< T, _OP >::ReOrder().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
T* TLArray< T, _OP >::arrayP size_t  idx  )  [inline, protected]
 

Use this for array subscript if you want a pointer:.

Definition at line 83 of file tlarray.h.

Referenced by TLArray< RJumpEntry, RJumpEntry_Operators >::_clearall(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::heapP(), TLArray< RJumpEntry, RJumpEntry_Operators >::insert(), TLSortedArray< T, _OP >::last(), TLSortedArray< T, _OP >::remove(), and TLArray< RJumpEntry, RJumpEntry_Operators >::remove().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
int TLArray< T, _OP >::assign const T &  e,
size_t  idx
[inline]
 

Assign element with passed index.

This will overwrite the element [idx] with a new value as passed in e.

Runtime is O(1).

Returns:
0 on success, -2 if the index is out of range.

Definition at line 212 of file tlarray.h.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
template<typename K>
ssize_t TLArray< T, _OP >::BinSearch const K key  )  [inline]
 

Perform binary search in array.

Binary search can only be used if the array is sorted ascentingly.

Runtime is O(log(n)).

Returns:
index of the first occurance or -1 if not found.

Definition at line 240 of file tlarray.h.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
void TLArray< T, _OP >::clear bool  keep_memory = 0  )  [inline]
 

Clear the whole array. Never free it if keep_memory is set.

Reimplemented in TLArrayHeap< T, _OP >, and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >.

Definition at line 161 of file tlarray.h.

Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::clear().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
int TLArray< T, _OP >::insert const T &  e,
size_t  idx
[inline]
 

Insert element into the array.

Insert element e before index idx in the array. After the operation, e will be stored in [idx] and all following elements were moved up by one index.

Runtime is O(n).

Returns:
0 on success, -2 if the index is out of range.

Definition at line 175 of file tlarray.h.

Referenced by TLSortedArray< T, _OP >::insert().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
bool TLArray< T, _OP >::IsEmpty  )  const [inline]
 

Is the array empty? Runtime O(1).

Definition at line 137 of file tlarray.h.

Referenced by VM::AssemblerFile_Plaintext::_WriteFunctionProgram().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
template<typename K>
ssize_t TLArray< T, _OP >::LinSearch const K key,
size_t  sidx = 0
[inline]
 

Perform linear search in array.

Search starts at index sidx (default: 0).

Runtime is O(n-sidx).

Returns:
index of the first occurance or -1 if not found.

Definition at line 224 of file tlarray.h.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
size_t TLArray< T, _OP >::NElem  )  const [inline]
 

Get number of elements in array:.

Definition at line 141 of file tlarray.h.

Referenced by VM::AssemblerFile_Plaintext::_WriteFunctionProgram(), and main().

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
void TLArray< T, _OP >::operator= const TLArray< T, _OP > &   )  [private]
 

Do not use.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
const T& TLArray< T, _OP >::operator[] size_t  idx  )  const [inline]
 

See non-const version.

Reimplemented in TLArrayHeap< T, _OP >, and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >.

Definition at line 157 of file tlarray.h.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
T& TLArray< T, _OP >::operator[] size_t  idx  )  [inline]
 

Get element with passed index as reference.

NO RANGE CHECK! Range: 0..NElem()-1.

Runtime is O(1).

Note: Probably only useful if you need to iterate through the elements or obtained an index via some function.

Reimplemented in TLArrayHeap< T, _OP >, and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >.

Definition at line 154 of file tlarray.h.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
int TLArray< T, _OP >::remove size_t  idx  )  [inline]
 

Remove element with passed index.

This will remove the element [idx] and move all elements with higher indeces one down.

Runtime is O(n).

Returns:
0 on success, -2 if the index is out of range.

Definition at line 195 of file tlarray.h.


Member Data Documentation

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
char* TLArray< T, _OP >::_array [protected]
 

Array memory; use array(idx) for subscript.

Definition at line 71 of file tlarray.h.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
size_t TLArray< T, _OP >::asize [protected]
 

Number of allocated array elements.

Definition at line 69 of file tlarray.h.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
size_t TLArray< T, _OP >::nelem [protected]
 

Array size (number of elements).

Definition at line 70 of file tlarray.h.

template<typename T, typename _OP = TLDefaultOperators_CDT<T>>
_OP TLArray< T, _OP >::OP
 

These are the operators... normally, the default OPs will not occupy any place (i.e. 1byte compiler dummy or so).

Definition at line 76 of file tlarray.h.

Referenced by main().


The documentation for this class was generated from the following file:
Generated on Sat Feb 19 22:35:46 2005 for Ray by doxygen 1.3.5