7 #ifndef PXR_EXEC_VDF_LRU_CACHE_H
8 #define PXR_EXEC_VDF_LRU_CACHE_H
26 template <
typename Key,
typename Value,
typename Hash >
40 explicit VdfLRUCache(
size_t capacity) : _capacity(capacity) {}
61 _Entry(
size_t h,
const Key &k) : hash(h), key(k) {}
70 using _List = std::list<_Entry>;
74 const size_t _capacity;
79 template <
typename Key,
typename Value,
typename Hash >
85 const size_t hash =
Hash()(key);
88 typename _List::iterator it = _list.begin();
89 for (; it != _list.end(); ++it) {
91 if (it->hash == hash && it->key == key) {
95 if (it != _list.begin()) {
96 _list.splice(_list.begin(), _list, it);
107 if (_list.size() < _capacity) {
108 _list.emplace_front(hash, key);
114 _list.splice(_list.begin(), _list, --_list.end());
115 _list.front().hash = hash;
116 _list.front().key = key;
120 *value = &_list.front().value;
124 template <
typename Key,
typename Value,
typename Hash >
STATIC_INLINE size_t Hash(const char *s, size_t len)
VdfLRUCache(size_t capacity)
#define PXR_NAMESPACE_OPEN_SCOPE
GLsizei const GLfloat * value
bool Lookup(const Key &key, Value **value)
VdfLRUCache(const VdfLRUCache &)=delete
A generic, discriminated value, whose type may be queried dynamically.
GLfloat GLfloat GLfloat GLfloat h
VdfLRUCache & operator=(const VdfLRUCache &)=delete
#define PXR_NAMESPACE_CLOSE_SCOPE