17template <
typename K,
typename V>
21 using Hash = HashMap<K, V>;
23 std::variant<Dense, Hash>
var;
33 void resizeReserve(
size_t denseTotalSize,
size_t hashAdditionalCapacity );
52template <
typename K,
typename V>
60template <
typename K,
typename V>
66 hmap.reserve( capacity );
67 res.
var = std::move( hmap );
71template <
typename K,
typename V>
74 std::visit( overloaded{
75 [denseTotalSize](
Dense& map ) { map.resize( denseTotalSize ); },
76 [hashAdditionalCapacity](
Hash& hashMap ) { hashMap.reserve( hashMap.size() + hashAdditionalCapacity ); }
80template <
typename K,
typename V>
83 std::visit( overloaded{
84 [=](
Dense& map ) { assert( key == map.endId() ); map.push_back( val ); },
85 [=](
Hash& hashMap ) { hashMap[key] = val; }
89template <
typename K,
typename V>
93 std::visit( overloaded{
94 [&f](
const Dense& map )
96 for ( K key( 0 ); key < map.size(); ++key )
97 if (
auto val = map[key] )
100 [&f](
const Hash& hashMap )
102 for (
const auto & [ key, val ] : hashMap )
108template <
typename K,
typename V>
111 std::visit( overloaded{
112 [](
Dense& map ) { map.clear(); },
113 [](
Hash& hashMap ) { hashMap.clear(); }
117template <
typename K,
typename V>
120 return std::visit( overloaded{
121 [key, def](
const Vector<V, K>& map ) {
return getAt( map, key, def ); },
122 [key, def](
const HashMap<K, V>& hashMap ) {
return getAt( hashMap, key, def ); }
126template <
typename K,
typename V>
129 std::visit( overloaded{
131 [key, val]( HashMap<K, V>& hashMap ) { hashMap[key] = val; }
#define MR_LIFETIMEBOUND
Definition MRMacros.h:81
#define MR_LIFETIME_CAPTURE_BY_NESTED(x)
Definition MRMacros.h:86
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:23
void setMap(Dense &&m MR_LIFETIME_CAPTURE_BY_NESTED(this))
Definition MRMapOrHashMap.h:28
const Hash * getHashMap() const MR_LIFETIMEBOUND
Definition MRMapOrHashMap.h:47
std::variant< Dense, Hash > var
default construction will select dense map
Definition MRMapOrHashMap.h:23
static MapOrHashMap createMap(size_t size=0)
Definition MRMapOrHashMap.h:53
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
void pushBack(K key MR_LIFETIME_CAPTURE_BY_NESTED(this), V val MR_LIFETIME_CAPTURE_BY_NESTED(this))
Definition MRMapOrHashMap.h:81
Dense * getMap() MR_LIFETIMEBOUND
Definition MRMapOrHashMap.h:43
T getAt(const Buffer< T, I > &bmap MR_LIFETIMEBOUND_NESTED, I key, T def={})
given some buffer map and a key, returns the value associated with the key, or default value if key i...
Definition MRBuffer.h:123
void resizeReserve(size_t denseTotalSize, size_t hashAdditionalCapacity)
Definition MRMapOrHashMap.h:72
void forEach(F &&f) const
executes given function for all pairs (key, value) with valid value for dense map
Definition MRMapOrHashMap.h:91
HashMap< K, V > Hash
Definition MRMapOrHashMap.h:21
void clear()
Definition MRMapOrHashMap.h:109
const Dense * getMap() const MR_LIFETIMEBOUND
Definition MRMapOrHashMap.h:44
Hash * getHashMap() MR_LIFETIMEBOUND
Definition MRMapOrHashMap.h:46
void setAt(MapOrHashMap< K, V > &m, K key, V val)
Definition MRMapOrHashMap.h:127
void setHashMap(Hash &&m MR_LIFETIME_CAPTURE_BY_NESTED(this))
Definition MRMapOrHashMap.h:29
static MapOrHashMap createHashMap(size_t capacity=0)
Definition MRMapOrHashMap.h:61
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMapOrHashMap.h:19