Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | List of all members
dart::HashTables Class Reference

#include <hash_table.h>

Inheritance diagram for dart::HashTables:
dart::AllStatic

Static Public Member Functions

template<typename Table >
static Table::Storage::ArrayPtr New (intptr_t initial_capacity, Heap::Space space=Heap::kNew)
 
template<typename Table >
static Table::Storage::ArrayPtr New (const typename Table::Storage::ArrayHandle &array)
 
template<typename From , typename To >
static void Copy (const From &from, const To &to)
 
template<typename Table >
static void EnsureLoadFactor (double high, const Table &table)
 
template<typename Table >
static ArrayPtr ToArray (const Table &table, bool include_payload)
 

Static Public Attributes

static constexpr double kMaxLoadFactor = 0.71
 

Detailed Description

Definition at line 570 of file hash_table.h.

Member Function Documentation

◆ Copy()

template<typename From , typename To >
static void dart::HashTables::Copy ( const From &  from,
const To &  to 
)
inlinestatic

Definition at line 596 of file hash_table.h.

596 {
597 COMPILE_ASSERT(From::kPayloadSize == To::kPayloadSize);
598 to.Initialize();
599 ASSERT(from.NumOccupied() < to.NumEntries());
600 typename From::Iterator it(&from);
601 Object& obj = Object::Handle();
602 while (it.MoveNext()) {
603 intptr_t from_entry = it.Current();
604 obj = from.GetKey(from_entry);
605 intptr_t to_entry = -1;
606 const Object& key = obj;
607 bool present = to.FindKeyOrDeletedOrUnused(key, &to_entry);
608 ASSERT(!present);
609 to.InsertKey(to_entry, obj);
610 for (intptr_t i = 0; i < From::kPayloadSize; ++i) {
611 obj = from.GetPayload(from_entry, i);
612 to.UpdatePayload(to_entry, i, obj);
613 }
614 }
615 }
#define COMPILE_ASSERT(expr)
Definition assert.h:339
static Object & Handle()
Definition object.h:407
#define ASSERT(E)

◆ EnsureLoadFactor()

template<typename Table >
static void dart::HashTables::EnsureLoadFactor ( double  high,
const Table &  table 
)
inlinestatic

Definition at line 620 of file hash_table.h.

620 {
621 // We count deleted elements because they take up space just
622 // like occupied slots in order to cause a rehashing.
623 const double current = (1 + table.NumOccupied() + table.NumDeleted()) /
624 static_cast<double>(table.NumEntries());
625 const bool too_many_deleted = table.NumOccupied() <= table.NumDeleted();
626 if (current < high && !too_many_deleted) {
627 return;
628 }
629
630 table.UpdateWeakDeleted();
631
632 // Normally we double the size here, but if less than half are occupied
633 // then it won't grow (this would imply that there were quite a lot of
634 // deleted slots). We don't want to constantly rehash if we are adding
635 // and deleting entries at just under the load factor limit, so we may
636 // double the size even though the number of occupied slots would not
637 // necessarily justify it. For example if the max load factor is 71% and
638 // the table is 70% full we will double the size to avoid a rehash every
639 // time 1% has been added and deleted.
640 const intptr_t new_capacity = table.NumOccupied() * 2 + 1;
641 ASSERT(table.NumOccupied() == 0 ||
642 ((1.0 + table.NumOccupied()) /
643 Utils::RoundUpToPowerOfTwo(new_capacity)) <= high);
644 Table new_table(New<Table>(new_capacity, // Is rounded up to power of 2.
645 table.data_->IsOld() ? Heap::kOld : Heap::kNew));
646 Copy(table, new_table);
647 Table::Storage::SetHandle(*table.data_, new_table.Release());
648 NOT_IN_PRODUCT(table.UpdateGrowth(); table.PrintStats();)
649 }
SI F table(const skcms_Curve *curve, F v)
static void Copy(const From &from, const To &to)
Definition hash_table.h:596
@ kOld
Definition heap.h:39
static constexpr uintptr_t RoundUpToPowerOfTwo(uintptr_t x)
Definition utils.h:120
#define NOT_IN_PRODUCT(code)
Definition globals.h:84

◆ New() [1/2]

template<typename Table >
static Table::Storage::ArrayPtr dart::HashTables::New ( const typename Table::Storage::ArrayHandle &  array)
inlinestatic

Definition at line 586 of file hash_table.h.

587 {
588 Table table(Thread::Current()->zone(), array.ptr());
589 table.Initialize();
590 return table.Release().ptr();
591 }
static Thread * Current()
Definition thread.h:361

◆ New() [2/2]

template<typename Table >
static Table::Storage::ArrayPtr dart::HashTables::New ( intptr_t  initial_capacity,
Heap::Space  space = Heap::kNew 
)
inlinestatic

Definition at line 574 of file hash_table.h.

575 {
576 auto zone = Thread::Current()->zone();
577 Table table(
578 zone,
579 Table::Storage::New(
580 zone, Table::ArrayLengthForNumOccupied(initial_capacity), space));
581 table.Initialize();
582 return table.Release().ptr();
583 }
Zone * zone() const

◆ ToArray()

template<typename Table >
static ArrayPtr dart::HashTables::ToArray ( const Table &  table,
bool  include_payload 
)
inlinestatic

Definition at line 653 of file hash_table.h.

653 {
654 const intptr_t entry_size = include_payload ? (1 + Table::kPayloadSize) : 1;
655 Array& result = Array::Handle(Array::New(table.NumOccupied() * entry_size));
656 typename Table::Iterator it(&table);
657 Object& obj = Object::Handle();
658 intptr_t result_index = 0;
659 while (it.MoveNext()) {
660 intptr_t entry = it.Current();
661 obj = table.GetKey(entry);
662 result.SetAt(result_index++, obj);
663 if (include_payload) {
664 for (intptr_t i = 0; i < Table::kPayloadSize; ++i) {
665 obj = table.GetPayload(entry, i);
666 result.SetAt(result_index++, obj);
667 }
668 }
669 }
670 return result.ptr();
671 }
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition object.h:10933
GAsyncResult * result

Member Data Documentation

◆ kMaxLoadFactor

constexpr double dart::HashTables::kMaxLoadFactor = 0.71
staticconstexpr

Definition at line 617 of file hash_table.h.


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