A generic index template base class. More...
#include "murl_index_base.h"
Public Types | |
| using | ConstIterator = typename ArrayType::ConstIterator |
| Definition of the const iterator. | |
Public Member Functions | |
| void | Clear () |
| Clear the index object and remove the underlying storage. | |
| void | ClearIndex () |
| Clear the hash index. | |
| void | Empty () |
| Empty the index object, but keep the underlying storage. | |
| void | RebuildHash (const SInt32 n) |
| Clear and rebuild the hash index for a given number of items. More... | |
| void | RebuildHash () |
| Clear and rebuild the hash index. | |
| void | Shrink () |
| Shrink the index object so that the underlying storage is only as large as necessary. | |
| void | Trim (SInt32 n) |
| Reduce the index object to a given number of items. More... | |
| void | Drop (SInt32 n=1) |
| Reduce the index object by removing a given number of items from the end. More... | |
| void | Reserve (SInt32 n) |
| Reserve storage space. More... | |
| void | Unlink (const SInt32 index) |
| Unlink the item at a given index. More... | |
| SInt32 | UnlinkKey (const KeyType &key) |
| Unlink all items matching a given key. More... | |
| SInt32 | UnlinkKey (const KeyType &key, const UInt32 hash) |
| Unlink all items matching a given key, using a pre calculated hash value. More... | |
| Bool | IsUnlinked (const SInt32 index) const |
| Check if the item at a given index is unlinked. More... | |
| Bool | HasUnlinked () const |
| Check if the index has unlinked items. More... | |
| SInt32Array | GetUnlinked () const |
| Get an array of indices of all unlinked items. More... | |
| void | Sweep () |
| Remove all unlinked items from the index. | |
| KeyType & | Set (SInt32 index, const KeyType &key, const UInt32 hash) |
| Replace the item at a specified index using a precomputed hash. More... | |
| KeyType & | Set (const SInt32 index, const KeyType &key) |
| Replace the item at a specified index. More... | |
| KeyType & | Add (const KeyType &key, const UInt32 hash) |
| Add an item with a precomputed hash value. More... | |
| KeyType & | Add (const KeyType &key) |
| Add an item. More... | |
| SInt32 | Put (const KeyType &key, const UInt32 hash) |
| Add an item or replace an unlinked item if present, using a precomputed hash value. More... | |
| SInt32 | Put (const KeyType &key) |
| Add an item or replace an unlinked item if present. More... | |
| SInt32 | FindAdd (const KeyType &key, const UInt32 hash) |
| Find the first occurrence of a given item in the index, or add an item if the item was not found, using a precomputed hash value. More... | |
| SInt32 | FindAdd (const KeyType &key) |
| Find the first occurrence of a given item in the index, or add an item if the item was not found. More... | |
| SInt32 | FindPut (const KeyType &key, const UInt32 hash) |
| Find the first occurrence of a given item or add the item if the item was not found, using a precomputed hash value. More... | |
| SInt32 | FindPut (const KeyType &key) |
| Find the first occurrence of a given item or put the item if the item was not found. More... | |
| SInt32 | Find (const KeyType &key, const UInt32 hash) const |
| Find the first occurrence of a given item using a precomputed hash value. More... | |
| SInt32 | Find (const KeyType &key) const |
| Find the first occurrence of a given item. More... | |
| SInt32 | FindNext (SInt32 index) const |
| Find the next occurrence of an item that is specified by a given index. More... | |
| SInt32 | FindPrev (SInt32 index) const |
| Find the previous occurrence of an item that is specified by a given index. More... | |
| SInt32 | FindLast (const KeyType &key, const UInt32 hash) const |
| Find the last occurrence of a given item, using a precomputed hash value. More... | |
| SInt32 | FindLast (const KeyType &key) const |
| Find the last occurrence of a given item. More... | |
| KeyType & | Insert (SInt32 index, const KeyType &key, const UInt32 hash) |
| Insert an item at a given position, using a precomputed hash value. More... | |
| KeyType & | Insert (SInt32 index, const KeyType &key) |
| Insert an item at a given position. More... | |
| void | Remove (SInt32 index) |
| Remove the item at a given position. More... | |
| void | Remove (SInt32 index, SInt32 count) |
| Remove a number of items at a given starting position. More... | |
| void | Remove (const SInt32 *sortedIndices, SInt32 count) |
| Remove a number of items at given positions. More... | |
| void | Remove (const SInt32Array &sortedIndices) |
| Remove a number of items at given positions. More... | |
| SInt32 | RemoveKey (const KeyType &key, const UInt32 hash) |
| Remove all items that match a given item, using a precomputed hash value. More... | |
| SInt32 | RemoveKey (const KeyType &key) |
| Remove all items that match a given item. More... | |
| const KeyType & | Front () const |
| Get a reference to the first item. More... | |
| const KeyType & | Back () const |
| Get a reference to the last item. More... | |
| const KeyType & | Bottom () const |
| Get a reference to the first item. More... | |
| const KeyType & | Top () const |
| Get a reference to the last item. More... | |
| Bool | IsIndexValid (SInt32 index) const |
| Check if a given index is a valid index. More... | |
| const KeyType & | operator[] (SInt32 index) const |
| Get a const reference to the item at a given index. More... | |
| const KeyType & | Get (SInt32 index) const |
| Get a const reference to the item at a given index. More... | |
| SInt32 | GetAlloc () const |
| Get the number of actually allocated items. More... | |
| SInt32 | GetCount () const |
| Get the number of items. More... | |
| Bool | IsEmpty () const |
| Check if the Index is empty. More... | |
| const ArrayType & | GetKeys () const |
| Get a const reference to the array of items. More... | |
| void | Swap (IndexBase &other) |
| Exchange the content of the index object with a given second one. More... | |
| ConstIterator | Begin () const |
| Get the const iterator to the first item. More... | |
| ConstIterator | End () const |
| Get the const iterator next to the last item. More... | |
| ConstIterator | GetIter (SInt32 index) const |
| Get the const iterator of a specified index. More... | |
| SInt32 | GetIterIndex (ConstIterator iterator) const |
| Get the item index by iterator. More... | |
| UInt32 | CalculateHash (const KeyType &key) const |
| Calculate the hash for an item. More... | |
| Bool | IsEqual (const IndexBase &other) const |
| Compare the index to another one. More... | |
| bool | operator== (const IndexBase &rhs) const |
| The "equal to" comparison operator, calls IsEqual(). More... | |
| bool | operator!= (const IndexBase &rhs) const |
| The "not equal to" comparison operator, calls IsEqual(). More... | |
| void | Add (InitListType initList) |
| Add an initializer list to the index. More... | |
Detailed Description
template<class KeyType, class ArrayType, class HashFunc>
class Murl::IndexBase< KeyType, ArrayType, HashFunc >
A generic index template base class.
The index class stores a number of (not necessarily unique) keys in a hash table.
This is the base class of the Index and ObjectIndex class.
This class is based on the NTL AIndex container, see http://www.ultimatepp.org
- Template Parameters
-
KeyType The key's data type of the index. ArrayType The array type of the keys. HashFunc The hash function of the key.
Member Function Documentation
◆ RebuildHash()
|
inline |
Clear and rebuild the hash index for a given number of items.
- Parameters
-
n The number of items to rebuild.
◆ Trim()
|
inline |
Reduce the index object to a given number of items.
- Parameters
-
n The new number of items in the index, must be smaller than the current item count.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Trim().
◆ Drop()
|
inline |
Reduce the index object by removing a given number of items from the end.
- Parameters
-
n The number of items to remove from the end.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Drop().
◆ Reserve()
|
inline |
Reserve storage space.
If the given size is less than the actual size, nothing is done.
- Parameters
-
n The number of items the underlying storage should hold.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Reserve().
◆ Unlink()
|
inline |
Unlink the item at a given index.
Unlinked items remain in the Index, but are ignored by any search operations.
- Parameters
-
index The index of the item to unlink.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Unlink().
◆ UnlinkKey() [1/2]
|
inline |
Unlink all items matching a given key.
Unlinked items remain in the Index, but are ignored by any search operations.
- Parameters
-
key The key of the item(s) to unlink.
- Returns
- The number of items that were unlinked.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::UnlinkKey(), and Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::UnlinkKey().
◆ UnlinkKey() [2/2]
|
inline |
Unlink all items matching a given key, using a pre calculated hash value.
Unlinked items remain in the Index, but are ignored by any search operations.
- Parameters
-
key The key of the item(s) to unlink. hash The pre calculated hash value.
- Returns
- The number of items that were unlinked.
◆ IsUnlinked()
|
inline |
Check if the item at a given index is unlinked.
- Parameters
-
index The index of the item to check.
- Returns
- true if the specified item is unlinked.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::IsUnlinked().
◆ HasUnlinked()
|
inline |
Check if the index has unlinked items.
- Returns
- true if there is at least one unlinked item.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::HasUnlinked(), and Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Sweep().
◆ GetUnlinked()
|
inline |
Get an array of indices of all unlinked items.
- Returns
- The array of indices.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::GetUnlinked(), and Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Sweep().
◆ Set() [1/2]
|
inline |
Replace the item at a specified index using a precomputed hash.
- Parameters
-
index The index to set. key The value to set. hash The precomputed hash.
- Returns
- A reference to the set item.
Referenced by Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::Set(), and Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::SetKey().
◆ Set() [2/2]
|
inline |
Replace the item at a specified index.
- Parameters
-
index The index to set. key The value to set.
- Returns
- A reference to the set item.
◆ Add() [1/3]
|
inline |
Add an item with a precomputed hash value.
- Parameters
-
key The item to add. hash The precomputed hash.
- Returns
- A reference to the added item.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Add(), Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::Add(), Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::FindAdd(), Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::FindAdd(), Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::GetAdd(), and Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::Put().
◆ Add() [2/3]
|
inline |
Add an item.
- Parameters
-
key The item to add.
- Returns
- A reference to the added item.
◆ Put() [1/2]
|
inline |
Add an item or replace an unlinked item if present, using a precomputed hash value.
- Parameters
-
key The item to add. hash The precomputed hash.
- Returns
- The index of the item.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::FindPut(), Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::FindPut(), Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Put(), and Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::Put().
◆ Put() [2/2]
|
inline |
Add an item or replace an unlinked item if present.
- Parameters
-
key The item to add.
- Returns
- The index of the item.
◆ FindAdd() [1/2]
|
inline |
Find the first occurrence of a given item in the index, or add an item if the item was not found, using a precomputed hash value.
- Parameters
-
key The item to search for and add. hash The precomputed hash.
- Returns
- The index of the item.
Referenced by Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::FindAdd().
◆ FindAdd() [2/2]
|
inline |
Find the first occurrence of a given item in the index, or add an item if the item was not found.
- Parameters
-
key The item to search for and add.
- Returns
- The index of the item.
◆ FindPut() [1/2]
|
inline |
Find the first occurrence of a given item or add the item if the item was not found, using a precomputed hash value.
Hereby replacing an unlinked element if possible.
- Parameters
-
key The item to search for and add. hash The precomputed hash.
- Returns
- The index of the item.
Referenced by Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::FindPut().
◆ FindPut() [2/2]
|
inline |
Find the first occurrence of a given item or put the item if the item was not found.
Hereby replacing an unlinked element if possible.
- Parameters
-
key The item to search for and add.
- Returns
- The index of the item.
◆ Find() [1/2]
|
inline |
Find the first occurrence of a given item using a precomputed hash value.
- Parameters
-
key The item to search for. hash The precomputed hash.
- Returns
- The index of the item, or -1 if not found.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Find(), Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::Find(), Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::FindAdd(), Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::FindPut(), Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::GetAdd(), and Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::RemoveKey().
◆ Find() [2/2]
|
inline |
Find the first occurrence of a given item.
- Parameters
-
key The item to search for.
- Returns
- The index of the item, or -1 if not found.
◆ FindNext()
|
inline |
Find the next occurrence of an item that is specified by a given index.
- Parameters
-
index The index of the item containing the key to search for.
- Returns
- The index of the next item, or -1 if not found.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::FindNext(), and Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::RemoveKey().
◆ FindPrev()
|
inline |
Find the previous occurrence of an item that is specified by a given index.
- Parameters
-
index The index of the item containing the key to search for.
- Returns
- The index of the previous item, or -1 if not found.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::FindPrev().
◆ FindLast() [1/2]
|
inline |
Find the last occurrence of a given item, using a precomputed hash value.
- Parameters
-
key The item to search for. hash The precomputed hash value.
- Returns
- The index of the item, or -1 if not found.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::FindLast(), and Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::FindLast().
◆ FindLast() [2/2]
|
inline |
Find the last occurrence of a given item.
- Parameters
-
key The item to search for.
- Returns
- The index of the item, or -1 if not found.
◆ Insert() [1/2]
|
inline |
Insert an item at a given position, using a precomputed hash value.
- Parameters
-
index The index where to insert the item. key The item to insert. hash The precomputed hash value.
- Returns
- A reference to the inserted item.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Insert().
◆ Insert() [2/2]
|
inline |
Insert an item at a given position.
- Parameters
-
index The index where to insert the item. key The item to insert.
- Returns
- A reference to the inserted item.
◆ Remove() [1/4]
|
inline |
Remove the item at a given position.
- Parameters
-
index The index from where to remove the item.
Referenced by Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::Remove(), Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Remove(), Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::RemoveKey(), Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::Sweep(), and Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Sweep().
◆ Remove() [2/4]
|
inline |
Remove a number of items at a given starting position.
- Parameters
-
index The index from where to start removing the items. count The number of subsequent items to remove.
◆ Remove() [3/4]
|
inline |
Remove a number of items at given positions.
- Parameters
-
sortedIndices A pointer to sorted indices where to remove the items. count The number of items to remove, i.e. the number of indices.
◆ Remove() [4/4]
|
inline |
Remove a number of items at given positions.
- Parameters
-
sortedIndices A sorted array of indices where to remove the items.
◆ RemoveKey() [1/2]
|
inline |
Remove all items that match a given item, using a precomputed hash value.
- Parameters
-
key The item to remove. hash The precomputed hash value.
- Returns
- The number of items that were removed.
Referenced by Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::RemoveKey().
◆ RemoveKey() [2/2]
|
inline |
Remove all items that match a given item.
- Parameters
-
key The item to remove.
- Returns
- The number of items that were removed.
◆ Front()
|
inline |
◆ Back()
|
inline |
◆ Bottom()
|
inline |
Get a reference to the first item.
- Returns
- A reference to the first item.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::BottomKey(), and Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::Front().
◆ Top()
|
inline |
Get a reference to the last item.
- Returns
- A reference to the last item.
Referenced by Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::Back(), and Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::TopKey().
◆ IsIndexValid()
|
inline |
Check if a given index is a valid index.
- Parameters
-
index The index to check.
- Returns
- true if index >= 0 and index < GetCount().
◆ operator[]()
|
inline |
Get a const reference to the item at a given index.
If the index is out of range, the behaviour is undefined.
- Parameters
-
index The index of the item to retrieve.
- Returns
- A const reference to the requested item.
◆ Get()
|
inline |
Get a const reference to the item at a given index.
If the index is out of range, the behaviour is undefined.
- Parameters
-
index The index of the item to retrieve.
- Returns
- A const reference to the requested item.
◆ GetAlloc()
|
inline |
Get the number of actually allocated items.
- Returns
- The number of allocated items.
◆ GetCount()
|
inline |
Get the number of items.
- Returns
- The number of items.
◆ IsEmpty()
|
inline |
◆ GetKeys()
|
inline |
Get a const reference to the array of items.
- Returns
- A const reference to the underlying item storage array.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::GetKeys().
◆ Swap()
|
inline |
Exchange the content of the index object with a given second one.
- Parameters
-
other The second index object.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::Swap().
◆ Begin()
|
inline |
Get the const iterator to the first item.
- Returns
- The const iterator to the first item.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::KeyBegin().
◆ End()
|
inline |
Get the const iterator next to the last item.
- Returns
- The const iterator next to the last item.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::KeyEnd().
◆ GetIter()
|
inline |
Get the const iterator of a specified index.
- Parameters
-
index The index for the iterator.
- Returns
- The const iterator or null if the index is out of range.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::KeyGetIter().
◆ GetIterIndex()
|
inline |
Get the item index by iterator.
(!) Adding or removing items will invalidate iterators.
- Parameters
-
iterator The iterator of the item.
- Returns
- The index of the item, or -1 if the iterator is invalid.
◆ CalculateHash()
|
inline |
Calculate the hash for an item.
- Parameters
-
key The item to calculate.
- Returns
- The hash value of the item.
Referenced by Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::FindAdd(), Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::FindPut(), and Murl::MapBase< const Murl::Graph::IBoundingVolume *, ShadowItem *, Array< ShadowItem * >, HashFunc >::GetAdd().
◆ IsEqual()
|
inline |
Compare the index to another one.
- Parameters
-
other The index to compare.
- Returns
- true if all keys have identical contents.
Referenced by Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::operator!=(), and Murl::IndexBase< Murl::Video::IFrameBuffer *, Array< Murl::Video::IFrameBuffer * >, HashFunc >::operator==().
◆ operator==()
|
inline |
The "equal to" comparison operator, calls IsEqual().
- Parameters
-
rhs The right hand side index to compare.
- Returns
- true if all keys have identical contents.
◆ operator!=()
|
inline |
The "not equal to" comparison operator, calls IsEqual().
- Parameters
-
rhs The right hand side index to compare.
- Returns
- true if the indices differ.
◆ Add() [3/3]
|
inline |
Add an initializer list to the index.
- Parameters
-
initList The initializer list to be added.
The documentation for this class was generated from the following file:
- murl_index_base.h