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>
397 unsafe_listiterator(
const unsafe_listiterator &
src)
399 , myIterator(src.myIterator)
403 ~unsafe_listiterator()
409 {
return myIterator->getKey(); }
411 {
return myIterator->getItem(); }
413 {
return myIterator->getId(); }
414 exint getItemShareCount()
const
415 {
return myIterator->getRef(); }
416 template <
typename T>
const T *keyAs()
const
417 {
return static_cast<const T *
>(getKey()); }
418 template <
typename T>
const T *itemAs()
const
419 {
return static_cast<const T *
>(getItem()); }
424 bool atEnd()
const {
return myCurr >= mySize; }
431 }
while (myCurr < mySize && !myIterator->isValid());
433 unsafe_listiterator &operator++() { advance();
return *
this; }
434 bool operator==(
const unsafe_listiterator &it)
const
436 if (atEnd() && it.atEnd())
438 return myMap == it.myMap &&
439 mySize == it.mySize &&
442 bool operator!=(
const unsafe_listiterator &it)
443 {
return !(*
this == it); }
448 , myIterator(map.myList.begin())
454 UT_IndexedHashMapVector::const_iterator myIterator;
455 exint mySize, myCurr;
470 , myIterator(src.myIterator)
479 myIterator = src.myIterator;
488 {
return myIterator->first.getKey(); }
490 {
return myIterator->second->getItem(); }
492 {
return myMap->_findId(getKey()); }
494 {
return myIterator->second->getRef();}
496 template <
typename T>
const T *
keyAs()
const
497 {
return static_cast<const T *
>(getKey()); }
499 {
return static_cast<const T *
>(getItem()); }
504 bool atEnd()
const {
return myCurr >= mySize; }
511 myIterator != myMap->myMap.end());
517 if (atEnd() && it.
atEnd())
519 return myMap == it.myMap &&
520 mySize == it.mySize &&
524 {
return !(*
this == it); }
529 , myIterator(map.myMap.
begin())
531 , mySize(map.entries())
535 UT_IndexedHashMapTable::const_iterator myIterator;
536 exint mySize, myCurr;
552 int getListSize()
const
553 {
return myListSize.relaxedLoad(); }
555 {
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
FMT_CONSTEXPR auto begin(const C &c) -> decltype(c.begin())
keyContainer(const keyContainer &src)
itemCompare(const UT_IndexedHashMap &map)
unsafe_iterator & operator++()
static bool equal(const keyContainer &a, const keyContainer &b)
GLboolean GLboolean GLboolean GLboolean a
keyContainer(const UT_IndexedHashMap &map, const InternalKeyT *key)
unsafe_iterator begin() const
Iterate over items in the map - this is arbitrary order.
InternalItemT * getItem() const
unsafe_iterator end() const
unsafe_iterator & operator=(const unsafe_iterator &src)
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
unsafe_iterator(const unsafe_iterator &src)
virtual InternalKeyT * copyKey(const InternalKeyT *key) const =0
listContainer(const listContainer &src)
const InternalKeyT * getKey() const
GLdouble GLdouble GLdouble b
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