Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator > Class Template Reference

#include <hash_map.h>

Inheritance diagram for dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >:
B A dart::BaseCStringIntMap< ValueObject, Zone > dart::BaseCStringSet< ZoneAllocated, Zone > dart::DirectChainedHashMap< IntKeyRawPointerValueTrait< V > > dart::DirectChainedHashMap< TypedDataKeyValueTrait > dart::DirectChainedHashMap< dart::Place > dart::DirectChainedHashMap< const dart::Place > dart::DirectChainedHashMap< Trait > dart::DirectChainedHashMap< S > dart::DirectChainedHashMap< dart::ConstantPoolTrait > dart::DirectChainedHashMap< dart::RawPointerKeyValueTrait > dart::DirectChainedHashMap< MorpherTrait > dart::DirectChainedHashMap< FieldKeyValueTrait > dart::DirectChainedHashMap< SymbolKeyValueTrait > dart::DirectChainedHashMap< ClassKeyValueTrait > dart::DirectChainedHashMap< TypeArgumentsKeyValueTrait > dart::DirectChainedHashMap< AbstractTypeKeyValueTrait > dart::DirectChainedHashMap< FunctionTypeKeyValueTrait > dart::DirectChainedHashMap< TypeParameterKeyValueTrait > dart::DirectChainedHashMap< InstanceKeyValueTrait > dart::DirectChainedHashMap< TableSelectorKeyValueTrait > dart::DirectChainedHashMap< ProgramElementKeyValueTrait > dart::DirectChainedHashMap< ProfileFunctionTableTrait > dart::DirectChainedHashMap< dart::Instruction > dart::DirectChainedHashMap< const dart::Slot > dart::DirectChainedHashMap< ScriptTableTrait > dart::DirectChainedHashMap< TypeSetTrait > dart::DirectChainedHashMap< DefinitionIndexPairTrait > dart::DirectChainedHashMap< dart::compiler::ObjIndexPair > dart::DirectChainedHashMap< IntKeyRawPointerValueTrait< VmType * > > dart::DirectChainedHashMap< IntKeyRawPointerValueTrait< dart::LocalVariable * > > dart::DirectChainedHashMap< IntKeyRawPointerValueTrait< dart::LocalScope * > > dart::DirectChainedHashMap< IntKeyRawPointerValueTrait< dart::JoinEntryInstr * > > dart::MallocDirectChainedHashMap< DebuggerKeyValueTrait >

Classes

class  Iterator
 

Public Member Functions

 BaseDirectChainedHashMap (Allocator *allocator, intptr_t initial_size=kInitialSize)
 
 BaseDirectChainedHashMap (const BaseDirectChainedHashMap &other)
 
intptr_t Length () const
 
 ~BaseDirectChainedHashMap ()
 
void Insert (typename KeyValueTrait::Pair kv)
 
bool Remove (typename KeyValueTrait::Key key)
 
void Update (typename KeyValueTrait::Pair kv)
 
KeyValueTrait::Value LookupValue (typename KeyValueTrait::Key key) const
 
KeyValueTrait::Pair * Lookup (typename KeyValueTrait::Key key) const
 
bool HasKey (typename KeyValueTrait::Key key) const
 
intptr_t Size () const
 
bool IsEmpty () const
 
void Clear ()
 
Iterator GetIterator () const
 
- Public Member Functions inherited from B
 B ()
 
void setValues (int v) override
 
bool checkValues (int v) override
 
- Public Member Functions inherited from A
 A ()
 
virtual ~A ()
 
void * operator new (size_t size)
 
void operator delete (void *p)
 

Protected Member Functions

void Resize (intptr_t new_size)
 

Protected Attributes

Allocator *const allocator_
 
uint32_t * hash_table_ = nullptr
 
KeyValueTrait::Pair * pairs_ = nullptr
 
uint32_t hash_table_size_ = 0
 
uint32_t pairs_size_ = 0
 
uint32_t next_pair_index_ = 0
 
uint32_t deleted_count_ = 0
 

Static Protected Attributes

static constexpr intptr_t kInitialSize = 16
 
static constexpr uint32_t kEmpty = kMaxUint32
 
static constexpr uint32_t kDeleted = kMaxUint32 - 1
 
static constexpr uint32_t kMaxPairs = kMaxUint32 - 2
 

Additional Inherited Members

- Static Public Member Functions inherited from A
static ACreate (SkRandom *r)
 
static void SetAllocator (size_t preallocSize, size_t minAllocSize)
 
static void ResetAllocator ()
 
static void ValidatePool ()
 

Detailed Description

template<typename KeyValueTrait, typename B, typename Allocator = Zone>
class dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >

Definition at line 17 of file hash_map.h.

Constructor & Destructor Documentation

◆ BaseDirectChainedHashMap() [1/2]

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::BaseDirectChainedHashMap ( Allocator allocator,
intptr_t  initial_size = kInitialSize 
)
inlineexplicit

Definition at line 19 of file hash_map.h.

21 : allocator_(allocator) {
22 Resize(initial_size);
23 }
Allocator *const allocator_
Definition hash_map.h:94
void Resize(intptr_t new_size)
Definition hash_map.h:184

◆ BaseDirectChainedHashMap() [2/2]

template<typename KeyValueTrait , typename B , typename Allocator >
dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::BaseDirectChainedHashMap ( const BaseDirectChainedHashMap< KeyValueTrait, B, Allocator > &  other)

Definition at line 111 of file hash_map.h.

113 : B(),
114 allocator_(other.allocator_),
116 other.allocator_->template Alloc<uint32_t>(other.hash_table_size_)),
117 pairs_(other.allocator_->template Alloc<typename KeyValueTrait::Pair>(
118 other.pairs_size_)),
119 hash_table_size_(other.hash_table_size_),
120 pairs_size_(other.pairs_size_),
121 next_pair_index_(other.next_pair_index_),
122 deleted_count_(other.deleted_count_) {
123 memmove(hash_table_, other.hash_table_, hash_table_size_ * sizeof(uint32_t));
124 memmove(pairs_, other.pairs_,
125 pairs_size_ * sizeof(typename KeyValueTrait::Pair));
126}
KeyValueTrait::Pair * pairs_
Definition hash_map.h:96

◆ ~BaseDirectChainedHashMap()

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::~BaseDirectChainedHashMap ( )
inline

Definition at line 29 of file hash_map.h.

29 {
30 allocator_->template Free<uint32_t>(hash_table_, hash_table_size_);
31 allocator_->template Free<typename KeyValueTrait::Pair>(pairs_,
33 }

Member Function Documentation

◆ Clear()

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
void dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::Clear ( )
inline

Definition at line 59 of file hash_map.h.

59 {
60 for (uint32_t i = 0; i < hash_table_size_; i++) {
62 }
63 for (uint32_t i = 0; i < next_pair_index_; i++) {
64 pairs_[i] = typename KeyValueTrait::Pair();
65 }
68 }
static constexpr uint32_t kEmpty
Definition hash_map.h:102

◆ GetIterator()

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
Iterator dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::GetIterator ( ) const
inline

Definition at line 87 of file hash_map.h.

87{ return Iterator(*this); }

◆ HasKey()

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
bool dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::HasKey ( typename KeyValueTrait::Key  key) const
inline

Definition at line 52 of file hash_map.h.

52 {
53 return Lookup(key) != nullptr;
54 }
KeyValueTrait::Pair * Lookup(typename KeyValueTrait::Key key) const
Definition hash_map.h:130

◆ Insert()

template<typename KeyValueTrait , typename B , typename Allocator >
void dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::Insert ( typename KeyValueTrait::Pair  kv)

Definition at line 230 of file hash_map.h.

231 {
232 // TODO(dartbug.com/38018):
233 // ASSERT(Lookup(KeyValueTrait::KeyOf(kv)) == nullptr);
235 uword hash = KeyValueTrait::Hash(KeyValueTrait::KeyOf(kv));
236 uint32_t mask = hash_table_size_ - 1;
237 uint32_t hash_index = hash & mask;
238 uint32_t start = hash_index;
239 intptr_t probes = 0;
240 for (;;) {
241 uint32_t pair_index = hash_table_[hash_index];
242 if ((pair_index == kEmpty) || (pair_index == kDeleted)) {
243 hash_table_[hash_index] = next_pair_index_;
246 break;
247 }
248 RELEASE_ASSERT(++probes < FLAG_hash_map_probes_limit);
249 ASSERT(pair_index < pairs_size_);
250 hash_index = (hash_index + 1) & mask;
251 // Hashtable must contain at least one empty marker.
252 ASSERT(hash_index != start);
253 }
254
256 Resize(Size() << 1);
257 }
258}
static uint32_t hash(const SkShaderBase::GradientInfo &v)
#define RELEASE_ASSERT(cond)
Definition assert.h:327
static constexpr uint32_t kDeleted
Definition hash_map.h:103
#define ASSERT(E)
uintptr_t uword
Definition globals.h:501

◆ IsEmpty()

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
bool dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::IsEmpty ( ) const
inline

Definition at line 57 of file hash_map.h.

57{ return Size() == 0; }

◆ Length()

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
intptr_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::Length ( ) const
inline

Definition at line 27 of file hash_map.h.

◆ Lookup()

template<typename KeyValueTrait , typename B , typename Allocator >
KeyValueTrait::Pair * dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::Lookup ( typename KeyValueTrait::Key  key) const

Definition at line 130 of file hash_map.h.

131 {
132 uword hash = KeyValueTrait::Hash(key);
133 uint32_t mask = hash_table_size_ - 1;
134 uint32_t hash_index = hash & mask;
135 uint32_t start = hash_index;
136 intptr_t probes = 0;
137 for (;;) {
138 uint32_t pair_index = hash_table_[hash_index];
139 if (pair_index == kEmpty) {
140 return nullptr;
141 }
142 if (pair_index != kDeleted) {
143 ASSERT(pair_index < pairs_size_);
144 RELEASE_ASSERT(++probes < FLAG_hash_map_probes_limit);
145 if (KeyValueTrait::IsKeyEqual(pairs_[pair_index], key)) {
146 return &pairs_[pair_index];
147 }
148 }
149 hash_index = (hash_index + 1) & mask;
150 // Hashtable must contain at least one empty marker.
151 ASSERT(hash_index != start);
152 }
153 UNREACHABLE();
154 return nullptr;
155}
#define UNREACHABLE()
Definition assert.h:248

◆ LookupValue()

template<typename KeyValueTrait , typename B , typename Allocator >
KeyValueTrait::Value dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::LookupValue ( typename KeyValueTrait::Key  key) const

Definition at line 159 of file hash_map.h.

160 {
161 const typename KeyValueTrait::Value kNoValue =
162 KeyValueTrait::ValueOf(typename KeyValueTrait::Pair());
163 typename KeyValueTrait::Pair* pair = Lookup(key);
164 return (pair == nullptr) ? kNoValue : KeyValueTrait::ValueOf(*pair);
165}

◆ Remove()

template<typename KeyValueTrait , typename B , typename Allocator >
bool dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::Remove ( typename KeyValueTrait::Key  key)

Definition at line 275 of file hash_map.h.

276 {
277 uword hash = KeyValueTrait::Hash(key);
278 uint32_t mask = hash_table_size_ - 1;
279 uint32_t hash_index = hash & mask;
280 uint32_t start = hash_index;
281 intptr_t probes = 0;
282 for (;;) {
283 uint32_t pair_index = hash_table_[hash_index];
284 if (pair_index == kEmpty) {
285 return false;
286 }
287 if (pair_index != kDeleted) {
288 ASSERT(pair_index < pairs_size_);
289 RELEASE_ASSERT(++probes < FLAG_hash_map_probes_limit);
290 if (KeyValueTrait::IsKeyEqual(pairs_[pair_index], key)) {
291 hash_table_[hash_index] = kDeleted;
292 pairs_[pair_index] = typename KeyValueTrait::Pair();
294 return true;
295 }
296 }
297 hash_index = (hash_index + 1) & mask;
298 // Hashtable must contain at least one empty marker.
299 ASSERT(hash_index != start);
300 }
301 UNREACHABLE();
302 return false;
303}

◆ Resize()

template<typename KeyValueTrait , typename B , typename Allocator >
void dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::Resize ( intptr_t  new_size)
protected

Definition at line 184 of file hash_map.h.

185 {
186 ASSERT(new_size >= Size());
187
188 uint32_t old_hash_table_size = hash_table_size_;
189 // 75% load factor + at least one kEmpty slot
190 hash_table_size_ = Utils::RoundUpToPowerOfTwo(new_size * 4 / 3 + 1);
191 hash_table_ = allocator_->template Realloc<uint32_t>(
192 hash_table_, old_hash_table_size, hash_table_size_);
193 for (uint32_t i = 0; i < hash_table_size_; i++) {
194 hash_table_[i] = kEmpty;
195 }
196
197 typename KeyValueTrait::Pair* old_pairs = pairs_;
198 uint32_t old_pairs_size = pairs_size_;
199 uint32_t old_next_pair_index = next_pair_index_;
200 uint32_t old_deleted_count = deleted_count_;
202 deleted_count_ = 0;
203 pairs_size_ = new_size;
204 pairs_ =
205 allocator_->template Alloc<typename KeyValueTrait::Pair>(pairs_size_);
206 for (uint32_t i = 0; i < pairs_size_; i++) {
207 pairs_[i] = typename KeyValueTrait::Pair();
208 }
209
210 const typename KeyValueTrait::Value kNoValue =
211 KeyValueTrait::ValueOf(typename KeyValueTrait::Pair());
212 uint32_t used = 0;
213 uint32_t deleted = 0;
214 for (uint32_t i = 0; i < old_next_pair_index; i++) {
215 if (KeyValueTrait::ValueOf(old_pairs[i]) == kNoValue) {
216 deleted++;
217 } else {
218 Insert(old_pairs[i]);
219 used++;
220 }
221 }
222 ASSERT_EQUAL(deleted, old_deleted_count);
223 ASSERT_EQUAL(used, old_next_pair_index - old_deleted_count);
225 allocator_->template Free<typename KeyValueTrait::Pair>(old_pairs,
226 old_pairs_size);
227}
#define ASSERT_EQUAL(expected, actual)
Definition assert.h:309
void Insert(typename KeyValueTrait::Pair kv)
Definition hash_map.h:230
static constexpr uintptr_t RoundUpToPowerOfTwo(uintptr_t x)
Definition utils.h:120

◆ Size()

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
intptr_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::Size ( ) const
inline

Definition at line 56 of file hash_map.h.

◆ Update()

template<typename KeyValueTrait , typename B , typename Allocator >
void dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::Update ( typename KeyValueTrait::Pair  kv)

Definition at line 261 of file hash_map.h.

262 {
263 const typename KeyValueTrait::Value kNoValue =
264 KeyValueTrait::ValueOf(typename KeyValueTrait::Pair());
265
266 ASSERT(KeyValueTrait::ValueOf(kv) != kNoValue);
267 if (auto const old_kv = Lookup(KeyValueTrait::KeyOf(kv))) {
268 *old_kv = kv;
269 } else {
270 Insert(kv);
271 }
272}

Member Data Documentation

◆ allocator_

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
Allocator* const dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::allocator_
protected

Definition at line 94 of file hash_map.h.

◆ deleted_count_

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
uint32_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::deleted_count_ = 0
protected

Definition at line 100 of file hash_map.h.

◆ hash_table_

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
uint32_t* dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::hash_table_ = nullptr
protected

Definition at line 95 of file hash_map.h.

◆ hash_table_size_

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
uint32_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::hash_table_size_ = 0
protected

Definition at line 97 of file hash_map.h.

◆ kDeleted

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
constexpr uint32_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::kDeleted = kMaxUint32 - 1
staticconstexprprotected

Definition at line 103 of file hash_map.h.

◆ kEmpty

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
constexpr uint32_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::kEmpty = kMaxUint32
staticconstexprprotected

Definition at line 102 of file hash_map.h.

◆ kInitialSize

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
constexpr intptr_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::kInitialSize = 16
staticconstexprprotected

Definition at line 90 of file hash_map.h.

◆ kMaxPairs

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
constexpr uint32_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::kMaxPairs = kMaxUint32 - 2
staticconstexprprotected

Definition at line 104 of file hash_map.h.

◆ next_pair_index_

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
uint32_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::next_pair_index_ = 0
protected

Definition at line 99 of file hash_map.h.

◆ pairs_

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
KeyValueTrait::Pair* dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::pairs_ = nullptr
protected

Definition at line 96 of file hash_map.h.

◆ pairs_size_

template<typename KeyValueTrait , typename B , typename Allocator = Zone>
uint32_t dart::BaseDirectChainedHashMap< KeyValueTrait, B, Allocator >::pairs_size_ = 0
protected

Definition at line 98 of file hash_map.h.


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