Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
skia_private::THashTable< T, K, Traits > Class Template Reference

#include <SkTHash.h>

Classes

class  Iter
 

Public Member Functions

 THashTable ()=default
 
 ~THashTable ()=default
 
 THashTable (const THashTable &that)
 
 THashTable (THashTable &&that)
 
THashTableoperator= (const THashTable &that)
 
THashTableoperator= (THashTable &&that)
 
void reset ()
 
int count () const
 
int capacity () const
 
size_t approxBytesUsed () const
 
void swap (THashTable &that)
 
void swap (THashTable &&that)
 
Tset (T val)
 
Tfind (const K &key) const
 
T findOrNull (const K &key) const
 
bool removeIfExists (const K &key)
 
void remove (const K &key)
 
void resize (int capacity)
 
template<typename Fn >
void foreach (Fn &&fn)
 
template<typename Fn >
void foreach (Fn &&fn) const
 

Detailed Description

template<typename T, typename K, typename Traits = T>
class skia_private::THashTable< T, K, Traits >

Definition at line 32 of file SkTHash.h.

Constructor & Destructor Documentation

◆ THashTable() [1/3]

template<typename T , typename K , typename Traits = T>
skia_private::THashTable< T, K, Traits >::THashTable ( )
default

◆ ~THashTable()

template<typename T , typename K , typename Traits = T>
skia_private::THashTable< T, K, Traits >::~THashTable ( )
default

◆ THashTable() [2/3]

template<typename T , typename K , typename Traits = T>
skia_private::THashTable< T, K, Traits >::THashTable ( const THashTable< T, K, Traits > &  that)
inline

Definition at line 37 of file SkTHash.h.

37{ *this = that; }

◆ THashTable() [3/3]

template<typename T , typename K , typename Traits = T>
skia_private::THashTable< T, K, Traits >::THashTable ( THashTable< T, K, Traits > &&  that)
inline

Definition at line 38 of file SkTHash.h.

38{ *this = std::move(that); }

Member Function Documentation

◆ approxBytesUsed()

template<typename T , typename K , typename Traits = T>
size_t skia_private::THashTable< T, K, Traits >::approxBytesUsed ( ) const
inline

Definition at line 74 of file SkTHash.h.

74{ return fCapacity * sizeof(Slot); }

◆ capacity()

template<typename T , typename K , typename Traits = T>
int skia_private::THashTable< T, K, Traits >::capacity ( ) const
inline

Definition at line 71 of file SkTHash.h.

71{ return fCapacity; }

◆ count()

template<typename T , typename K , typename Traits = T>
int skia_private::THashTable< T, K, Traits >::count ( ) const
inline

Definition at line 67 of file SkTHash.h.

67{ return fCount; }

◆ find()

template<typename T , typename K , typename Traits = T>
T * skia_private::THashTable< T, K, Traits >::find ( const K key) const
inline

Definition at line 107 of file SkTHash.h.

107 {
108 uint32_t hash = Hash(key);
109 int index = hash & (fCapacity-1);
110 for (int n = 0; n < fCapacity; n++) {
111 Slot& s = fSlots[index];
112 if (s.empty()) {
113 return nullptr;
114 }
115 if (hash == s.fHash && key == Traits::GetKey(*s)) {
116 return &*s;
117 }
118 index = this->next(index);
119 }
120 SkASSERT(fCapacity == fCount);
121 return nullptr;
122 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
static uint32_t hash(const SkShaderBase::GradientInfo &v)
struct MyStruct s

◆ findOrNull()

template<typename T , typename K , typename Traits = T>
T skia_private::THashTable< T, K, Traits >::findOrNull ( const K key) const
inline

Definition at line 126 of file SkTHash.h.

126 {
127 if (T* p = this->find(key)) {
128 return *p;
129 }
130 return nullptr;
131 }
T * find(const K &key) const
Definition: SkTHash.h:107
#define T
Definition: precompiler.cc:65

◆ foreach() [1/2]

template<typename T , typename K , typename Traits = T>
template<typename Fn >
void skia_private::THashTable< T, K, Traits >::foreach ( Fn &&  fn)
inline

Definition at line 184 of file SkTHash.h.

184 {
185 for (int i = 0; i < fCapacity; i++) {
186 if (fSlots[i].has_value()) {
187 fn(&*fSlots[i]);
188 }
189 }
190 }

◆ foreach() [2/2]

template<typename T , typename K , typename Traits = T>
template<typename Fn >
void skia_private::THashTable< T, K, Traits >::foreach ( Fn &&  fn) const
inline

Definition at line 194 of file SkTHash.h.

194 {
195 for (int i = 0; i < fCapacity; i++) {
196 if (fSlots[i].has_value()) {
197 fn(*fSlots[i]);
198 }
199 }
200 }

◆ operator=() [1/2]

template<typename T , typename K , typename Traits = T>
THashTable & skia_private::THashTable< T, K, Traits >::operator= ( const THashTable< T, K, Traits > &  that)
inline

Definition at line 40 of file SkTHash.h.

40 {
41 if (this != &that) {
42 fCount = that.fCount;
43 fCapacity = that.fCapacity;
44 fSlots.reset(new Slot[that.fCapacity]);
45 for (int i = 0; i < fCapacity; i++) {
46 fSlots[i] = that.fSlots[i];
47 }
48 }
49 return *this;
50 }

◆ operator=() [2/2]

template<typename T , typename K , typename Traits = T>
THashTable & skia_private::THashTable< T, K, Traits >::operator= ( THashTable< T, K, Traits > &&  that)
inline

Definition at line 52 of file SkTHash.h.

52 {
53 if (this != &that) {
54 fCount = that.fCount;
55 fCapacity = that.fCapacity;
56 fSlots = std::move(that.fSlots);
57
58 that.fCount = that.fCapacity = 0;
59 }
60 return *this;
61 }

◆ remove()

template<typename T , typename K , typename Traits = T>
void skia_private::THashTable< T, K, Traits >::remove ( const K key)
inline

Definition at line 157 of file SkTHash.h.

157 {
159 }
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
bool removeIfExists(const K &key)
Definition: SkTHash.h:135

◆ removeIfExists()

template<typename T , typename K , typename Traits = T>
bool skia_private::THashTable< T, K, Traits >::removeIfExists ( const K key)
inline

Definition at line 135 of file SkTHash.h.

135 {
136 uint32_t hash = Hash(key);
137 int index = hash & (fCapacity-1);
138 for (int n = 0; n < fCapacity; n++) {
139 Slot& s = fSlots[index];
140 if (s.empty()) {
141 return false;
142 }
143 if (hash == s.fHash && key == Traits::GetKey(*s)) {
144 this->removeSlot(index);
145 if (4 * fCount <= fCapacity && fCapacity > 4) {
146 this->resize(fCapacity / 2);
147 }
148 return true;
149 }
150 index = this->next(index);
151 }
152 SkASSERT(fCapacity == fCount);
153 return false;
154 }
void resize(int capacity)
Definition: SkTHash.h:163

◆ reset()

template<typename T , typename K , typename Traits = T>
void skia_private::THashTable< T, K, Traits >::reset ( )
inline

Definition at line 64 of file SkTHash.h.

64{ *this = THashTable(); }

◆ resize()

template<typename T , typename K , typename Traits = T>
void skia_private::THashTable< T, K, Traits >::resize ( int  capacity)
inline

Definition at line 163 of file SkTHash.h.

163 {
164 SkASSERT(capacity >= fCount);
165 int oldCapacity = fCapacity;
166 SkDEBUGCODE(int oldCount = fCount);
167
168 fCount = 0;
169 fCapacity = capacity;
170 std::unique_ptr<Slot[]> oldSlots = std::move(fSlots);
171 fSlots.reset(new Slot[capacity]);
172
173 for (int i = 0; i < oldCapacity; i++) {
174 Slot& s = oldSlots[i];
175 if (s.has_value()) {
176 this->uncheckedSet(*std::move(s));
177 }
178 }
179 SkASSERT(fCount == oldCount);
180 }
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
int capacity() const
Definition: SkTHash.h:71

◆ set()

template<typename T , typename K , typename Traits = T>
T * skia_private::THashTable< T, K, Traits >::set ( T  val)
inline

Definition at line 99 of file SkTHash.h.

99 {
100 if (4 * fCount >= 3 * fCapacity) {
101 this->resize(fCapacity > 0 ? fCapacity * 2 : 4);
102 }
103 return this->uncheckedSet(std::move(val));
104 }

◆ swap() [1/2]

template<typename T , typename K , typename Traits = T>
void skia_private::THashTable< T, K, Traits >::swap ( THashTable< T, K, Traits > &&  that)
inline

Definition at line 83 of file SkTHash.h.

83 {
84 *this = std::move(that);
85 }

◆ swap() [2/2]

template<typename T , typename K , typename Traits = T>
void skia_private::THashTable< T, K, Traits >::swap ( THashTable< T, K, Traits > &  that)
inline

Definition at line 77 of file SkTHash.h.

77 {
78 std::swap(fCount, that.fCount);
79 std::swap(fCapacity, that.fCapacity);
80 std::swap(fSlots, that.fSlots);
81 }
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341

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