#include <tlsortedarray.h>
Inheritance diagram for TLSortedArray< T, _OP >:
Public Member Functions | |
TLSortedArray (const _OP &op=_OP()) | |
Create empty heap. | |
~TLSortedArray () | |
Destroy heap clearing it. | |
T * | last () |
Clear the whole array. | |
const T * | last () const |
template<typename K> ssize_t | GetInsertIdx (const K &ent, int allow_dup) |
Get interstion index. | |
int | insert (const T &ent, int allow_dup, ssize_t *ret_idx=NULL) |
Add element to the array. | |
ssize_t | ReOrder (size_t idx, int allow_dup) |
Bring element at correct position in array. | |
void | ReOrder () |
Sort the array. | |
template<typename K> ssize_t | search (const K &key) |
Search an element in the array. | |
template<typename K> ssize_t | remove (const K &key) |
Remove element from array. Remove passed element. | |
size_t | CheckOrder () |
Debugging: check ordering condition for all entries. | |
Private Member Functions | |
TLSortedArray (const TLSortedArray &) | |
Do not use these:. | |
void | operator= (const TLSortedArray &) |
Sorted arrays allow to insert() and remove() in O(n), and search operations in O(log(n)) (binary search). Of course, the smallest and largest elements are accessible O(1). Removing the largest is O(1) as well.
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 array 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 60 of file tlsortedarray.h.
|
Do not use these:.
|
|
Create empty heap.
Definition at line 78 of file tlsortedarray.h. |
|
Destroy heap clearing it.
Definition at line 80 of file tlsortedarray.h. |
|
Debugging: check ordering condition for all entries.
Definition at line 264 of file tlsortedarray.h. References TLArray< T, _OP >::array(). |
|
Get interstion index. This returns the index where to add the passed element. Returned index is -1 if you shall not add the passed elem (allow_dup==0). Index i means that you should add ent at array[i] thus moving array[i] to array[i+1] etc. before doing so. For the allow_dup parameter, see insert(). Runtime is O(log(n)). Definition at line 112 of file tlsortedarray.h. References TLArray< T, _OP >::array(), and ssize_t. Referenced by TLSortedArray< T, _OP >::insert(), and TLSortedArray< T, _OP >::ReOrder(). |
|
Add element to the array. If allow_dup is set, add element even if it is already in the array. If allow_dup is <0, add as the first elem of the equal ones, if >0 as the last.
E.g. for a case insensitive match, adding "b" to "AAABBBCC" will yield:
Definition at line 147 of file tlsortedarray.h. References TLSortedArray< T, _OP >::GetInsertIdx(), TLArray< T, _OP >::insert(), and ssize_t. |
|
Definition at line 96 of file tlsortedarray.h. References TLArray< T, _OP >::arrayP(). |
|
Clear the whole array. Get last (=largest) element in the array (or NULL): Runtime is O(1). Definition at line 95 of file tlsortedarray.h. References TLArray< T, _OP >::arrayP(). |
|
|
|
Remove element from array. Remove passed element. Runtime is O(log(n)) for the search and O(n) for the move. In case several elements matching key exist, all of them are removed. Returns number of removed elements. Definition at line 240 of file tlsortedarray.h. References TLArray< T, _OP >::_downsize(), TLArray< T, _OP >::array(), TLArray< T, _OP >::arrayP(), and ssize_t. |
|
Sort the array. Reorder complete list; may be used if several elements were modified. This uses "insertion sort" to sort the list; hence runtime is O(m*n) with m being the number of elements which are not in the correct position. Hence, it is nearly O(n) as long as m << n. In the worst case (list not ordered), runtime is O(n^2).
Definition at line 197 of file tlsortedarray.h. References TLArray< T, _OP >::array(). |
|
Bring element at correct position in array. In case the array element with index idx was modified, call this function to have it put into the correct position in the array so that the array stays sorted. For the allow_dup parameter, see insert(). Runtime is O(log(n)) for the search and O(n) for the move.
Definition at line 171 of file tlsortedarray.h. References TLArray< T, _OP >::array(), TLSortedArray< T, _OP >::GetInsertIdx(), and ssize_t. |
|
Search an element in the array. This uses binary search and is hence O(log(n)).
Definition at line 224 of file tlsortedarray.h. References ssize_t, and TLBinarySearch(). |