A hash class. More...

#include "murl_hash.h"

Public Member Functions

 Hash ()
 The default constructor. More...
 
 Hash (const Hash &hash)
 The copy constructor. More...
 
Hashoperator= (const Hash &hash)
 The assignment operator. More...
 
 Hash (Hash &&hash) noexcept
 The copy constructor. More...
 
Hashoperator= (Hash &&hash) noexcept
 The assignment operator. More...
 
 ~Hash ()
 The destructor.
 
void Clear ()
 Clear the hash object.
 
void ClearIndex ()
 Clear the index.
 
void Reindex (SInt32 n)
 Clear and rebuild the index for a given number of items. More...
 
void Reindex ()
 Clear and rebuild the index.
 
void Shrink ()
 Shrink the hash object so that the underlying storage is only as large as necessary.
 
Bool Trim (SInt32 n)
 Reduce the hash object to a given number of items. More...
 
Bool Drop (SInt32 n)
 Reduce the hash object by removing a given number of items from the end. More...
 
void Reserve (SInt32 n)
 Reserve storage space. More...
 
Bool Unlink (SInt32 index)
 Unlink a given index. More...
 
Bool IsUnlinked (SInt32 index) const
 Check if the given index is unlinked. More...
 
Bool HasUnlinked () const
 Check if the hash has unlinked entries. More...
 
SInt32Array GetUnlinked () const
 Get an array of unlinked indices. More...
 
void Set (SInt32 index, UInt32 hash)
 Replace the index for a specified hash value. More...
 
void SetUn (SInt32 index, UInt32 hash)
 Replace the hash value at a specified index without consideration of multiple entries per hash value. More...
 
void Add (UInt32 hash)
 Add a hash value. More...
 
SInt32 Put (UInt32 hash)
 Put a hash value by replacing an unlinked index if present. More...
 
void Insert (SInt32 index, UInt32 hash)
 Insert an index for a given hash value. More...
 
void Remove (SInt32 index)
 Remove the hash value at a given position. More...
 
void Remove (SInt32 index, SInt32 count)
 Remove a number of hash values at a given starting position. More...
 
void Remove (const SInt32 *sortedIndices, SInt32 count)
 Remove a number of hash values at given positions. More...
 
SInt32 Find (UInt32 hash) const
 Find the first index of a given hash value. More...
 
SInt32 FindNext (SInt32 index) const
 Find the next occurrence of a hash value that is specified by a given index. More...
 
SInt32 FindPrev (SInt32 index) const
 Find the previous occurrence of a hash value that is specified by a given index. More...
 
SInt32 FindLast (UInt32 hash) const
 Find the last occurrence of a hash value. More...
 
UInt32 operator[] (SInt32 index) const
 Get the hash value for a given index. More...
 
SInt32 GetCount () const
 Get the number of items. More...
 
void Swap (Hash &other)
 Exchange the content of the hash object with a given second one. More...
 

Detailed Description

A hash class.

The hash class stores indices accessible by a hash value.
This class is based on the NTL Hash container, see http://www.ultimatepp.org

Constructor & Destructor Documentation

◆ Hash() [1/3]

Murl::Hash::Hash ( )
inline

The default constructor.

Create an empty hash object.

◆ Hash() [2/3]

Murl::Hash::Hash ( const Hash hash)
inline

The copy constructor.

Parameters
hashThe hash object to copy.

References Reindex().

◆ Hash() [3/3]

Murl::Hash::Hash ( Hash &&  hash)
inlinenoexcept

The copy constructor.

Parameters
hashThe hash object to copy.

References Swap().

Member Function Documentation

◆ operator=() [1/2]

Hash& Murl::Hash::operator= ( const Hash hash)
inline

The assignment operator.

Parameters
hashThe hash object to copy.
Returns
A reference to this hash object.

References Reindex().

◆ operator=() [2/2]

Hash& Murl::Hash::operator= ( Hash &&  hash)
inlinenoexcept

The assignment operator.

Parameters
hashThe hash object to copy.
Returns
A reference to this hash object.

References Swap().

◆ Reindex()

void Murl::Hash::Reindex ( SInt32  n)
inline

Clear and rebuild the index for a given number of items.

Parameters
nThe number of items to rebuild.

References ClearIndex(), Murl::Array< DataType >::Empty(), and Murl::Util::Fill().

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::RebuildHash().

◆ Trim()

Bool Murl::Hash::Trim ( SInt32  n)
inline

Reduce the hash object to a given number of items.

Parameters
nThe new number of items in the hash object, must be smaller than the current item count.
Returns
true if successful.

Referenced by Drop(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::Empty(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Trim().

◆ Drop()

Bool Murl::Hash::Drop ( SInt32  n)
inline

Reduce the hash object by removing a given number of items from the end.

Parameters
nThe number of items to remove from the end.
Returns
true if successful.

References Murl::Array< DataType >::GetCount(), and Trim().

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Drop().

◆ Reserve()

void Murl::Hash::Reserve ( SInt32  n)
inline

Reserve storage space.

If the given size is less than the actual size, nothing is done.

Parameters
nThe number of items the underlying storage should hold.

References Reindex(), and Murl::Array< DataType >::Reserve().

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Reserve().

◆ Unlink()

Bool Murl::Hash::Unlink ( SInt32  index)
inline

Unlink a given index.

Unlinked items remain in the hash object, but are ignored by any search operations.

Parameters
indexThe index to unlink.
Returns
true if successful.

Referenced by Set(), SetUn(), Murl::IndexBase< KeyType, ArrayType, HashFunc >::Unlink(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::UnlinkKey().

◆ IsUnlinked()

Bool Murl::Hash::IsUnlinked ( SInt32  index) const
inline

Check if the given index is unlinked.

Parameters
indexThe index to check.
Returns
true if the specified item is unlinked.

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::IsUnlinked().

◆ HasUnlinked()

Bool Murl::Hash::HasUnlinked ( ) const
inline

Check if the hash has unlinked entries.

Returns
true if there is at least one unlinked entry.

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::HasUnlinked(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Sweep().

◆ GetUnlinked()

SInt32Array Murl::Hash::GetUnlinked ( ) const
inline

Get an array of unlinked indices.

Returns
The array of indices.

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::GetUnlinked(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Sweep().

◆ Set()

void Murl::Hash::Set ( SInt32  index,
UInt32  hash 
)
inline

Replace the index for a specified hash value.

Parameters
indexThe index to set.
hashThe hash value to set.

References Unlink().

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

◆ SetUn()

void Murl::Hash::SetUn ( SInt32  index,
UInt32  hash 
)
inline

Replace the hash value at a specified index without consideration of multiple entries per hash value.

Parameters
indexThe index to set.
hashThe hash value to set.

References Unlink().

◆ Add()

void Murl::Hash::Add ( UInt32  hash)
inline

Add a hash value.

Parameters
hashThe hash value to add.

References Murl::Array< DataType >::Add().

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

◆ Put()

SInt32 Murl::Hash::Put ( UInt32  hash)
inline

Put a hash value by replacing an unlinked index if present.

Parameters
hashThe hash value to add.
Returns
The index of the hash value or -1 if no unlinked index is available.

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Put().

◆ Insert()

void Murl::Hash::Insert ( SInt32  index,
UInt32  hash 
)
inline

Insert an index for a given hash value.

Parameters
indexThe index to insert.
hashThe hash value to insert.

References ClearIndex(), Murl::Array< DataType >::Insert(), and Reindex().

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Insert().

◆ Remove() [1/3]

void Murl::Hash::Remove ( SInt32  index)
inline

Remove the hash value at a given position.

Parameters
indexThe index from where to remove the hash value.

References ClearIndex(), Reindex(), and Murl::Array< DataType >::Remove().

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Remove().

◆ Remove() [2/3]

void Murl::Hash::Remove ( SInt32  index,
SInt32  count 
)
inline

Remove a number of hash values at a given starting position.

Parameters
indexThe index from where to start removing the hash values.
countThe number of subsequent hash values to remove.

References ClearIndex(), Reindex(), and Murl::Array< DataType >::Remove().

◆ Remove() [3/3]

void Murl::Hash::Remove ( const SInt32 sortedIndices,
SInt32  count 
)
inline

Remove a number of hash values at given positions.

Parameters
sortedIndicesA pointer to sorted indices where to remove the hash values.
countThe number of hash values to remove, i.e. the number of indices.

References ClearIndex(), Reindex(), and Murl::Array< DataType >::Remove().

◆ Find()

SInt32 Murl::Hash::Find ( UInt32  hash) const
inline

Find the first index of a given hash value.

Parameters
hashThe hash value to search for.
Returns
The index of the hash value, or -1 if not found.

References Murl::Array< DataType >::GetCount().

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::Find(), FindLast(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::UnlinkKey().

◆ FindNext()

SInt32 Murl::Hash::FindNext ( SInt32  index) const
inline

Find the next occurrence of a hash value that is specified by a given index.

Parameters
indexThe index of the hash value to search for.
Returns
The index of the next hash value, or -1 if not found.

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindNext(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::UnlinkKey().

◆ FindPrev()

SInt32 Murl::Hash::FindPrev ( SInt32  index) const
inline

Find the previous occurrence of a hash value that is specified by a given index.

Parameters
indexThe index of the hash value to search for.
Returns
The index of the previous hash value, or -1 if not found.

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindPrev().

◆ FindLast()

SInt32 Murl::Hash::FindLast ( UInt32  hash) const
inline

Find the last occurrence of a hash value.

Parameters
hashThe hash value to search for.
Returns
The index of the item, or -1 if not found.

References Find(), and Murl::Array< DataType >::GetCount().

Referenced by Murl::IndexBase< KeyType, ArrayType, HashFunc >::FindLast().

◆ operator[]()

UInt32 Murl::Hash::operator[] ( SInt32  index) const
inline

Get the hash value for a given index.

If the index is out of range, the behaviour is undefined.

Parameters
indexThe index of the hash value to retrieve.
Returns
The hash value of the requested index.

◆ GetCount()

SInt32 Murl::Hash::GetCount ( ) const
inline

Get the number of items.

Returns
The number of items.

References Murl::Array< DataType >::GetCount().

◆ Swap()

void Murl::Hash::Swap ( Hash other)
inline

Exchange the content of the hash object with a given second one.

Parameters
otherThe second hash object.

References Murl::Array< DataType >::Swap(), and Murl::Util::Swap().

Referenced by Hash(), operator=(), and Murl::IndexBase< KeyType, ArrayType, HashFunc >::Swap().


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


Copyright © 2011-2024 Spraylight GmbH.