Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
GrHashMapWithCache< K, V, KeyTraits, HashT > Class Template Reference

#include <GrHashMapWithCache.h>

Inheritance diagram for GrHashMapWithCache< K, V, KeyTraits, HashT >:
SkNoncopyable

Public Member Functions

int count () const
 
size_t approxBytesUsed () const
 
const Vfind (const K &key) const
 
const Vset (K key, V val)
 
void remove (K key)
 
void reset ()
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 

Detailed Description

template<typename K, typename V, typename KeyTraits, typename HashT = SkGoodHash>
class GrHashMapWithCache< K, V, KeyTraits, HashT >

A hash map that caches the most recently accessed entry. The API is a subset of SkHashMap, and you must provide a sentinel key that will never be present, such as SK_InvalidUniqueID.

KeyTraits must have:

Definition at line 30 of file GrHashMapWithCache.h.

Member Function Documentation

◆ approxBytesUsed()

template<typename K , typename V , typename KeyTraits , typename HashT = SkGoodHash>
size_t GrHashMapWithCache< K, V, KeyTraits, HashT >::approxBytesUsed ( ) const
inline

Definition at line 36 of file GrHashMapWithCache.h.

36{ return fMap.approxBytesUsed(); }

◆ count()

template<typename K , typename V , typename KeyTraits , typename HashT = SkGoodHash>
int GrHashMapWithCache< K, V, KeyTraits, HashT >::count ( ) const
inline

Definition at line 33 of file GrHashMapWithCache.h.

33{ return fMap.count(); }

◆ find()

template<typename K , typename V , typename KeyTraits , typename HashT = SkGoodHash>
const V * GrHashMapWithCache< K, V, KeyTraits, HashT >::find ( const K key) const
inline

Definition at line 42 of file GrHashMapWithCache.h.

42 {
43 if (key != fLastKey) {
44 fLastKey = key;
45 fLastValue = fMap.find(key);
46 }
47 return fLastValue;
48 }

◆ remove()

template<typename K , typename V , typename KeyTraits , typename HashT = SkGoodHash>
void GrHashMapWithCache< K, V, KeyTraits, HashT >::remove ( K  key)
inline

Definition at line 63 of file GrHashMapWithCache.h.

63 {
64 // Match THashMap requirement. The caller can find() if they're unsure.
65 SkASSERT(fMap.find(fLastKey));
66 fLastKey = std::move(key);
67 fLastValue = nullptr;
68 fMap.remove(fLastKey);
69 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ reset()

template<typename K , typename V , typename KeyTraits , typename HashT = SkGoodHash>
void GrHashMapWithCache< K, V, KeyTraits, HashT >::reset ( )
inline

Definition at line 72 of file GrHashMapWithCache.h.

72 {
73 fLastKey = KeyTraits::GetInvalidKey();
74 fLastValue = nullptr;
75 fMap.reset();
76 }

◆ set()

template<typename K , typename V , typename KeyTraits , typename HashT = SkGoodHash>
const V * GrHashMapWithCache< K, V, KeyTraits, HashT >::set ( K  key,
V  val 
)
inline

Definition at line 52 of file GrHashMapWithCache.h.

52 {
53 if (fLastValue && key == fLastKey) {
54 *fLastValue = std::move(val);
55 } else {
56 fLastKey = key;
57 fLastValue = fMap.set(std::move(key), std::move(val));
58 }
59 return fLastValue;
60 }

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