DHART
|
A queue that remembers every object inserted, and prevents the addition of nodes that have already been inserted even if they've been popped. More...
#include <unique_queue.h>
Public Member Functions | |
bool | push (const HF::SpatialStructures::Node &p) |
Add a node to the queue if it has never previously been in the queue. More... | |
HF::SpatialStructures::Node | pop () |
Remove the topmost node from the queue and return it. More... | |
int | size () const |
Determine how many nodes are currently in the queue. More... | |
HF::SpatialStructures::Node | popFromDict () |
Retrieve the topmost node from the queue, but "forget" about it to allow it to enter again in the future. More... | |
bool | hasNode (const HF::SpatialStructures::Node &p) const |
Check to see if the node has ever been in the queue. More... | |
bool | forcePush (const HF::SpatialStructures::Node &p) |
Forcibly push a node onto the queue without checking it. Saves a hash function, but risks breaking the invariant. More... | |
bool | empty () const |
Tell if the queue is empty. More... | |
void | clearQueue () |
Clear every node from the queue without forgetting them. More... | |
std::vector< SpatialStructures::Node > | popMany (int max=-1) |
Pop a set amount of nodes from the queue, and return them as a vector. More... | |
template<typename arr_type > | |
bool | PushAny (const arr_type &node) |
Call push with any type of object. More... | |
Private Attributes | |
std::queue< HF::SpatialStructures::Node > | node_queue |
The underlying queue. More... | |
robin_hood::unordered_map< HF::SpatialStructures::Node, int > | hashmap |
Hashmap to keep track of nodes that have entered the queue. More... | |
A queue that remembers every object inserted, and prevents the addition of nodes that have already been inserted even if they've been popped.
Definition at line 29 of file unique_queue.h.
void HF::GraphGenerator::UniqueQueue::clearQueue | ( | ) |
Clear every node from the queue without forgetting them.
Definition at line 57 of file unique_queue.cpp.
References node_queue.
bool HF::GraphGenerator::UniqueQueue::empty | ( | ) | const |
Tell if the queue is empty.
Definition at line 55 of file unique_queue.cpp.
References size().
Referenced by HF::GraphGenerator::GraphGenerator::CrawlGeom(), and HF::GraphGenerator::GraphGenerator::CrawlGeomParallel().
bool HF::GraphGenerator::UniqueQueue::forcePush | ( | const HF::SpatialStructures::Node & | p | ) |
Forcibly push a node onto the queue without checking it. Saves a hash function, but risks breaking the invariant.
p | Node to add to the end of the queue. |
Definition at line 47 of file unique_queue.cpp.
References node_queue.
bool HF::GraphGenerator::UniqueQueue::hasNode | ( | const HF::SpatialStructures::Node & | p | ) | const |
Check to see if the node has ever been in the queue.
p | Node to check. |
Definition at line 43 of file unique_queue.cpp.
HF::SpatialStructures::Node HF::GraphGenerator::UniqueQueue::pop | ( | ) |
Remove the topmost node from the queue and return it.
Definition at line 25 of file unique_queue.cpp.
References node_queue.
Referenced by HF::GraphGenerator::GraphGenerator::CrawlGeom(), and popMany().
HF::SpatialStructures::Node HF::GraphGenerator::UniqueQueue::popFromDict | ( | ) |
Retrieve the topmost node from the queue, but "forget" about it to allow it to enter again in the future.
This sets the node's value to 0 in the hashmap, making it behave exactly like a node that has never been seen by the queue.
Definition at line 34 of file unique_queue.cpp.
References node_queue.
std::vector< SpatialStructures::Node > HF::GraphGenerator::UniqueQueue::popMany | ( | int | max = -1 | ) |
Pop a set amount of nodes from the queue, and return them as a vector.
max | Stop after popping this amount of nodes. |
Use this to quickly pop several nodes without having to make a function call for each.
Definition at line 64 of file unique_queue.cpp.
References node_queue, pop(), and size().
Referenced by HF::GraphGenerator::GraphGenerator::CrawlGeomParallel().
bool HF::GraphGenerator::UniqueQueue::push | ( | const HF::SpatialStructures::Node & | p | ) |
Add a node to the queue if it has never previously been in the queue.
p | Node to add to the queue. |
If the node has a value of 1 in hashmap, then the node is ignored. If the node doesn't already exist in the hashmap, the call to hashmap[p] will automatically create an entry with a value of 0, indicating that the node hasn't been seen before.
Definition at line 11 of file unique_queue.cpp.
References node_queue.
Referenced by HF::GraphGenerator::GraphGenerator::CrawlGeomParallel(), and PushAny().
|
inline |
Call push with any type of object.
p | Node to add to the queue. |
If the node has a value of 1 in hashmap, then the node is ignored. If the node doesn't already exist in the hashmap, the call to hashmap[p] will automatically create an entry with a value of 0, indicating that the node hasn't been seen before.
Definition at line 118 of file unique_queue.h.
References push().
Referenced by HF::GraphGenerator::GraphGenerator::CrawlGeom(), and HF::GraphGenerator::GraphGenerator::IMPL_BuildNetwork().
int HF::GraphGenerator::UniqueQueue::size | ( | ) | const |
Determine how many nodes are currently in the queue.
Definition at line 32 of file unique_queue.cpp.
References node_queue.
Referenced by HF::GraphGenerator::GraphGenerator::CrawlGeomParallel(), empty(), and popMany().
|
private |
Hashmap to keep track of nodes that have entered the queue.
Values of 0 indicate that a node has never been pushed before. Values of 1 indicate that a node has already been in the hashmap previously.
Definition at line 38 of file unique_queue.h.
|
private |
The underlying queue.
Definition at line 31 of file unique_queue.h.
Referenced by clearQueue(), forcePush(), pop(), popFromDict(), popMany(), push(), and size().