20template <
class Titem,
int Thash_bits_open,
int Thash_bits_closed>
24 using Key =
typename Titem::Key;
37 this->new_node =
nullptr;
46 return this->open_nodes.
Count();
55 return this->closed_nodes.
Count();
64 return this->items.Length();
73 if (this->new_node ==
nullptr) this->new_node = &this->items.emplace_back();
74 return *this->new_node;
84 if (&item == this->new_node) {
85 this->new_node =
nullptr;
96 assert(this->closed_nodes.
Find(item.GetKey()) ==
nullptr);
97 this->open_nodes.
Push(item);
98 this->open_queue.
Include(&item);
99 if (&item == this->new_node) {
100 this->new_node =
nullptr;
110 if (!this->open_queue.
IsEmpty()) {
111 return this->open_queue.
Begin();
122 if (!this->open_queue.
IsEmpty()) {
123 Titem *item = this->open_queue.
Shift();
124 this->open_nodes.
Pop(*item);
137 return this->open_nodes.
Find(key);
147 Titem &item = this->open_nodes.
Pop(key);
148 size_t index = this->open_queue.
FindIndex(item);
149 this->open_queue.
Remove(index);
159 assert(this->open_nodes.
Find(item.GetKey()) ==
nullptr);
160 this->closed_nodes.
Push(item);
170 return this->closed_nodes.
Find(key);
180 return this->items[index];
190 dmp.WriteStructT(
"data", &this->items);
Binary heap implementation.
Binary Heap as C++ template.
void Remove(size_t index)
Remove item at given index from the priority queue.
void Include(T *new_item)
Insert new item into the priority queue, maintaining heap order.
size_t FindIndex(const T &item) const
Search for an item in the priority queue.
T * Shift()
Remove and return the smallest (and also first) item from the priority queue.
bool IsEmpty() const
Test if the priority queue is empty.
T * Begin()
Get the smallest item in the binary tree.
class HashTable<Titem, HASH_BITS> - simple hash table of pointers allocated elsewhere.
void Push(Titem &new_item)
Add an item that may not exist.
const Titem * Find(const Tkey &key) const
Try to find an item by key.
int Count() const
Get the number of elements.
Titem & Pop(const Tkey &key)
Remove an item by key that must exist.
HashTable< CYapfRailNode, Thash_bits_open > open_nodes
CBinaryHeapT< CYapfRailNode > open_queue
void Dump(D &dmp) const
Helper for creating output of this array.
NodeList()
default constructor
void InsertClosedNode(Titem &item)
Insert the given item into the closed nodes set.
Titem * FindClosedNode(const Key &key)
Find a closed node by its key.
int TotalCount()
Get the total node count.
void InsertOpenNode(Titem &item)
Insert given item as open node (into open_nodes and open_queue).
int OpenCount()
Get open node count.
Titem * PopBestOpenNode()
Remove and return the best open node.
std::deque< CYapfRailNode > items
int ClosedCount()
Get closed node count.
Titem & CreateNewNode()
Allocate new data item from items.
Titem * GetBestOpenNode()
Get the open node at the begin of the open queue.
Titem & ItemAt(int index)
Get a particular item.
Titem & PopOpenNode(const Key &key)
Find and remove an open node by key.
void FoundBestNode(Titem &item)
Notify the nodelist that we don't want to discard the given node.
HashTable< CYapfRailNode, Thash_bits_closed > closed_nodes
Titem * FindOpenNode(const Key &key)
Find an open node by key.