HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  keyHasher
 
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.

When the map stores 'ids', 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).

The KEY template parameter needs to have:

KEY(const KEY &src); // The copy constructor
uint hash() const; // A hash method
bool isEqual(const KEY &src) const; // A comparison operator

Definition at line 50 of file UT_IndexedHashSet.h.

Member Typedef Documentation

Definition at line 247 of file UT_IndexedHashSet.h.

Definition at line 248 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 56 of file UT_IndexedHashSet.h.

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

Definition at line 59 of file UT_IndexedHashSet.h.

Member Function Documentation

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

Definition at line 202 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 117 of file UT_IndexedHashSetImpl.h.

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

Definition at line 154 of file UT_IndexedHashSet.h.

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

Definition at line 387 of file UT_IndexedHashSet.h.

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

Definition at line 391 of file UT_IndexedHashSet.h.

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

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
This is a no-op if id's are not stored in the map

Definition at line 346 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 73 of file UT_IndexedHashSet.h.

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

Definition at line 389 of file UT_IndexedHashSet.h.

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

Definition at line 393 of file UT_IndexedHashSet.h.

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

Return the number of entries in the map.

Note
This is not thread-safe

Definition at line 70 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 409 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 439 of file UT_IndexedHashSetImpl.h.

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

Definition at line 462 of file UT_IndexedHashSetImpl.h.

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

Definition at line 157 of file UT_IndexedHashSet.h.

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

Definition at line 225 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 166 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
Not supported if id's are not stored in the map

Definition at line 82 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 476 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
Not supported if id's are not stored in the map

Definition at line 88 of file UT_IndexedHashSet.h.

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

Definition at line 93 of file UT_IndexedHashSetImpl.h.

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

Definition at line 153 of file UT_IndexedHashSetImpl.h.

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

Definition at line 170 of file UT_IndexedHashSetImpl.h.

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

Definition at line 240 of file UT_IndexedHashSetImpl.h.

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

Definition at line 268 of file UT_IndexedHashSetImpl.h.

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

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 283 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
This is a no-op if id's are not stored in the map

Definition at line 381 of file UT_IndexedHashSetImpl.h.


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