13 #ifndef __UT_IndexedHashSetImpl__
14 #define __UT_IndexedHashSetImpl__
28 myListSize.relaxedStore(0);
57 exint listsize = src.myList.size();
58 myList.resize(listsize);
59 myListSize.relaxedStore(listsize);
60 myMap.rehash(src.myMap.size());
62 for (
exint id = 0;
id < listsize; ++
id)
64 const T &srckey = src.myList[
id];
65 if (!isValidKey(srckey))
67 invalidateKey(myList[
id]);
74 typename UT_IndexedHashSetTable::const_accessor
a;
75 src.myMap.find(a, srckey);
76 refcount = a->second.getRef();
79 myMap.insert(std::pair<T,IdAndRefCount>(srckey,
IdAndRefCount(
id, refcount)));
82 if (!src.myHoles.empty())
86 myHoles.~UT_IndexedHashSetHoleQueue();
108 *id_store = it.getItemId();
123 typename UT_IndexedHashSetTable::accessor
a;
124 if (myMap.find(a, myList[
id]))
127 if (!a->second.bumpRef(inc))
134 invalidateKey(myList[
id]);
159 typename UT_IndexedHashSetTable::accessor
a;
160 if (myMap.find(a, myList[
id]))
162 return a->second.getRef();
173 typename UT_IndexedHashSetTable::accessor
a;
174 if (myMap.find(a, key))
176 return a->second.getRef();
187 if (myHoles.try_pop(offset))
189 UT_ASSERT(offset >= 0 && offset < myList.size());
194 offset = myList.push_back(key) - myList.begin();
195 myListSize.maximum(offset+1);
206 typename UT_IndexedHashSetTable::accessor
a;
207 if (myMap.insert(a, key))
218 a->second.bumpRef(1);
220 return a->second.getId();
229 typename UT_IndexedHashSetTable::const_accessor
a;
230 if (myMap.find(a, key))
232 id = a->second.getId();
242 typename UT_IndexedHashSetTable::accessor
a;
243 if (myMap.find(a, key))
246 if (!a->second.bumpRef(-1))
253 invalidateKey(myList[
id]);
273 const T &key = myList[
id];
287 if (!isValidId(
id) || !isValidKey(myList[
id]))
290 typename UT_IndexedHashSetTable::accessor
a;
292 const T &okey = myList[
id];
293 if (!myMap.find(a, okey))
295 UT_ASSERT(0 &&
"Missing object that's in the map!");
300 exint irefcount = a->second.getRef();
306 invalidateKey(myList[
id]);
319 if (myMap.insert(a, key))
323 a->second.setRef(irefcount);
325 myList[
id] = a->first;
336 a->second.bumpRef(irefcount);
339 id = a->second.getId();
352 remapping.prepare(n);
356 const T &skey = myList[
s];
357 if (!isValidKey(skey))
360 remapping.setId(
s, d);
364 typename UT_IndexedHashSetTable::accessor
a;
373 myListSize.relaxedStore(myList.size());
383 if (!myHoles.empty())
388 UT_ASSERT(myListSize.relaxedLoad() == myList.size());
389 exint nitems = myListSize.relaxedLoad();
390 std::vector<T> items;
391 items.reserve(nitems);
392 for (
exint i = 0; i < nitems; ++i)
394 items.push_back(myList[i]);
396 std::stable_sort(items.begin(), items.end(), predicate);
398 for (
exint i = 0; i < nitems; ++i)
400 myList[i] = items[i];
401 myMap[items[i]].setId(i);
407 template<
typename ID_ARRAY,
typename T_ARRAY>
412 exint maxitems)
const
417 UT_ASSERT(myListSize.relaxedLoad() == myList.size());
418 exint nitems = myListSize.relaxedLoad();
419 for (
exint i = 0; i < nitems; ++i)
421 if (isValidKey(myList[i]))
427 items.append(myList[i]);
429 if (items.size() >= maxitems)
437 template<
typename ID_ARRAY,
typename T_ARRAY>
441 T_ARRAY &items)
const
443 UT_ASSERT(myListSize.relaxedLoad() == myList.size());
444 exint nitems = myListSize.relaxedLoad();
445 for (
exint i = 0; i < nitems; ++i)
447 if (isValidKey(myList[i]))
453 items.append(myList[i]);
460 template<
typename T_ARRAY>
463 T_ARRAY &items)
const
465 exint nitems = myListSize.relaxedLoad();
466 for (
exint i = 0; i < nitems; ++i)
468 if (isValidKey(myList[i]))
469 items.append(myList[i]);
478 int64 mem = inclusive ?
sizeof(*this) : 0;
480 UT_ASSERT(myListSize.relaxedLoad() == myList.size());
unsafe_listiterator beginList() const
bool sortItems(const P &predicate)
GLboolean GLboolean GLboolean GLboolean a
UT_IndexedHashSetItemId add(const T &key)
exint UT_IndexedHashSetItemId
Each item in the shared map is assigned a unique id.
A thread-safe hash map which stores indexed shared items.
const T * getOrderedItem(exint index, UT_IndexedHashSetItemId *id=nullptr) const
const T * findItemAndId(const T &key, UT_IndexedHashSetItemId &id) const
void replace(const UT_IndexedHashSet &src)
int64 getMemoryUsage(bool inclusive) const
Return approximate memory usage (not including key or item storage)
exint getReferenceCount(UT_IndexedHashSetItemId id) const
int64 UTgetMemoryUsage(const UT_ConcurrentHashMap< K, V, H, A > &map, const bool inclusive)
exint extractItems(ID_ARRAY &ids, T_ARRAY &items, exint maxitems) const
bool remove(const T &key)
bool compactIds(IdRemapping &remapping)
UT_IndexedHashSetItemId replaceItem(UT_IndexedHashSetItemId id, const T &key)
#define UT_VERIFY_P(expr)
UT_ConcurrentQueue< UT_IndexedHashSetItemId > UT_IndexedHashSetHoleQueue
const T * addReference(UT_IndexedHashSetItemId id, int inc)
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool