Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
SkLRUCache< K, V, HashK > Class Template Reference

#include <SkLRUCache.h>

Public Member Functions

 SkLRUCache (int maxCount)
 
 SkLRUCache ()=delete
 
 ~SkLRUCache ()
 
 SkLRUCache (const SkLRUCache &)=delete
 
SkLRUCacheoperator= (const SkLRUCache &)=delete
 
Vfind (const K &key)
 
Vinsert (const K &key, V value)
 
Vinsert_or_update (const K &key, V value)
 
int count () const
 
template<typename Fn >
void foreach (Fn &&fn)
 
void reset ()
 

Detailed Description

template<typename K, typename V, typename HashK = SkGoodHash>
class SkLRUCache< K, V, HashK >

A generic LRU cache.

Definition at line 19 of file SkLRUCache.h.

Constructor & Destructor Documentation

◆ SkLRUCache() [1/3]

template<typename K , typename V , typename HashK = SkGoodHash>
SkLRUCache< K, V, HashK >::SkLRUCache ( int  maxCount)
inlineexplicit

Definition at line 33 of file SkLRUCache.h.

33: fMaxCount(maxCount) {}

◆ SkLRUCache() [2/3]

template<typename K , typename V , typename HashK = SkGoodHash>
SkLRUCache< K, V, HashK >::SkLRUCache ( )
delete

◆ ~SkLRUCache()

template<typename K , typename V , typename HashK = SkGoodHash>
SkLRUCache< K, V, HashK >::~SkLRUCache ( )
inline

Definition at line 36 of file SkLRUCache.h.

36 {
37 Entry* node = fLRU.head();
38 while (node) {
39 fLRU.remove(node);
40 delete node;
41 node = fLRU.head();
42 }
43 }
void remove(T *entry)

◆ SkLRUCache() [3/3]

template<typename K , typename V , typename HashK = SkGoodHash>
SkLRUCache< K, V, HashK >::SkLRUCache ( const SkLRUCache< K, V, HashK > &  )
delete

Member Function Documentation

◆ count()

template<typename K , typename V , typename HashK = SkGoodHash>
int SkLRUCache< K, V, HashK >::count ( ) const
inline

Definition at line 83 of file SkLRUCache.h.

83 {
84 return fMap.count();
85 }
int count() const
Definition: SkTHash.h:67

◆ find()

template<typename K , typename V , typename HashK = SkGoodHash>
V * SkLRUCache< K, V, HashK >::find ( const K key)
inline

Definition at line 49 of file SkLRUCache.h.

49 {
50 Entry** value = fMap.find(key);
51 if (!value) {
52 return nullptr;
53 }
54 Entry* entry = *value;
55 if (entry != fLRU.head()) {
56 fLRU.remove(entry);
57 fLRU.addToHead(entry);
58 } // else it's already at head position, don't need to do anything
59 return &entry->fValue;
60 }
void addToHead(T *entry)
T * find(const K &key) const
Definition: SkTHash.h:107
uint8_t value

◆ foreach()

template<typename K , typename V , typename HashK = SkGoodHash>
template<typename Fn >
void SkLRUCache< K, V, HashK >::foreach ( Fn &&  fn)
inline

Definition at line 88 of file SkLRUCache.h.

88 {
91 e = iter.next()) {
92 fn(&e->fKey, &e->fValue);
93 }
94 }

◆ insert()

template<typename K , typename V , typename HashK = SkGoodHash>
V * SkLRUCache< K, V, HashK >::insert ( const K key,
V  value 
)
inline

Definition at line 62 of file SkLRUCache.h.

62 {
63 SkASSERT(!this->find(key));
64
65 Entry* entry = new Entry(key, std::move(value));
66 fMap.set(entry);
67 fLRU.addToHead(entry);
68 while (fMap.count() > fMaxCount) {
69 this->remove(fLRU.tail()->fKey);
70 }
71 return &entry->fValue;
72 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
V * find(const K &key)
Definition: SkLRUCache.h:49

◆ insert_or_update()

template<typename K , typename V , typename HashK = SkGoodHash>
V * SkLRUCache< K, V, HashK >::insert_or_update ( const K key,
V  value 
)
inline

Definition at line 74 of file SkLRUCache.h.

74 {
75 if (V* found = this->find(key)) {
76 *found = std::move(value);
77 return found;
78 } else {
79 return this->insert(key, std::move(value));
80 }
81 }
V * insert(const K &key, V value)
Definition: SkLRUCache.h:62
T __attribute__((ext_vector_type(N))) V

◆ operator=()

template<typename K , typename V , typename HashK = SkGoodHash>
SkLRUCache & SkLRUCache< K, V, HashK >::operator= ( const SkLRUCache< K, V, HashK > &  )
delete

◆ reset()

template<typename K , typename V , typename HashK = SkGoodHash>
void SkLRUCache< K, V, HashK >::reset ( )
inline

Definition at line 96 of file SkLRUCache.h.

96 {
97 fMap.reset();
98 for (Entry* e = fLRU.head(); e; e = fLRU.head()) {
99 fLRU.remove(e);
100 delete e;
101 }
102 }

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