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... | |
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.
References Murl::Hash::Reindex().
◆ 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.
References Murl::Hash::Trim().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, 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.
References Murl::Hash::Drop().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, 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.
References Murl::Hash::Reserve().
Referenced by Murl::ObjectMap< Murl::String, EvaluatorVariable >::Insert().
◆ 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.
References Murl::Hash::Unlink().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, 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< KeyType, DataType, ArrayType, 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.
References Murl::Hash::Find(), Murl::Hash::FindNext(), and Murl::Hash::Unlink().
◆ 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.
References Murl::Hash::IsUnlinked().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::IsUnlinked().
◆ HasUnlinked()
|
inline |
Check if the index has unlinked items.
- Returns
- true if there is at least one unlinked item.
References Murl::Hash::HasUnlinked().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::HasUnlinked(), and Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Sweep().
◆ GetUnlinked()
|
inline |
Get an array of indices of all unlinked items.
- Returns
- The array of indices.
References Murl::Hash::GetUnlinked().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::GetUnlinked(), and Murl::MapBase< KeyType, DataType, ArrayType, 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.
References Murl::Hash::Set().
Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Set(), and Murl::MapBase< KeyType, DataType, ArrayType, 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::Set().
◆ Add() [1/2]
|
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.
References Murl::Hash::Add().
Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Add(), Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Add(), Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::FindAdd(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindAdd(), Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::GetAdd(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Put().
◆ Add() [2/2]
|
inline |
Add an item.
- Parameters
-
key The item to add.
- Returns
- A reference to the added item.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::Add().
◆ 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::Add(), and Murl::Hash::Put().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::FindPut(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindPut(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::Put(), and Murl::MapBase< KeyType, DataType, ArrayType, 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::Put().
◆ 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::Add(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Find().
Referenced by Murl::IndexBase< KeyType, ArrayType, 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindAdd().
◆ 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::Find(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Put().
Referenced by Murl::IndexBase< KeyType, ArrayType, 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindPut().
◆ 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.
References Murl::Hash::Find().
Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Find(), Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Find(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindAdd(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindPut(), Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::GetAdd(), and Murl::IndexBase< KeyType, ArrayType, 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::Find().
◆ 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.
References Murl::Hash::FindNext().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::FindNext(), and Murl::IndexBase< KeyType, ArrayType, 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.
References Murl::Hash::FindPrev().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, 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.
References Murl::Hash::FindLast().
Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindLast(), and Murl::MapBase< KeyType, DataType, ArrayType, 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindLast().
◆ 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.
References Murl::Hash::Insert().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, 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.
References Murl::Hash::Insert().
◆ Remove() [1/4]
|
inline |
Remove the item at a given position.
- Parameters
-
index The index from where to remove the item.
References Murl::Hash::Remove().
Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Remove(), Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Remove(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::RemoveKey(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::Sweep(), and Murl::MapBase< KeyType, DataType, ArrayType, 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.
References Murl::Hash::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.
References Murl::Hash::Remove().
◆ Remove() [4/4]
|
inline |
Remove a number of items at given positions.
- Parameters
-
sortedIndices A sorted array of indices where to remove the items.
References Murl::Array< DataType >::GetCount(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Remove().
◆ 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.
References Murl::Array< DataType >::Add(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::Find(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindNext(), Murl::Array< DataType >::GetCount(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Remove().
Referenced by Murl::IndexBase< KeyType, ArrayType, 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::RemoveKey().
◆ Front()
|
inline |
Get a reference to the first item.
Synonymous to Bottom().
- Returns
- A reference to the first item.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::Bottom().
◆ Back()
|
inline |
Get a reference to the last item.
Synonymous to Top().
- Returns
- A reference to the last item.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::Top().
◆ Bottom()
|
inline |
Get a reference to the first item.
- Returns
- A reference to the first item.
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::BottomKey(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Front().
◆ Top()
|
inline |
Get a reference to the last item.
- Returns
- A reference to the last item.
Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Back(), and Murl::MapBase< KeyType, DataType, ArrayType, 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< KeyType, DataType, ArrayType, HashFunc >::GetKeys().
◆ Swap()
|
inline |
Exchange the content of the index object with a given second one.
- Parameters
-
other The second index object.
References Murl::Hash::Swap().
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Swap().
◆ Begin()
|
inline |
Get the const iterator to the first item.
- Returns
- The const iterator to the first item.
Referenced by Murl::MapBase< KeyType, DataType, ArrayType, 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< KeyType, DataType, ArrayType, 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< KeyType, DataType, ArrayType, 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< KeyType, DataType, ArrayType, HashFunc >::FindAdd(), Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::FindPut(), and Murl::MapBase< KeyType, DataType, ArrayType, 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< KeyType, ArrayType, HashFunc >::operator!=(), and Murl::IndexBase< KeyType, ArrayType, 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::IsEqual().
◆ 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.
References Murl::IndexBase< KeyType, ArrayType, HashFunc >::IsEqual().
The documentation for this class was generated from the following file:
- murl_index_base.h