#include <tlarray.h>
Inheritance diagram for TLArray< T, _OP >:
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. |
This class can be used to implement array-based heaps and stacks but also directly for arrays.
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.
|
Do not use.
|
|
Create empty array.
|
|
Destroy array clearing it.
|
|
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(). |
|
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(). |
|
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(). |
|
Get new size of array when shrinking the array.
Definition at line 99 of file tlarray.h. Referenced by TLArray< RJumpEntry, RJumpEntry_Operators >::_downsize(). |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
Assign element with passed index. This will overwrite the element [idx] with a new value as passed in e. Runtime is O(1).
|
|
Perform binary search in array. Binary search can only be used if the array is sorted ascentingly. Runtime is O(log(n)).
|
|
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(). |
|
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).
Definition at line 175 of file tlarray.h. Referenced by TLSortedArray< T, _OP >::insert(). |
|
Is the array empty? Runtime O(1).
Definition at line 137 of file tlarray.h. Referenced by VM::AssemblerFile_Plaintext::_WriteFunctionProgram(). |
|
Perform linear search in array. Search starts at index sidx (default: 0). Runtime is O(n-sidx).
|
|
Get number of elements in array:.
Definition at line 141 of file tlarray.h. Referenced by VM::AssemblerFile_Plaintext::_WriteFunctionProgram(), and main(). |
|
Do not use.
|
|
See non-const version.
Reimplemented in TLArrayHeap< T, _OP >, and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >. |
|
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 >. |
|
Remove element with passed index. This will remove the element [idx] and move all elements with higher indeces one down. Runtime is O(n).
|
|
Array memory; use array(idx) for subscript.
|
|
Number of allocated array elements.
|
|
Array size (number of elements).
|
|
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(). |