HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_IndexedHashSet< T > Class Template Reference

A thread-safe hash map which stores indexed shared items. More...

#include <UT_IndexedHashSet.h>

Classes

class  IdAndRefCount
 
class  IdRemapping
 
class  unsafe_iterator
 Iterate over items in the map - this is arbitrary order. More...
 
class  unsafe_listiterator
 

Public Types

typedef UT_ConcurrentHashMap
< T, IdAndRefCount
UT_IndexedHashSetTable
 
typedef UT_ConcurrentVector< TUT_IndexedHashSetVector
 
typedef UT_ConcurrentQueue
< UT_IndexedHashSetItemId
UT_IndexedHashSetHoleQueue
 

Public Member Functions

 UT_IndexedHashSet ()
 
 ~UT_IndexedHashSet ()
 
void clear ()
 
exint entries () const
 
bool empty () const
 Return whether the map is empty. More...
 
int64 getMemoryUsage (bool inclusive) const
 Return approximate memory usage (not including key or item storage) More...
 
UT_IndexedHashSetItemId getItemIdUpperBound () const
 
fpreal getOccupancy () const
 
bool compactIds (IdRemapping &remapping)
 
template<typename P >
bool sortItems (const P &predicate)
 
exint getReferenceCount (UT_IndexedHashSetItemId id) const
 
exint getReferenceCount (const T &key) const
 
void replace (const UT_IndexedHashSet &src)
 
UT_IndexedHashSetItemId add (const T &key)
 
const TaddReference (UT_IndexedHashSetItemId id, int inc)
 
SYS_FORCE_INLINE const TaddReference (UT_IndexedHashSetItemId id)
 
UT_IndexedHashSetItemId findId (const T &key) const
 
const TfindItemAndId (const T &key, UT_IndexedHashSetItemId &id) const
 
SYS_FORCE_INLINE const Tget (UT_IndexedHashSetItemId id) const
 
const TgetOrderedItem (exint index, UT_IndexedHashSetItemId *id=nullptr) const
 
bool remove (const T &key)
 
bool remove (UT_IndexedHashSetItemId id)
 
UT_IndexedHashSetItemId replaceItem (UT_IndexedHashSetItemId id, const T &key)
 
template<typename ID_ARRAY , typename T_ARRAY >
exint extractItems (ID_ARRAY &ids, T_ARRAY &items, exint maxitems) const
 
template<typename ID_ARRAY , typename T_ARRAY >
exint extractItems (ID_ARRAY &ids, T_ARRAY &items) const
 
template<typename T_ARRAY >
exint extractItems (T_ARRAY &items) const
 
unsafe_iterator begin () const
 
unsafe_iterator end () const
 
unsafe_listiterator beginList () const
 
unsafe_listiterator endList () const
 

Detailed Description

template<class T>
class UT_IndexedHashSet< T >

A thread-safe hash map which stores indexed shared items.

Each item in the hash map is reference counted. That is, if objects are added multiple times, only a single object will be stored in the map.

Removing an item from the hash map (by id or key) will decrement the reference count on the item. When no longer referenced, the map will delete the item.

Each item is assigned a unique id (UT_IndexedHashSetItemId). The item can then be retrieved efficiently from the map using the id (UT_IndexedHashSet::get())

Many methods on the map are thread-safe. Some methods are not (and are noted in the comments).

Definition at line 44 of file UT_IndexedHashSet.h.

Member Typedef Documentation

Definition at line 225 of file UT_IndexedHashSet.h.

Definition at line 226 of file UT_IndexedHashSet.h.

Constructor & Destructor Documentation

template<class T>
UT_IndexedHashSet< T >::UT_IndexedHashSet ( )
inline

Each item stored in the map will be given a unique id of type UT_IndexedHashSetItemId. These id's can be used to perform efficient lookup of items in the map.

Definition at line 50 of file UT_IndexedHashSet.h.

template<class T>
UT_IndexedHashSet< T >::~UT_IndexedHashSet ( )
inline

Definition at line 53 of file UT_IndexedHashSet.h.

Member Function Documentation

template<typename T>
UT_IndexedHashSetItemId UT_IndexedHashSet< T >::add ( const T key)

Definition at line 169 of file UT_IndexedHashSetImpl.h.

template<typename T >
const T * UT_IndexedHashSet< T >::addReference ( UT_IndexedHashSetItemId  id,
int  inc 
)

This may return null if inc is negative and the reference count reaches zero, or if the ID is out of range.

Definition at line 84 of file UT_IndexedHashSetImpl.h.

template<class T>
SYS_FORCE_INLINE const T* UT_IndexedHashSet< T >::addReference ( UT_IndexedHashSetItemId  id)
inline

Definition at line 148 of file UT_IndexedHashSet.h.

template<class T>
unsafe_iterator UT_IndexedHashSet< T >::begin ( void  ) const
inline

Definition at line 365 of file UT_IndexedHashSet.h.

template<class T>
unsafe_listiterator UT_IndexedHashSet< T >::beginList ( ) const
inline

Definition at line 369 of file UT_IndexedHashSet.h.

template<typename T >
void UT_IndexedHashSet< T >::clear ( )

Clear the map

Note
This is not thread-safe

Definition at line 23 of file UT_IndexedHashSetImpl.h.

template<typename T >
bool UT_IndexedHashSet< T >::compactIds ( IdRemapping remapping)

Compact the list. This fills out the integer map of old id's and their new id's. If no compaction was done, the function returns false.

Note
This is not thread-safe

Definition at line 313 of file UT_IndexedHashSetImpl.h.

template<class T>
bool UT_IndexedHashSet< T >::empty ( void  ) const
inline

Return whether the map is empty.

Definition at line 67 of file UT_IndexedHashSet.h.

template<class T>
unsafe_iterator UT_IndexedHashSet< T >::end ( void  ) const
inline

Definition at line 367 of file UT_IndexedHashSet.h.

template<class T>
unsafe_listiterator UT_IndexedHashSet< T >::endList ( ) const
inline

Definition at line 371 of file UT_IndexedHashSet.h.

template<class T>
exint UT_IndexedHashSet< T >::entries ( ) const
inline

Return the number of entries in the map.

Note
This is not thread-safe

Definition at line 64 of file UT_IndexedHashSet.h.

template<typename T >
template<typename ID_ARRAY , typename T_ARRAY >
exint UT_IndexedHashSet< T >::extractItems ( ID_ARRAY &  ids,
T_ARRAY &  items,
exint  maxitems 
) const

Definition at line 376 of file UT_IndexedHashSetImpl.h.

template<typename T >
template<typename ID_ARRAY , typename T_ARRAY >
exint UT_IndexedHashSet< T >::extractItems ( ID_ARRAY &  ids,
T_ARRAY &  items 
) const

Definition at line 406 of file UT_IndexedHashSetImpl.h.

template<typename T >
template<typename T_ARRAY >
exint UT_IndexedHashSet< T >::extractItems ( T_ARRAY &  items) const

Definition at line 429 of file UT_IndexedHashSetImpl.h.

template<class T>
UT_IndexedHashSetItemId UT_IndexedHashSet< T >::findId ( const T key) const
inline

Definition at line 151 of file UT_IndexedHashSet.h.

template<typename T>
const T * UT_IndexedHashSet< T >::findItemAndId ( const T key,
UT_IndexedHashSetItemId id 
) const

Definition at line 192 of file UT_IndexedHashSetImpl.h.

template<class T>
SYS_FORCE_INLINE const T* UT_IndexedHashSet< T >::get ( UT_IndexedHashSetItemId  id) const
inline

Definition at line 160 of file UT_IndexedHashSet.h.

template<class T>
UT_IndexedHashSetItemId UT_IndexedHashSet< T >::getItemIdUpperBound ( ) const
inline

Return the maximum possible UT_IndexedHashSetItemId stored in the map. This returns an upper bound and is not exact.

Note
This is not thread-safe

Definition at line 75 of file UT_IndexedHashSet.h.

template<typename T >
int64 UT_IndexedHashSet< T >::getMemoryUsage ( bool  inclusive) const

Return approximate memory usage (not including key or item storage)

Definition at line 443 of file UT_IndexedHashSetImpl.h.

template<class T>
fpreal UT_IndexedHashSet< T >::getOccupancy ( ) const
inline

Return the "occupancy" of the map.

Note
This is not thread-safe

Definition at line 80 of file UT_IndexedHashSet.h.

template<typename T >
const T * UT_IndexedHashSet< T >::getOrderedItem ( exint  index,
UT_IndexedHashSetItemId id = nullptr 
) const

Definition at line 60 of file UT_IndexedHashSetImpl.h.

template<typename T >
exint UT_IndexedHashSet< T >::getReferenceCount ( UT_IndexedHashSetItemId  id) const

Definition at line 120 of file UT_IndexedHashSetImpl.h.

template<typename T>
exint UT_IndexedHashSet< T >::getReferenceCount ( const T key) const

Definition at line 137 of file UT_IndexedHashSetImpl.h.

template<typename T>
bool UT_IndexedHashSet< T >::remove ( const T key)

Definition at line 207 of file UT_IndexedHashSetImpl.h.

template<typename T>
bool UT_IndexedHashSet< T >::remove ( UT_IndexedHashSetItemId  id)

Definition at line 235 of file UT_IndexedHashSetImpl.h.

template<typename T >
void UT_IndexedHashSet< T >::replace ( const UT_IndexedHashSet< T > &  src)

Replace with the contents of another map.

Note
This is not thread-safe

Definition at line 47 of file UT_IndexedHashSetImpl.h.

template<typename T>
UT_IndexedHashSetItemId UT_IndexedHashSet< T >::replaceItem ( UT_IndexedHashSetItemId  id,
const T key 
)

Definition at line 250 of file UT_IndexedHashSetImpl.h.

template<typename T >
template<typename P >
bool UT_IndexedHashSet< T >::sortItems ( const P predicate)

Sort the list of ids based on the comparator. This method only works if the table has been compacted. Returns false if there are no ids or the list is not compacted.

Note
This is not thread-safe

Definition at line 348 of file UT_IndexedHashSetImpl.h.


The documentation for this class was generated from the following files: