mirror of https://github.com/OpenTTD/OpenTTD
(svn r20686) -Codechange: Make init_BinaryHeap() a method.
parent
2c962548e5
commit
bc6a5a5e64
|
@ -296,7 +296,7 @@ void init_AyStar(AyStar *aystar, Hash_HashProc hash, uint num_buckets)
|
||||||
* BinaryHeap allocates a block of 1024 nodes
|
* BinaryHeap allocates a block of 1024 nodes
|
||||||
* When that one gets full it reserves another one, till this number
|
* When that one gets full it reserves another one, till this number
|
||||||
* That is why it can stay this high */
|
* That is why it can stay this high */
|
||||||
init_BinaryHeap(&aystar->OpenListQueue, 102400);
|
aystar->OpenListQueue.Init(102400);
|
||||||
|
|
||||||
aystar->addstart = AyStarMain_AddStartNode;
|
aystar->addstart = AyStarMain_AddStartNode;
|
||||||
aystar->main = AyStarMain_Main;
|
aystar->main = AyStarMain_Main;
|
||||||
|
|
|
@ -225,16 +225,19 @@ void *Queue::Pop()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_BinaryHeap(Queue *q, uint max_size)
|
/**
|
||||||
|
* Initializes a binary heap and allocates internal memory for maximum of
|
||||||
|
* max_size elements
|
||||||
|
*/
|
||||||
|
void Queue::Init(uint max_size)
|
||||||
{
|
{
|
||||||
assert(q != NULL);
|
this->max_size = max_size;
|
||||||
q->max_size = max_size;
|
this->size = 0;
|
||||||
q->size = 0;
|
|
||||||
/* We malloc memory in block of BINARY_HEAP_BLOCKSIZE
|
/* We malloc memory in block of BINARY_HEAP_BLOCKSIZE
|
||||||
* It autosizes when it runs out of memory */
|
* It autosizes when it runs out of memory */
|
||||||
q->elements = CallocT<BinaryHeapNode*>((max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1);
|
this->elements = CallocT<BinaryHeapNode*>((max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1);
|
||||||
q->elements[0] = MallocT<BinaryHeapNode>(BINARY_HEAP_BLOCKSIZE);
|
this->elements[0] = MallocT<BinaryHeapNode>(BINARY_HEAP_BLOCKSIZE);
|
||||||
q->blocks = 1;
|
this->blocks = 1;
|
||||||
#ifdef QUEUE_DEBUG
|
#ifdef QUEUE_DEBUG
|
||||||
printf("[BinaryHeap] Initial size of elements is %d nodes\n", BINARY_HEAP_BLOCKSIZE);
|
printf("[BinaryHeap] Initial size of elements is %d nodes\n", BINARY_HEAP_BLOCKSIZE);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,7 +24,14 @@ struct BinaryHeapNode {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Binary Heap
|
||||||
|
* For information, see:
|
||||||
|
* http://www.policyalmanac.org/games/binaryHeaps.htm
|
||||||
|
*/
|
||||||
struct Queue {
|
struct Queue {
|
||||||
|
void Init(uint max_size);
|
||||||
|
|
||||||
bool Push(void *item, int priority);
|
bool Push(void *item, int priority);
|
||||||
void *Pop();
|
void *Pop();
|
||||||
bool Delete(void *item, int priority);
|
bool Delete(void *item, int priority);
|
||||||
|
@ -37,22 +44,9 @@ struct Queue {
|
||||||
BinaryHeapNode **elements;
|
BinaryHeapNode **elements;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Binary Heap
|
|
||||||
* For information, see:
|
|
||||||
* http://www.policyalmanac.org/games/binaryHeaps.htm
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* The amount of elements that will be malloc'd at a time */
|
/* The amount of elements that will be malloc'd at a time */
|
||||||
#define BINARY_HEAP_BLOCKSIZE_BITS 10
|
#define BINARY_HEAP_BLOCKSIZE_BITS 10
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a binary heap and allocates internal memory for maximum of
|
|
||||||
* max_size elements
|
|
||||||
*/
|
|
||||||
void init_BinaryHeap(Queue *q, uint max_size);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hash
|
* Hash
|
||||||
|
|
Loading…
Reference in New Issue