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

#include <port_set.h>

Classes

struct  Entry
 
class  Iterator
 

Public Member Functions

 PortSet ()
 
 ~PortSet ()
 
bool IsEmpty () const
 
DART_FORCE_INLINE Iterator begin ()
 
DART_FORCE_INLINE Iterator end ()
 
void Insert (const T &entry)
 
Iterator TryLookup (Dart_Port port)
 
bool Contains (Dart_Port port)
 
void Rebalance ()
 

Static Public Attributes

static constexpr Dart_Port kFreePort = static_cast<Dart_Port>(0)
 
static constexpr Dart_Port kDeletedPort = static_cast<Dart_Port>(3)
 

Detailed Description

template<typename T>
class dart::PortSet< T >

Definition at line 17 of file port_set.h.

Constructor & Destructor Documentation

◆ PortSet()

template<typename T >
dart::PortSet< T >::PortSet ( )
inline

Definition at line 101 of file port_set.h.

101 {
102 const intptr_t kInitialCapacity = 8;
103 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity));
104 map_ = new T[kInitialCapacity];
105 capacity_ = kInitialCapacity;
106 }
static constexpr bool IsPowerOfTwo(T x)
Definition utils.h:61
#define ASSERT(E)
#define T

◆ ~PortSet()

template<typename T >
dart::PortSet< T >::~PortSet ( )
inline

Definition at line 107 of file port_set.h.

107 {
108 delete[] map_;
109 map_ = nullptr;
110 }

Member Function Documentation

◆ begin()

template<typename T >
DART_FORCE_INLINE Iterator dart::PortSet< T >::begin ( )
inline

Definition at line 114 of file port_set.h.

114 {
115 for (intptr_t i = 0; i < capacity_; ++i) {
116 auto& entry = map_[i];
117 if (entry.port != kFreePort && entry.port != kDeletedPort) {
118 return Iterator(this, i);
119 }
120 }
121 return end();
122 }
static constexpr Dart_Port kDeletedPort
Definition port_set.h:20
DART_FORCE_INLINE Iterator end()
Definition port_set.h:124
static constexpr Dart_Port kFreePort
Definition port_set.h:19

◆ Contains()

template<typename T >
bool dart::PortSet< T >::Contains ( Dart_Port  port)
inline

Definition at line 162 of file port_set.h.

162{ return FindIndexOfPort(port) >= 0; }

◆ end()

template<typename T >
DART_FORCE_INLINE Iterator dart::PortSet< T >::end ( )
inline

Definition at line 124 of file port_set.h.

124{ return Iterator(this, capacity_); }

◆ Insert()

template<typename T >
void dart::PortSet< T >::Insert ( const T entry)
inline

Definition at line 126 of file port_set.h.

126 {
127 // Search for the first unused slot. Make use of the knowledge that here is
128 // currently no port with this id in the port map.
129 ASSERT(FindIndexOfPort(entry.port) < 0);
130 intptr_t index = entry.port % capacity_;
131 T cur = map_[index];
132
133 // Stop the search at the first found unused (free or deleted) slot.
134 while (cur.port != kFreePort && cur.port != kDeletedPort) {
135 index = (index + 1) % capacity_;
136 cur = map_[index];
137 }
138
139 // Insert the newly created port at the index.
140 ASSERT(map_[index].port == kFreePort || map_[index].port == kDeletedPort);
141 if (map_[index].port == kDeletedPort) {
142 deleted_--;
143 }
144 map_[index] = entry;
145 ASSERT(FindIndexOfPort(entry.port) >= 0);
146
147 // Increment number of used slots and grow if necessary.
148 used_++;
149 MaintainInvariants();
150
151#if defined(DEBUG)
152 dirty_counter_++;
153#endif
154 }

◆ IsEmpty()

template<typename T >
bool dart::PortSet< T >::IsEmpty ( ) const
inline

Definition at line 112 of file port_set.h.

112{ return used_ == 0; }

◆ Rebalance()

template<typename T >
void dart::PortSet< T >::Rebalance ( )
inline

Definition at line 165 of file port_set.h.

165{ MaintainInvariants(); }

◆ TryLookup()

template<typename T >
Iterator dart::PortSet< T >::TryLookup ( Dart_Port  port)
inline

Definition at line 156 of file port_set.h.

156 {
157 const intptr_t index = FindIndexOfPort(port);
158 if (index >= 0) return Iterator(this, index);
159 return Iterator(this, capacity_);
160 }

Member Data Documentation

◆ kDeletedPort

template<typename T >
constexpr Dart_Port dart::PortSet< T >::kDeletedPort = static_cast<Dart_Port>(3)
staticconstexpr

Definition at line 20 of file port_set.h.

◆ kFreePort

template<typename T >
constexpr Dart_Port dart::PortSet< T >::kFreePort = static_cast<Dart_Port>(0)
staticconstexpr

Definition at line 19 of file port_set.h.


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