13 #ifndef __UT_IndexedHashSetImpl__
14 #define __UT_IndexedHashSetImpl__
28 myListSize.relaxedStore(0);
53 myListSize.relaxedStore(myList.size());
55 myHoles = src.myHoles;
75 *id_store = it.getItemId();
90 typename UT_IndexedHashSetTable::accessor
a;
91 if (myMap.find(a, myList[
id]))
94 if (!a->second.bumpRef(inc))
101 invalidateKey(myList[
id]);
126 typename UT_IndexedHashSetTable::accessor
a;
127 if (myMap.find(a, myList[
id]))
129 return a->second.getRef();
140 typename UT_IndexedHashSetTable::accessor
a;
141 if (myMap.find(a, key))
143 return a->second.getRef();
154 if (myHoles.try_pop(offset))
156 UT_ASSERT(offset >= 0 && offset < myList.size());
161 offset = myList.push_back(key) - myList.begin();
162 myListSize.maximum(offset+1);
173 typename UT_IndexedHashSetTable::accessor
a;
174 if (myMap.insert(a, key))
185 a->second.bumpRef(1);
187 return a->second.getId();
196 typename UT_IndexedHashSetTable::const_accessor
a;
197 if (myMap.find(a, key))
199 id = a->second.getId();
209 typename UT_IndexedHashSetTable::accessor
a;
210 if (myMap.find(a, key))
213 if (!a->second.bumpRef(-1))
220 invalidateKey(myList[
id]);
240 const T &key = myList[
id];
254 if (!isValidId(
id) || !isValidKey(myList[
id]))
257 typename UT_IndexedHashSetTable::accessor
a;
259 const T &okey = myList[
id];
260 if (!myMap.find(a, okey))
262 UT_ASSERT(0 &&
"Missing object that's in the map!");
267 exint irefcount = a->second.getRef();
273 invalidateKey(myList[
id]);
286 if (myMap.insert(a, key))
290 a->second.setRef(irefcount);
292 myList[
id] = a->first;
303 a->second.bumpRef(irefcount);
306 id = a->second.getId();
319 remapping.prepare(n);
323 const T &skey = myList[
s];
324 if (!isValidKey(skey))
327 remapping.setId(
s, d);
331 typename UT_IndexedHashSetTable::accessor
a;
340 myListSize.relaxedStore(myList.size());
350 if (!myHoles.empty())
355 UT_ASSERT(myListSize.relaxedLoad() == myList.size());
356 exint nitems = myListSize.relaxedLoad();
357 std::vector<T> items;
358 items.reserve(nitems);
359 for (
exint i = 0; i < nitems; ++i)
361 items.push_back(myList[i]);
363 std::stable_sort(items.begin(), items.end(), predicate);
365 for (
exint i = 0; i < nitems; ++i)
367 myList[i] = items[i];
368 myMap[items[i]].setId(i);
374 template<
typename ID_ARRAY,
typename T_ARRAY>
379 exint maxitems)
const
384 UT_ASSERT(myListSize.relaxedLoad() == myList.size());
385 exint nitems = myListSize.relaxedLoad();
386 for (
exint i = 0; i < nitems; ++i)
388 if (isValidKey(myList[i]))
394 items.append(myList[i]);
396 if (items.size() >= maxitems)
404 template<
typename ID_ARRAY,
typename T_ARRAY>
408 T_ARRAY &items)
const
410 UT_ASSERT(myListSize.relaxedLoad() == myList.size());
411 exint nitems = myListSize.relaxedLoad();
412 for (
exint i = 0; i < nitems; ++i)
414 if (isValidKey(myList[i]))
420 items.append(myList[i]);
427 template<
typename T_ARRAY>
430 T_ARRAY &items)
const
432 exint nitems = myListSize.relaxedLoad();
433 for (
exint i = 0; i < nitems; ++i)
435 if (isValidKey(myList[i]))
436 items.append(myList[i]);
445 int64 mem = inclusive ?
sizeof(*this) : 0;
447 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.
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
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)
const T * addReference(UT_IndexedHashSetItemId id, int inc)