About
maxon::HashMap is a generic class template for a map that maps keys to values with the help of hash values. It can use data types as a key that implement a "GetHashCode" and "IsEqual" function. maxon::HashMap is based on maxon::MapBase and maxon::Collection.
Create
A new hash map object can simply be created using the class template:
Definition: hashmap.h:1115
ResultRef< Entry > Insert(KEY &&key, const V &value, Bool &created=BoolLValue())
Definition: hashmap.h:1633
#define iferr_return
Definition: resultbase.h:1531
The data stored in a maxon::HashMap can be cleared with:
Access
An entry in a maxon::HashMap is represented as a maxon::HashMap::Entry object. New entries can be inserted with:
if (created && e)
e->SetValue("Helium"_s);
str = "Lithium"_s;
{
entry.SetValue("Beryllium"_s);
};
if (e)
e->SetValue("Deuterium"_s);
Definition: hashmap.h:1988
Result< Entry * > InsertLambda(KEY &&key, LAMBDA &&lambda, Bool &created=BoolLValue())
Definition: hashmap.h:1614
ResultRef< Entry > InsertMultiEntry(KEY &&key)
Definition: hashmap.h:1680
ResultRef< V > InsertKey(const K &key, Bool &created=BoolLValue())
Definition: hashmap.h:1555
ResultRef< Entry > InsertEntry(const K &key, Bool &created=BoolLValue())
Definition: hashmap.h:1513
Definition: string.h:1287
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:180
return OK
Definition: apibase.h:2771
An entry stored in the maxon::HashMap can be found using the proper key:
if (e)
if (str)
Opt< V & > FindValue(const KEY &key)
Definition: hashmap.h:1367
Entry * Find(const KEY &key)
Definition: hashmap.h:1335
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:170
An entry of the maxon::HashMap can also be deleted:
if (e)
{
}
ResultOk< void > Erase(const Entry *entry, Bool deleteEntry=true)
Definition: hashmap.h:1740
It is easily possible to iterate trough all stored key and values with:
See also Iterate.
for (
const auto& it : atoms.
FindAll(1))
{
const auto value = it.GetValue();
}
KeyIterator GetKeys()
Definition: hashmap.h:2458
MultiEntryIterator< false > FindAll(const K &key)
Definition: hashmap.h:2165
ValueIterator GetValues()
Definition: hashmap.h:2476
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:187
A maxon::HashMap stores a certain number of elements and has a certain capacity to store further elements:
Int GetCount() const
Definition: hashmap.h:1237
Int GetNonEmptyBucketCount() const
Definition: hashmap.h:1275
Int GetTableSize() const
Definition: hashmap.h:1246
Iterate
It is easily to iterate over all entries in the maxon::HashMap:
for (const auto& e : atoms)
{
}
auto e = atoms.Find(1);
if (e)
{
auto it = atoms.GetIterator(e);
++it;
}
V & GetValue()
Definition: hashmap.h:133
decltype(ENTRY_HANDLER::GetKey(*(V *) nullptr) GetKey)() const
Definition: hashmap.h:124
Utility
A maxon::HashMap can easily be copied:
Further utility functions are:
Further Reading