13 #include "../../misc/hashtable.hpp"
14 #include "../../misc/binaryheap.hpp"
21 template <
class Titem_,
int Thash_bits_open_,
int Thash_bits_closed_>
25 typedef typename Titem_::Key
Key;
42 this->new_node =
nullptr;
53 return this->open_nodes.
Count();
59 return this->closed_nodes.
Count();
65 if (this->new_node ==
nullptr) this->new_node = &this->items.emplace_back();
73 if (&item == this->new_node) {
74 this->new_node =
nullptr;
82 assert(this->closed_nodes.
Find(item.GetKey()) ==
nullptr);
83 this->open_nodes.
Push(item);
84 this->open_queue.
Include(&item);
85 if (&item == this->new_node) {
86 this->new_node =
nullptr;
93 if (!this->open_queue.
IsEmpty()) {
94 return this->open_queue.
Begin();
102 if (!this->open_queue.
IsEmpty()) {
103 Titem_ *item = this->open_queue.
Shift();
104 this->open_nodes.
Pop(*item);
113 Titem_ *item = this->open_nodes.
Find(key);
120 Titem_ &item = this->open_nodes.
Pop(key);
121 size_t idxPop = this->open_queue.
FindIndex(item);
122 this->open_queue.
Remove(idxPop);
129 assert(this->open_nodes.
Find(item.GetKey()) ==
nullptr);
130 this->closed_nodes.
Push(item);
136 Titem_ *item = this->closed_nodes.
Find(key);
143 return this->items.Length();
149 return this->items[idx];
153 template <
class D>
void Dump(D &dmp)
const
155 dmp.WriteStructT(
"data", &this->items);
void Remove(size_t index)
Remove item at given index from the priority queue.
T * Begin()
Get the smallest item in the binary tree.
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.
bool IsEmpty() const
Test if the priority queue is empty.
T * Shift()
Remove and return the smallest (and also first) item from the priority queue.
Hash table based node list multi-container class.
CPriorityQueue open_queue
Priority queue of pointers to open item data.
CItemArray items
Here we store full item data (Titem_).
Titem_ & PopOpenNode(const Key &key)
remove and return the open node specified by a key
std::deque< Titem_ > CItemArray
Type that we will use as item container.
int TotalCount()
The number of items.
Titem * new_node
New open node under construction.
Titem_ Titem
Make #Titem_ visible from outside of class.
void InsertOpenNode(Titem_ &item)
insert given item as open node (into m_open and m_open_queue)
~CNodeList_HashTableT()
destructor
int OpenCount()
return number of open nodes
COpenList open_nodes
Hash table of pointers to open item data.
Titem_ * PopBestOpenNode()
remove and return the best open node
HashTable< Titem_, Thash_bits_open_ > COpenList
How pointers to open nodes will be stored.
Titem_ * GetBestOpenNode()
return the best open node
Titem_ & ItemAt(int idx)
Get a particular item.
CClosedList closed_nodes
Hash table of pointers to closed item data.
void Dump(D &dmp) const
Helper for creating output of this array.
Titem_ * FindOpenNode(const Key &key)
return the open node specified by a key or nullptr if not found
void InsertClosedNode(Titem_ &item)
close node
Titem_::Key Key
Make Titem_::Key a property of this class.
Titem_ * FindClosedNode(const Key &key)
return the closed node specified by a key or nullptr if not found
void FoundBestNode(Titem_ &item)
Notify the nodelist that we don't want to discard the given node.
int ClosedCount()
return number of closed nodes
CBinaryHeapT< Titem_ > CPriorityQueue
How the priority queue will be managed.
HashTable< Titem_, Thash_bits_closed_ > CClosedList
How pointers to closed nodes will be stored.
Titem_ * CreateNewNode()
allocate new data item from items
CNodeList_HashTableT()
default constructor
const Titem * Find(const Tkey &key) const
const item search
void Push(Titem &new_item)
add one item - copy it from the given item
int Count() const
item count
Titem & Pop(const Tkey &key)
non-const item search & removal