28 #ifndef _GUSD_UT_CAPPEDCACHE_H_
29 #define _GUSD_UT_CAPPEDCACHE_H_
45 template <
typename KeyT,
46 typename HashCompare=tbb::tbb_hash_compare<KeyT> >
59 {
return HashCompare().hash(_key); }
63 return HashCompare().equal(_key,
64 UTverify_cast<const GusdUT_CappedKey*>(
89 template <
typename Item>
92 template <
typename Item,
typename Creator,
typename... Args>
94 const Creator& creator,
100 template <
typename T,
typename Creator,
typename... Args>
102 const Creator& creator,
105 template <
typename MatchFn>
113 {
return (
size_t)k->getHash(); }
116 {
return a->isEqual(*b); }
122 _HashCompare> _ConstructMap;
123 _ConstructMap _constructMap;
127 template <
typename Item>
138 template <
typename Item,
typename Creator,
typename... Args>
141 const Creator& creator,
144 if(
auto item = Find<Item>(key))
149 _ConstructMap::accessor
a;
150 if(_constructMap.insert(a, keyHnd)) {
154 if((a->second = creator(args...))) {
157 _constructMap.erase(a);
163 UTverify_cast<const Item*>(a->second.get()));
164 _constructMap.erase(a);
168 template <
typename MatchFn>
177 if(matchFn(key, item)) {
178 freed += item->getMemoryUsage();
UT_CappedItemHandle findItem(const UT_CappedKey &key)
Find an item in the cache.
~GusdUT_CappedCache() override
GusdUT_CappedCache(const char *name, int64 size_in_mb=32)
UT_IntrusivePtr< UT_CappedItem > UT_CappedItemHandle
Base class for search keys for UT_CappedCache.
GLboolean GLboolean GLboolean GLboolean a
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
GusdUT_CappedKey(const KeyT &key)
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
~GusdUT_CappedKey() override
bool isEqual(const UT_CappedKey &key) const override
Test equality.
bool FindOrCreateVal(const UT_CappedKey &key, const Creator &creator, Args &...args)
int64 ClearEntries(const MatchFn &matchFn)
bool FindVal(const UT_CappedKey &key)
const KeyT & operator*() const
void deleteItem(const UT_CappedKey &key)
Remove an item from the cache.
void threadSafeTraversal(T &task)
unsigned getHash() const override
Return a hash for the key.
UT_CappedKey * duplicate() const override
The duplicate() method should return a copy of the key.
Wrapper around hboost::intrusive_ptr.
UT_CappedItemHandle addItem(const UT_CappedKey &key, const UT_CappedItemHandle &item)
GLuint const GLchar * name
const KeyT * operator->() const
GLboolean GLboolean GLboolean b
#define UT_ConcurrentHashMap
UT_IntrusivePtr< const Item > Find(const UT_CappedKey &key)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
virtual UT_CappedKey * duplicate() const =0
The duplicate() method should return a copy of the key.
UT_IntrusivePtr< const Item > FindOrCreate(const UT_CappedKey &key, const Creator &creator, Args &...args)
#define PXR_NAMESPACE_CLOSE_SCOPE
UT_IntrusivePtr< UT_CappedKey > UT_CappedKeyHandle
**If you just want to fire and args