11 #ifndef __UT_IndexedHashMap__
12 #define __UT_IndexedHashMap__
89 bool empty()
const {
return myMap.empty(); }
92 int64 getMemoryUsage(
bool inclusive)
const;
99 {
return SYSmax(1, getListSize())-1; }
106 exint lsize = getListSize();
107 exint hsize = myHoles.unsafe_size();
108 if (!lsize || !hsize)
129 if (prev >= 0 && prev < myIdMap.entries())
130 return myIdMap(prev);
137 myIdMap.entries(size);
138 myIdMap.constant(-1);
144 myIdMap(prev) = curr;
154 bool compactIds(IdRemapping &remapping);
171 InternalItemT *_add(
const InternalKeyT *key,
172 InternalItemT *item=NULL,
176 {
return _addReference(
id, 1); }
181 return _findItemAndId(key,
id);
186 if (!_findItemAndId(key, hid))
190 InternalItemT *_findItemAndId(
const InternalKeyT *key,
196 bool _remove(
const InternalKeyT *key);
199 const InternalKeyT *key,
200 InternalItemT *new_item=NULL);
232 myMap.deleteItem(myItem);
268 , myKey(src.myKey ? src.myMap.copyKey(src.myKey) : NULL)
274 myMap.deleteKey(const_cast<InternalKeyT *>(myKey));
279 if (myKey != src.myKey)
282 myMap.deleteKey(const_cast<InternalKeyT *>(myKey));
285 src.myMap.
copyKey(src.myKey) : NULL;
297 return myMap.hash(myKey);
302 return myMap.areKeysEqual(myKey, b.myKey);
336 return myItem ? myItem->getItem() : NULL;
343 {
return myItem ? myItem->getRef() : -1; }
385 typedef UT_ConcurrentQueue<UT_IndexedHashMapItemId>
403 {
return myIterator->getKey(); }
405 {
return myIterator->getItem(); }
407 {
return myIterator->getId(); }
408 exint getItemShareCount()
const
409 {
return myIterator->getRef(); }
410 template <
typename T>
const T *keyAs()
const
411 {
return static_cast<const T *
>(getKey()); }
412 template <
typename T>
const T *itemAs()
const
413 {
return static_cast<const T *
>(getItem()); }
418 bool atEnd()
const {
return myCurr >= mySize; }
425 }
while (myCurr < mySize && !myIterator->isValid());
427 unsafe_listiterator &operator++() { advance();
return *
this; }
428 bool operator==(
const unsafe_listiterator &it)
const
430 if (atEnd() && it.atEnd())
432 return myMap == it.myMap &&
433 mySize == it.mySize &&
436 bool operator!=(
const unsafe_listiterator &it)
437 {
return !(*
this == it); }
442 , myIterator(map.myList.begin())
448 UT_IndexedHashMapVector::const_iterator myIterator;
449 exint mySize, myCurr;
466 {
return myIterator->first.getKey(); }
468 {
return myIterator->second->getItem(); }
470 {
return myMap->_findId(getKey()); }
472 {
return myIterator->second->getRef();}
474 template <
typename T>
const T *
keyAs()
const
475 {
return static_cast<const T *
>(getKey()); }
477 {
return static_cast<const T *
>(getItem()); }
482 bool atEnd()
const {
return myCurr >= mySize; }
489 myIterator != myMap->myMap.end());
495 if (atEnd() && it.
atEnd())
497 return myMap == it.myMap &&
498 mySize == it.mySize &&
502 {
return !(*
this == it); }
507 , myIterator(map.myMap.
begin())
509 , mySize(map.entries())
513 UT_IndexedHashMapTable::const_iterator myIterator;
514 exint mySize, myCurr;
530 int getListSize()
const
531 {
return myListSize.relaxedLoad(); }
533 {
return id >= 0 &&
id < getListSize(); }
bool operator()(const listContainer &a, const listContainer &b) const
fpreal getOccupancy() const
bool empty() const
Return whether the map is empty.
exint getItemShareCount() const
UT_IndexedHashMapItemId getItemIdUpperBound() const
keyContainer(const keyContainer &src)
itemCompare(const UT_IndexedHashMap &map)
unsafe_iterator & operator++()
static bool equal(const keyContainer &a, const keyContainer &b)
keyContainer(const UT_IndexedHashMap &map, const InternalKeyT *key)
unsafe_iterator begin() const
GLboolean GLboolean GLboolean GLboolean a
Iterate over items in the map - this is arbitrary order.
InternalItemT * getItem() const
static size_t hash(const keyContainer &key)
unsafe_iterator end() const
bool operator==(const unsafe_iterator &it) const
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
UT_IndexedHashMapItemId newId(UT_IndexedHashMapItemId prev) const
Query the new id associated with the previous id.
itemContainer(const UT_IndexedHashMap &map, InternalItemT *item, exint id)
const InternalKeyT * getKey() const
exint entries() const
Find the number of entries in the map.
tbb::concurrent_hash_map< K, T, H, A > UT_ConcurrentHashMap
bool isEqual(const keyContainer &b) const
exint _findId(const InternalKeyT *key) const
GLboolean GLboolean GLboolean b
virtual InternalKeyT * copyKey(const InternalKeyT *key) const =0
listContainer(const listContainer &src)
const InternalKeyT * getKey() const
const InternalKeyT * getKey() const
InternalItemT * _addReference(UT_IndexedHashMapItemId id)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
UT_ConcurrentQueue< UT_IndexedHashMapItemId > UT_IndexedHashMapHoleQueue
listContainer & operator=(const listContainer &src)
bool operator!=(const unsafe_iterator &it)
unsafe_listiterator endList() const
itemContainer * getItemContainer()
A thread-safe hash map which stores indexed shared items.
friend class itemContainer
InternalItemT * getItem() const
unsafe_listiterator beginList() const
UT_ConcurrentVector< listContainer > UT_IndexedHashMapVector
keyContainer & operator=(const keyContainer &src)
listContainer(itemContainer *i, const InternalKeyT *k)
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
UT_IndexedHashMapItemId getItemId() const
InternalItemT * _find(const InternalKeyT *key) const
UT_ConcurrentHashMap< keyContainer, itemContainer *, keyCompare > UT_IndexedHashMapTable
int UT_IndexedHashMapItemId
Each item in the shared map is assigned a unique id.
InternalItemT * getItem() const