Urho3D
Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
Urho3D::HashMap< T, U > Class Template Reference

Hash map template class. More...

#include </home/runner/work/urho3d-doxygen.github.io/urho3d-doxygen.github.io/urho3d_repo/Source/Urho3D/Container/HashMap.h>

Inheritance diagram for Urho3D::HashMap< T, U >:
Urho3D::HashBase

Classes

struct  ConstIterator
 Hash map node const iterator. More...
 
struct  Iterator
 Hash map node iterator. More...
 
class  KeyValue
 Hash map key-value pair with const key. More...
 
struct  Node
 Hash map node. More...
 

Public Types

using KeyType = T
 
using ValueType = U
 

Public Member Functions

 HashMap ()
 Construct empty.
 
 HashMap (const HashMap< T, U > &map)
 Construct from another hash map.
 
 HashMap (HashMap< T, U > &&map) noexcept
 Move-construct from another hash map.
 
 HashMap (const std::initializer_list< Pair< T, U > > &list)
 Aggregate initialization constructor.
 
 ~HashMap ()
 Destruct.
 
HashMapoperator= (const HashMap< T, U > &rhs)
 Assign a hash map.
 
HashMapoperator= (HashMap< T, U > &&rhs) noexcept
 Move-assign a hash map.
 
HashMapoperator+= (const Pair< T, U > &rhs)
 Add-assign a pair.
 
HashMapoperator+= (const HashMap< T, U > &rhs)
 Add-assign a hash map.
 
bool operator== (const HashMap< T, U > &rhs) const
 Test for equality with another hash map.
 
bool operator!= (const HashMap< T, U > &rhs) const
 Test for inequality with another hash map.
 
U & operator[] (const T &key)
 Index the map. Create a new pair if key not found.
 
U * operator[] (const T &key) const
 Index the map. Return null if key is not found, does not create a new pair.
 
HashMapPopulate (const T &key, const U &value)
 Populate the map using variadic template. This handles the base case.
 
template<typename... Args>
HashMapPopulate (const T &key, const U &value, const Args &... args)
 Populate the map using variadic template.
 
Iterator Insert (const Pair< T, U > &pair)
 Insert a pair. Return an iterator to it.
 
Iterator Insert (const Pair< T, U > &pair, bool &exists)
 Insert a pair. Return iterator and set exists flag according to whether the key already existed.
 
void Insert (const HashMap< T, U > &map)
 Insert a map.
 
Iterator Insert (const ConstIterator &it)
 Insert a pair by iterator. Return iterator to the value.
 
void Insert (const ConstIterator &start, const ConstIterator &end)
 Insert a range by iterators.
 
bool Erase (const T &key)
 Erase a pair by key. Return true if was found.
 
Iterator Erase (const Iterator &it)
 Erase a pair by iterator. Return iterator to the next pair.
 
void Clear ()
 Clear the map.
 
void Sort ()
 Sort pairs. After sorting the map can be iterated in order until new elements are inserted.
 
bool Rehash (i32 numBuckets)
 Rehash to a specific bucket count, which must be a power of two. Return true if successful.
 
Iterator Find (const T &key)
 Return iterator to the pair with key, or end iterator if not found.
 
ConstIterator Find (const T &key) const
 Return const iterator to the pair with key, or end iterator if not found.
 
bool Contains (const T &key) const
 Return whether contains a pair with key.
 
bool TryGetValue (const T &key, U &out) const
 Try to copy value to output. Return true if was found.
 
Vector< T > Keys () const
 Return all the keys.
 
Vector< U > Values () const
 Return all the values.
 
Iterator Begin ()
 Return iterator to the beginning.
 
ConstIterator Begin () const
 Return iterator to the beginning.
 
Iterator End ()
 Return iterator to the end.
 
ConstIterator End () const
 Return iterator to the end.
 
const KeyValueFront () const
 Return first pair.
 
const KeyValueBack () const
 Return last pair.
 
- Public Member Functions inherited from Urho3D::HashBase
 HashBase ()
 Construct.
 
void Swap (HashBase &rhs)
 Swap with another hash set or map.
 
i32 Size () const
 Return number of elements.
 
i32 NumBuckets () const
 Return number of buckets.
 
bool Empty () const
 Return whether has no elements.
 

Private Member Functions

NodeHead () const
 Return the head node.
 
NodeTail () const
 Return the tail node.
 
NodeFindNode (const T &key, hash32 hashKey) const
 Find a node from the buckets. Do not call if the buckets have not been allocated.
 
NodeFindNode (const T &key, hash32 hashKey, Node *&previous) const
 Find a node and the previous node from the buckets. Do not call if the buckets have not been allocated.
 
NodeInsertNode (const T &key, const U &value, bool findExisting=true)
 Insert a key and value and return either the new or existing node.
 
NodeInsertNode (Node *dest, const T &key, const U &value)
 Insert a node into the list. Return the new node.
 
NodeEraseNode (Node *node)
 Erase a node from the list. Return pointer to the next element, or to the end if could not erase.
 
NodeReserveNode ()
 Reserve a node.
 
NodeReserveNode (const T &key, const U &value)
 Reserve a node with specified key and value.
 
void FreeNode (Node *node)
 Free a node.
 
void Rehash ()
 Rehash the buckets.
 
hash32 Hash (const T &key) const
 Compute a hash based on the key and the bucket size.
 

Static Private Member Functions

static bool CompareNodes (Node *&lhs, Node *&rhs)
 Compare two nodes.
 

Additional Inherited Members

- Static Public Attributes inherited from Urho3D::HashBase
static constexpr i32 MIN_BUCKETS = 8
 Initial amount of buckets.
 
static constexpr i32 MAX_LOAD_FACTOR = 4
 Maximum load factor.
 
- Protected Member Functions inherited from Urho3D::HashBase
void AllocateBuckets (i32 size, i32 numBuckets)
 Allocate bucket head pointers + room for size and bucket count variables.
 
void ResetPtrs ()
 Reset bucket head pointers.
 
void SetSize (i32 size)
 Set new size.
 
HashNodeBase ** Ptrs () const
 Return bucket head pointers.
 
- Protected Attributes inherited from Urho3D::HashBase
HashNodeBasehead_
 List head node pointer.
 
HashNodeBasetail_
 List tail node pointer.
 
HashNodeBase ** ptrs_
 Bucket head pointers.
 
AllocatorBlockallocator_
 Node allocator.
 

Detailed Description

template<class T, class U>
class Urho3D::HashMap< T, U >

Hash map template class.


The documentation for this class was generated from the following file: