Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | List of all members
dart::PriorityQueue< P, V > Class Template Reference

#include <priority_queue.h>

Classes

struct  Entry
 

Public Member Functions

 PriorityQueue ()
 
 ~PriorityQueue ()
 
bool IsEmpty () const
 
void Insert (const P &priority, const V &value)
 
const EntryMinimum () const
 
void RemoveMinimum ()
 
bool RemoveByValue (const V &value)
 
bool ContainsValue (const V &value)
 
bool InsertOrChangePriority (const P &priority, const V &value)
 

Static Public Attributes

static constexpr intptr_t kMinimumSize = 16
 

Detailed Description

template<typename P, typename V>
class dart::PriorityQueue< P, V >

Definition at line 25 of file priority_queue.h.

Constructor & Destructor Documentation

◆ PriorityQueue()

template<typename P , typename V >
dart::PriorityQueue< P, V >::PriorityQueue ( )
inline

Definition at line 34 of file priority_queue.h.

34 : hashmap_(&MatchFun, kMinimumSize) {
35 min_heap_size_ = kMinimumSize;
36 min_heap_ =
37 reinterpret_cast<Entry*>(malloc(sizeof(Entry) * min_heap_size_));
38 if (min_heap_ == nullptr) FATAL("Cannot allocate memory.");
39 size_ = 0;
40 }
static constexpr intptr_t kMinimumSize
#define FATAL(error)
void * malloc(size_t size)
Definition allocation.cc:19

◆ ~PriorityQueue()

template<typename P , typename V >
dart::PriorityQueue< P, V >::~PriorityQueue ( )
inline

Definition at line 42 of file priority_queue.h.

42{ free(min_heap_); }

Member Function Documentation

◆ ContainsValue()

template<typename P , typename V >
bool dart::PriorityQueue< P, V >::ContainsValue ( const V value)
inline

Definition at line 92 of file priority_queue.h.

92{ return FindMapEntry(value) != nullptr; }

◆ Insert()

template<typename P , typename V >
void dart::PriorityQueue< P, V >::Insert ( const P &  priority,
const V value 
)
inline

Definition at line 49 of file priority_queue.h.

49 {
50 ASSERT(!ContainsValue(value));
51
52 if (size_ == min_heap_size_) {
53 Resize(min_heap_size_ << 1);
54 }
55
56 Set(size_, {priority, value});
57 BubbleUp(size_);
58
59 size_++;
60 }
bool ContainsValue(const V &value)
#define ASSERT(E)
uint8_t value

◆ InsertOrChangePriority()

template<typename P , typename V >
bool dart::PriorityQueue< P, V >::InsertOrChangePriority ( const P &  priority,
const V value 
)
inline

Definition at line 96 of file priority_queue.h.

96 {
97 auto map_entry = FindMapEntry(value);
98 if (map_entry == nullptr) {
99 Insert(priority, value);
100 return true;
101 }
102
103 const intptr_t offset = ValueOfMapEntry(map_entry);
104 ASSERT(offset < size_);
105
106 Entry& entry = min_heap_[offset];
107 entry.priority = priority;
108 if (offset == 0) {
109 BubbleDown(offset);
110 } else {
111 intptr_t parent = (offset - 1) / 2;
112 intptr_t diff = entry.priority - min_heap_[parent].priority;
113 if (diff < 0) {
114 BubbleUp(offset);
115 } else if (diff > 0) {
116 BubbleDown(offset);
117 }
118 }
119 return false;
120 }
void Insert(const P &priority, const V &value)
Point offset

◆ IsEmpty()

template<typename P , typename V >
bool dart::PriorityQueue< P, V >::IsEmpty ( ) const
inline

Definition at line 45 of file priority_queue.h.

45{ return size_ == 0; }

◆ Minimum()

template<typename P , typename V >
const Entry & dart::PriorityQueue< P, V >::Minimum ( ) const
inline

Definition at line 65 of file priority_queue.h.

65 {
66 ASSERT(!IsEmpty());
67 return min_heap_[0];
68 }

◆ RemoveByValue()

template<typename P , typename V >
bool dart::PriorityQueue< P, V >::RemoveByValue ( const V value)
inline

Definition at line 79 of file priority_queue.h.

79 {
80 auto entry = FindMapEntry(value);
81 if (entry != nullptr) {
82 const intptr_t offset = ValueOfMapEntry(entry);
83 RemoveAt(offset);
84
85 ASSERT(hashmap_.size() == size_);
86 return true;
87 }
88 return false;
89 }
intptr_t size() const
Definition hashmap.h:74

◆ RemoveMinimum()

template<typename P , typename V >
void dart::PriorityQueue< P, V >::RemoveMinimum ( )
inline

Definition at line 71 of file priority_queue.h.

71 {
72 ASSERT(!IsEmpty());
73 RemoveAt(0);
74 }

Member Data Documentation

◆ kMinimumSize

template<typename P , typename V >
constexpr intptr_t dart::PriorityQueue< P, V >::kMinimumSize = 16
staticconstexpr

Definition at line 27 of file priority_queue.h.


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