AyStar: Change types used for hashes and queue
Use robin_hood for the hashes Store nodes in PodPools Change BinaryHeap to store node IDs
This commit is contained in:
@@ -25,31 +25,18 @@ const int BinaryHeap::BINARY_HEAP_BLOCKSIZE_MASK = BinaryHeap::BINARY_HEAP_BLOCK
|
||||
|
||||
/**
|
||||
* Clears the queue, by removing all values from it. Its state is
|
||||
* effectively reset. If free_items is true, each of the items cleared
|
||||
* in this way are free()'d.
|
||||
* effectively reset.
|
||||
*/
|
||||
void BinaryHeap::Clear(bool free_values)
|
||||
void BinaryHeap::Clear()
|
||||
{
|
||||
/* Free all items if needed and free all but the first blocks of memory */
|
||||
uint i;
|
||||
uint j;
|
||||
|
||||
for (i = 0; i < this->blocks; i++) {
|
||||
if (this->elements[i] == nullptr) {
|
||||
/* No more allocated blocks */
|
||||
break;
|
||||
}
|
||||
/* For every allocated block */
|
||||
if (free_values) {
|
||||
for (j = 0; j < (1 << BINARY_HEAP_BLOCKSIZE_BITS); j++) {
|
||||
/* For every element in the block */
|
||||
if ((this->size >> BINARY_HEAP_BLOCKSIZE_BITS) == i &&
|
||||
(this->size & BINARY_HEAP_BLOCKSIZE_MASK) == j) {
|
||||
break; // We're past the last element
|
||||
}
|
||||
free(this->elements[i][j].item);
|
||||
}
|
||||
}
|
||||
if (i != 0) {
|
||||
/* Leave the first block of memory alone */
|
||||
free(this->elements[i]);
|
||||
@@ -62,14 +49,13 @@ void BinaryHeap::Clear(bool free_values)
|
||||
|
||||
/**
|
||||
* Frees the queue, by reclaiming all memory allocated by it. After
|
||||
* this it is no longer usable. If free_items is true, any remaining
|
||||
* items are free()'d too.
|
||||
* this it is no longer usable.
|
||||
*/
|
||||
void BinaryHeap::Free(bool free_values)
|
||||
void BinaryHeap::Free()
|
||||
{
|
||||
uint i;
|
||||
|
||||
this->Clear(free_values);
|
||||
this->Clear();
|
||||
for (i = 0; i < this->blocks; i++) {
|
||||
if (this->elements[i] == nullptr) break;
|
||||
free(this->elements[i]);
|
||||
@@ -81,7 +67,7 @@ void BinaryHeap::Free(bool free_values)
|
||||
* Pushes an element into the queue, at the appropriate place for the queue.
|
||||
* Requires the queue pointer to be of an appropriate type, of course.
|
||||
*/
|
||||
bool BinaryHeap::Push(void *item, int priority)
|
||||
bool BinaryHeap::Push(uint32 item, int priority)
|
||||
{
|
||||
if (this->size == this->max_size) return false;
|
||||
dbg_assert(this->size < this->max_size);
|
||||
@@ -130,7 +116,7 @@ bool BinaryHeap::Push(void *item, int priority)
|
||||
* known, which speeds up the deleting for some queue's. Should be -1
|
||||
* if not known.
|
||||
*/
|
||||
bool BinaryHeap::Delete(void *item, int priority)
|
||||
bool BinaryHeap::Delete(uint32 item, int priority)
|
||||
{
|
||||
uint i = 0;
|
||||
|
||||
@@ -189,14 +175,12 @@ bool BinaryHeap::Delete(void *item, int priority)
|
||||
* Pops the first element from the queue. What exactly is the first element,
|
||||
* is defined by the exact type of queue.
|
||||
*/
|
||||
void *BinaryHeap::Pop()
|
||||
uint32 BinaryHeap::Pop()
|
||||
{
|
||||
void *result;
|
||||
|
||||
if (this->size == 0) return nullptr;
|
||||
if (this->size == 0) return UINT32_MAX;
|
||||
|
||||
/* The best item is always on top, so give that as result */
|
||||
result = this->GetElement(1).item;
|
||||
uint32 result = this->GetElement(1).item;
|
||||
/* And now we should get rid of this item... */
|
||||
this->Delete(this->GetElement(1).item, this->GetElement(1).priority);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user