HDK
|
A thread-safe hash map which stores indexed shared items. More...
#include <UT_IndexedHashMapT.h>
Additional Inherited Members | |
Public Types inherited from UT_IndexedHashMap | |
typedef void | InternalKeyT |
typedef void | InternalItemT |
Protected Types inherited from UT_IndexedHashMap | |
typedef UT_ConcurrentHashMap < keyContainer, itemContainer *, keyCompare > | UT_IndexedHashMapTable |
typedef UT_ConcurrentVector < listContainer > | UT_IndexedHashMapVector |
typedef UT_ConcurrentQueue < UT_IndexedHashMapItemId > | UT_IndexedHashMapHoleQueue |
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 automatically delete the item.
As items are added to the map, each is assigned a unique id (UT_IndexedHashMapItemId). Items can then be retrieved efficiently from the map using the id (UT_IndexedHashMapT::get()).
Many methods on the map are thread-safe, though some are not. The thread safety of the methods is described in the comments.
The KEY template parameter needs to have:
For sorting, there should be a < operator defined on items.
When adding items to an indexed hash map, only a single item is every created for duplicate keys. To optimize addition, items can be created only if the item will be added to the map. This is done through the DEFER_ALLOC template parameter. With the default argument (which doesn't allow deferred allocation), ITEM objects must be passed in the add() method.
Definition at line 125 of file UT_IndexedHashMapT.h.
|
inline |
Definition at line 162 of file UT_IndexedHashMapT.h.
|
inlineoverride |
Definition at line 165 of file UT_IndexedHashMapT.h.
|
inline |
Add a new item to the map, returning the item actually stored in the map. This may not be the item passed in if the map already contains the object.
If the item passed in is NULL, an item will be allocated using the deferred allocator (see the DEFER_ALLOC template argument). The default allocator does not allow for deferred construction and requires the item to be passed in.
Definition at line 191 of file UT_IndexedHashMapT.h.
|
inline |
Add reference to an existing item.
id | Item index |
inc | The number of references to add. It defaults to 1. If negative, the item may be removed in which case it returns 0. |
Definition at line 202 of file UT_IndexedHashMapT.h.
|
inline |
Add reference to an existing item.
id | Item index |
inc | The number of references to add. It defaults to 1. If negative, the item may be removed in which case it returns 0. |
Definition at line 204 of file UT_IndexedHashMapT.h.
|
inlineoverrideprotectedvirtual |
Implements UT_IndexedHashMap.
Definition at line 143 of file UT_IndexedHashMapT.h.
|
inlineprotected |
Definition at line 135 of file UT_IndexedHashMapT.h.
|
inlineprotected |
Definition at line 137 of file UT_IndexedHashMapT.h.
|
inlineprotected |
The indexed hash map maintains all operations on internal types. This allows the bulk of the code to be shared between template instantiations.
Definition at line 131 of file UT_IndexedHashMapT.h.
|
inlineprotected |
Definition at line 133 of file UT_IndexedHashMapT.h.
|
inlineoverrideprotectedvirtual |
Implements UT_IndexedHashMap.
Definition at line 146 of file UT_IndexedHashMapT.h.
|
inlineoverrideprotectedvirtual |
Implements UT_IndexedHashMap.
Definition at line 155 of file UT_IndexedHashMapT.h.
|
inlineoverrideprotectedvirtual |
Implements UT_IndexedHashMap.
Definition at line 148 of file UT_IndexedHashMapT.h.
|
inline |
Extract the items into a list of ids and pointers to items. Items will be appended to the lists. The function returns the number of items added.
Definition at line 306 of file UT_IndexedHashMapT.h.
|
inline |
Definition at line 314 of file UT_IndexedHashMapT.h.
|
inline |
Extract an array of pointers to items.
If there are id's associated with the items, the items will be stored at their indexed location. The list of items may contain NULL pointers for unused index entries.
If there are no id's, the items will be extracted in arbitrary order into a packed array.
The function returns the number of items in the array.
Definition at line 336 of file UT_IndexedHashMapT.h.
|
inline |
Find an item in the map.
Definition at line 210 of file UT_IndexedHashMapT.h.
|
inline |
|
inline |
Given a key, find an item's id (or -1 if not found)
Definition at line 215 of file UT_IndexedHashMapT.h.
|
inline |
Get the item which has the given id
Definition at line 227 of file UT_IndexedHashMapT.h.
|
inline |
Get the key associated with the given id
Definition at line 250 of file UT_IndexedHashMapT.h.
|
inline |
Return approximate memory usage NOTE: Not including KEY or ITEM storage, even though the destructor destroys both the KEY and ITEM objects, because the caller should know better what KEY and ITEM are. If they can't vary in size, just multiply by entries(); if they can, use begin() to iterate through.
Definition at line 175 of file UT_IndexedHashMapT.h.
|
inline |
Get the n'th item in the list. This skips over holes and will return items for a contiguous list of integers. For example:
The UT_IndexedHashMapItemId's
returned should be monotonic, but not contiguous. If the id
parameter is non-null, the id for the item will be stored there.
Definition at line 244 of file UT_IndexedHashMapT.h.
|
inlineoverrideprotectedvirtual |
Methods for keys.
Implements UT_IndexedHashMap.
Definition at line 141 of file UT_IndexedHashMapT.h.
|
inlineoverrideprotectedvirtual |
Implements UT_IndexedHashMap.
Definition at line 157 of file UT_IndexedHashMapT.h.
|
inlineoverrideprotectedvirtual |
Implements UT_IndexedHashMap.
Definition at line 151 of file UT_IndexedHashMapT.h.
|
inline |
Convenience operators
Definition at line 349 of file UT_IndexedHashMapT.h.
|
inline |
Convenience operators
Definition at line 351 of file UT_IndexedHashMapT.h.
|
inline |
Convenience operators
Definition at line 345 of file UT_IndexedHashMapT.h.
|
inline |
Convenience operators
Definition at line 347 of file UT_IndexedHashMapT.h.
|
inline |
Remove an item from the map. This dereferences the item in the map and returns true if the item was deleted from the map. The method will return false if the item was shared and is still in the map.
Definition at line 257 of file UT_IndexedHashMapT.h.
|
inline |
Remove the item with the given id from the map.
Definition at line 262 of file UT_IndexedHashMapT.h.
|
inline |
Replaces the content of this with the content of src.
Definition at line 356 of file UT_IndexedHashMapT.h.
|
inline |
Replace an item at a given id.
The existing item will be deleted from the table and the new item will replace it. The method will fail if there is currently no item at the given location.
The method will return the new id for the item. Usually, this will be the same as the existing id, unless the new item already exists in the map.
If the item passed in is NULL, a new item will be called using newItem()
id
does not match the id
passed in, it's the user's responsibility to update any references to the new id. Definition at line 281 of file UT_IndexedHashMapT.h.
|
inline |
Replace the object given by the old_key
with the value given by the new_key
.
The old_key
will be removed by the map.
If the map stores id's, the new_key
will be assigned the same id as the old_key
unless the new_key
already exists in the map.
The new_key
object will inherit all references of the old_key
.
This method returns the id of the new item. This will be the same id as the old object unless the new_key
already exists in the map.
Definition at line 298 of file UT_IndexedHashMapT.h.