11 #ifndef __UT_IndexedHashMap__
12 #define __UT_IndexedHashMap__
88 bool empty()
const {
return myMap.empty(); }
91 int64 getMemoryUsage(
bool inclusive)
const;
98 {
return SYSmax(1, getListSize())-1; }
105 exint lsize = getListSize();
106 exint hsize = myHoles.unsafe_size();
107 if (!lsize || !hsize)
127 if (prev >= 0 && prev < myIdMap.entries())
128 return myIdMap(prev);
135 myIdMap.entries(size);
136 myIdMap.constant(-1);
142 myIdMap(prev) = curr;
152 bool compactIds(IdRemapping &remapping);
169 InternalItemT *_add(
const InternalKeyT *key,
170 InternalItemT *item=NULL,
174 {
return _addReference(
id, 1); }
179 return _findItemAndId(key,
id);
184 if (!_findItemAndId(key, hid))
188 InternalItemT *_findItemAndId(
const InternalKeyT *key,
194 bool _remove(
const InternalKeyT *key);
197 const InternalKeyT *key,
198 InternalItemT *new_item=NULL);
230 myMap.deleteItem(myItem);
266 , myKey(src.myKey ? src.myMap.copyKey(src.myKey) : NULL)
272 myMap.deleteKey(const_cast<InternalKeyT *>(myKey));
277 if (myKey != src.myKey)
280 myMap.deleteKey(const_cast<InternalKeyT *>(myKey));
283 src.myMap.
copyKey(src.myKey) : NULL;
295 return myMap.hash(myKey);
300 return myMap.areKeysEqual(myKey, b.myKey);
334 return myItem ? myItem->getItem() : NULL;
341 {
return myItem ? myItem->getRef() : -1; }
380 typedef UT_ConcurrentHashMap<keyContainer, itemContainer *, keyCompare>
383 typedef UT_ConcurrentQueue<UT_IndexedHashMapItemId>
401 {
return myIterator->getKey(); }
403 {
return myIterator->getItem(); }
405 {
return myIterator->getId(); }
406 exint getItemShareCount()
const
407 {
return myIterator->getRef(); }
408 template <
typename T>
const T *keyAs()
const
409 {
return static_cast<const T *
>(getKey()); }
410 template <
typename T>
const T *itemAs()
const
411 {
return static_cast<const T *
>(getItem()); }
416 bool atEnd()
const {
return myCurr >= mySize; }
423 }
while (myCurr < mySize && !myIterator->isValid());
425 unsafe_listiterator &operator++() { advance();
return *
this; }
426 bool operator==(
const unsafe_listiterator &it)
const
428 if (atEnd() && it.atEnd())
430 return myMap == it.myMap &&
431 mySize == it.mySize &&
434 bool operator!=(
const unsafe_listiterator &it)
435 {
return !(*
this == it); }
440 , myIterator(map.myList.begin())
446 UT_IndexedHashMapVector::const_iterator myIterator;
447 exint mySize, myCurr;
464 {
return myIterator->first.getKey(); }
466 {
return myIterator->second->getItem(); }
468 {
return myMap->_findId(getKey()); }
470 {
return myIterator->second->getRef();}
472 template <
typename T>
const T *
keyAs()
const
473 {
return static_cast<const T *
>(getKey()); }
475 {
return static_cast<const T *
>(getItem()); }
480 bool atEnd()
const {
return myCurr >= mySize; }
487 myIterator != myMap->myMap.end());
493 if (atEnd() && it.
atEnd())
495 return myMap == it.myMap &&
496 mySize == it.mySize &&
500 {
return !(*
this == it); }
505 , myIterator(map.myMap.
begin())
507 , mySize(map.entries())
511 UT_IndexedHashMapTable::const_iterator myIterator;
512 exint mySize, myCurr;
528 int getListSize()
const
529 {
return myListSize.relaxedLoad(); }
531 {
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
unsafe_iterator end() const
bool operator==(const unsafe_iterator &it) const
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
static uint hash(const keyContainer &key)
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.
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)
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
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.