Murl::ObjectIndex< KeyType, HashFunc > Class Template Reference

A generic index template class for non-moveable objects eg. NonCopyable classes. More...

#include "murl_object_index.h"

Inheritance diagram for Murl::ObjectIndex< KeyType, HashFunc >:

Public Types

using KeyValueType = KeyType
 The template key parameter value type.
 
using HashValueType = HashFunc
 The template hash parameter value type.
 
- Public Types inherited from Murl::IndexBase< KeyType, ObjectArray< KeyType >, StdHash< KeyType > >
using ConstIterator = typename ArrayType::ConstIterator
 Definition of the const iterator.
 

Public Member Functions

 ObjectIndex ()
 The default constructor. More...
 
 ObjectIndex (const ObjectIndex &index)
 The copy constructor. More...
 
 ObjectIndex (const ObjectArray< KeyType > &array)
 Constructor taking an array. More...
 
KeyType & Add (KeyType *key, UInt32 hash)
 Add a new allocated item with a precomputed hash value. More...
 
KeyType & Add (KeyType *key)
 Add a new allocated item. More...
 
KeyType & Set (SInt32 index, KeyType *key, UInt32 hash)
 Replace the item at a specified index using a precomputed hash. More...
 
KeyType & Set (SInt32 index, KeyType *key)
 Replace the item at a specified index. More...
 
KeyType * PopDetach ()
 Removes the item from the top position and giving up ownership. More...
 
KeyType * Detach (SInt32 index)
 Removes the item at a given position and giving up ownership. 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...
 
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...
 
- Public Member Functions inherited from Murl::IndexBase< KeyType, ObjectArray< KeyType >, StdHash< KeyType > >
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 ObjectArray< KeyType > & 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 HashFunc = StdHash<KeyType>>
class Murl::ObjectIndex< KeyType, HashFunc >

A generic index template class for non-moveable objects eg. NonCopyable classes.

See IndexBase class for all index methods.
The index class stores a number of (not necessarily unique) keys in a hash table.
The object index class uses pointers to the key objects, this ensures that the object's memory location is unchanged when modifying the index.
This class is based on the NTL ArrayIndex container, see http://www.ultimatepp.org

Template Parameters
KeyTypeThe key's data type of the index.
HashFuncThe hash function of the key.

Constructor & Destructor Documentation

◆ ObjectIndex() [1/3]

template<class KeyType , class HashFunc = StdHash<KeyType>>
Murl::ObjectIndex< KeyType, HashFunc >::ObjectIndex ( )
inline

The default constructor.

Create an empty index object.

◆ ObjectIndex() [2/3]

template<class KeyType , class HashFunc = StdHash<KeyType>>
Murl::ObjectIndex< KeyType, HashFunc >::ObjectIndex ( const ObjectIndex< KeyType, HashFunc > &  index)
inline

The copy constructor.

Parameters
indexThe index object to copy.

◆ ObjectIndex() [3/3]

template<class KeyType , class HashFunc = StdHash<KeyType>>
Murl::ObjectIndex< KeyType, HashFunc >::ObjectIndex ( const ObjectArray< KeyType > &  array)
inline

Constructor taking an array.

Parameters
arrayThe array object to copy.

Member Function Documentation

◆ Add() [1/4]

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType& Murl::ObjectIndex< KeyType, HashFunc >::Add ( KeyType *  key,
UInt32  hash 
)
inline

Add a new allocated item with a precomputed hash value.

The index takes the ownership of the item.

Parameters
keyThe item to add.
hashThe precomputed hash.
Returns
A reference to the added item.

◆ Add() [2/4]

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType& Murl::ObjectIndex< KeyType, HashFunc >::Add ( KeyType *  key)
inline

Add a new allocated item.

The index takes the ownership of the item.

Parameters
keyThe item to add.
Returns
A reference to the added item.

References Murl::ObjectIndex< KeyType, HashFunc >::Add().

◆ Set() [1/4]

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType& Murl::ObjectIndex< KeyType, HashFunc >::Set ( SInt32  index,
KeyType *  key,
UInt32  hash 
)
inline

Replace the item at a specified index using a precomputed hash.

The index takes the ownership of the item.

Parameters
indexThe index to set.
keyThe value to set.
hashThe precomputed hash.
Returns
A reference to the set item.

◆ Set() [2/4]

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType& Murl::ObjectIndex< KeyType, HashFunc >::Set ( SInt32  index,
KeyType *  key 
)
inline

Replace the item at a specified index.

The index takes the ownership of the item.

Parameters
indexThe index to set.
keyThe value to set.
Returns
A reference to the set item.

References Murl::ObjectIndex< KeyType, HashFunc >::Set().

◆ PopDetach()

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType* Murl::ObjectIndex< KeyType, HashFunc >::PopDetach ( )
inline

Removes the item from the top position and giving up ownership.

(!) The client is responsible for deletion of the returned item.

Returns
The pointer to the heap allocated item.

◆ Detach()

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType* Murl::ObjectIndex< KeyType, HashFunc >::Detach ( SInt32  index)
inline

Removes the item at a given position and giving up ownership.

(!) The client is responsible for deletion of the returned item.

Parameters
indexThe zero-based index of the item to remove.
Returns
The pointer to the heap allocated item.

◆ Add() [3/4]

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType& Murl::IndexBase< KeyType, ArrayType, HashFunc >::Add
inline

Add an item with a precomputed hash value.

Parameters
keyThe item to add.
hashThe precomputed hash.
Returns
A reference to the added item.

Referenced by Murl::ObjectIndex< KeyType, HashFunc >::Add().

◆ Add() [4/4]

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType& Murl::IndexBase< KeyType, ArrayType, HashFunc >::Add
inline

Add an item.

Parameters
keyThe item to add.
Returns
A reference to the added item.

◆ Set() [3/4]

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType& Murl::IndexBase< KeyType, ArrayType, HashFunc >::Set
inline

Replace the item at a specified index using a precomputed hash.

Parameters
indexThe index to set.
keyThe value to set.
hashThe precomputed hash.
Returns
A reference to the set item.

Referenced by Murl::ObjectIndex< KeyType, HashFunc >::Set().

◆ Set() [4/4]

template<class KeyType , class HashFunc = StdHash<KeyType>>
KeyType& Murl::IndexBase< KeyType, ArrayType, HashFunc >::Set
inline

Replace the item at a specified index.

Parameters
indexThe index to set.
keyThe value to set.
Returns
A reference to the set item.

The documentation for this class was generated from the following file:
  • murl_object_index.h


Copyright © 2011-2024 Spraylight GmbH.