7#include "MRPch/MRBindingMacros.h"
20template <
typename K,
typename V>
32template <
typename K,
typename V>
38 std::variant<Dense, Hash>
var;
48 void resizeReserve(
size_t denseTotalSize,
size_t hashAdditionalCapacity );
72template <
typename K,
typename V>
80template <
typename K,
typename V>
86 hmap.reserve( capacity );
87 res.
var = std::move( hmap );
91template <
typename K,
typename V>
95 [denseTotalSize](
Dense& map ) { map.resize( denseTotalSize ); },
96 [hashAdditionalCapacity](
Hash& hashMap ) { hashMap.reserve( hashMap.size() + hashAdditionalCapacity ); }
100template <
typename K,
typename V>
104 [=](
Dense& map ) { assert( key == map.endId() ); map.push_back( val ); },
105 [=](
Hash& hashMap ) { hashMap[key] = val; }
109template <
typename K,
typename V>
114 [&f](
const Dense& map )
116 for ( K key( 0 ); key < map.size(); ++key )
117 if (
auto val = map[key] )
120 [&f](
const Hash& hashMap )
122 for (
const auto & [ key, val ] : hashMap )
128template <
typename K,
typename V>
133 [&f](
const Dense& map )
137 if (
auto val = map[key] )
141 [&f](
const Hash& hashMap )
144 auto firstFullFrom = [&hashMap] (
size_t slot )
148 tbb::parallel_for( tbb::blocked_range<size_t>( 0, hashMap.capacity() ), [&] (
const tbb::blocked_range<size_t>& range )
150 for ( auto it = firstFullFrom( range.begin() ), last = firstFullFrom( range.end() ); it != last; ++it )
151 f( it->first, it->second );
157template <
typename K,
typename V>
161 [](
Dense& map ) { map.clear(); },
162 [](
Hash& hashMap ) { hashMap.clear(); }
166template <
typename K,
typename V>
170 [key, def](
const Vector<V, K>& map ) {
return getAt( map, key, def ); },
175template <
typename K,
typename V>
#define MR_LIFETIMEBOUND
Definition MRMacros.h:86
#define MR_LIFETIME_CAPTURE_BY_NESTED(x)
Definition MRMacros.h:91
Vector<T> is indexed by size_t.
Definition MRVector.h:24
auto ParallelFor(I begin, I end, F &&f, Cb &&... cb)
Definition MRParallelFor.h:30
void setMap(Dense &&m MR_LIFETIME_CAPTURE_BY_NESTED(this))
Definition MRMapOrHashMap.h:43
Dense * getMap()
Definition MRMapOrHashMap.h:63
void forEachParallel(F &&f) const
Definition MRMapOrHashMap.h:130
std::variant< Dense, Hash > var
Definition MRMapOrHashMap.h:38
const Hash * getHashMap() const
Definition MRMapOrHashMap.h:67
static MapOrHashMap createMap(size_t size=0)
Definition MRMapOrHashMap.h:73
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:59
Hash * getHashMap()
Definition MRMapOrHashMap.h:66
T getAt(const Buffer< T, I > &bmap, 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:140
static constexpr IteratorAt iteratorAt
Definition MRMapOrHashMap.h:24
void pushBack(K key MR_LIFETIME_CAPTURE_BY_NESTED(this), V val MR_LIFETIME_CAPTURE_BY_NESTED(this))
Definition MRMapOrHashMap.h:101
void resizeReserve(size_t denseTotalSize, size_t hashAdditionalCapacity)
Definition MRMapOrHashMap.h:92
overloaded(Ts...) -> overloaded< Ts... >
explicit deduction guide (not needed as of C++20, but still needed in Clang)
const Dense * getMap() const
Definition MRMapOrHashMap.h:64
void forEach(F &&f) const
executes given function for all pairs (key, value) with valid value for dense map
Definition MRMapOrHashMap.h:111
typename HashMap< K, V >::const_iterator(HashMap< K, V >::*)(size_t) const IteratorAt
Definition MRMapOrHashMap.h:23
HashMap< K, V > Hash
Definition MRMapOrHashMap.h:36
phmap::flat_hash_map< K, V, Hash, Eq, Allocator< std::pair< const K, V > > > HashMap
Definition MRMeshFwd.h:632
void clear()
Definition MRMapOrHashMap.h:158
Vector< V, K > Dense
Definition MRMapOrHashMap.h:35
void setAt(MapOrHashMap< K, V > &m, K key, V val)
Definition MRMapOrHashMap.h:176
void setHashMap(Hash &&m MR_LIFETIME_CAPTURE_BY_NESTED(this))
Definition MRMapOrHashMap.h:44
static MapOrHashMap createHashMap(size_t capacity=0)
Definition MRMapOrHashMap.h:81
for internal use: namespace detail is not bound to other languages
Definition MRFastInt.h:19
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRMapOrHashMap.h:34
phmap has no public access to a slot of a hash table by its index: take its protected iterator_at() v...
Definition MRMapOrHashMap.h:22
Definition MRMeshFwd.h:822