Crossfire Server, Trunk  1.75.0
minheap.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MinHeap
 In order to adequately path for A* search, we will need a minheap to efficiently handle pathing from the lowest cost to our destination. More...
 

Functions

void minheap_free (MinHeap *to_free)
 Cleans the minheap. More...
 
MinHeapminheap_init (int amt, int(*measure_func)(const void *), void(*cleanup_func)(void *))
 Function to intialize the minheap. More...
 
void minheap_init_static (MinHeap *heap, void **arr, int amt, int(*measure_func)(const void *))
 Initialize the minheap using statically allocated components. More...
 
int minheap_insert (MinHeap *heap, void *ob)
 Inserts an element into the min-heap. More...
 
void * minheap_remove (MinHeap *heap)
 Pops the top of the minheap off. More...
 

Function Documentation

◆ minheap_free()

void minheap_free ( MinHeap to_free)

Cleans the minheap.

Parameters
to_freeThe minheap to free.

Definition at line 226 of file minheap.cpp.

References MinHeap::arr, MinHeap::element_cleanup, and MinHeap::len.

◆ minheap_init()

MinHeap* minheap_init ( int  amt,
int(*)(const void *)  measure_func,
void(*)(void *)  cleanup_func 
)

Function to intialize the minheap.

Parameters
amtThe capacity of the min-heap.
measure_funcPointer to the function to measure the data we're storing.
cleanup_funcPointer to a given element's cleanup function. Can be NULL if the data does not need to be cleaned up for any reason.
Returns
Pointer to the allocated min-heap. Errors out if allocation fails.

Definition at line 129 of file minheap.cpp.

References MinHeap::arr, MinHeap::capacity, MinHeap::element_cleanup, fatal(), MinHeap::get_measure, MinHeap::len, and OUT_OF_MEMORY.

+ Here is the call graph for this function:

◆ minheap_init_static()

void minheap_init_static ( MinHeap heap,
void **  arr,
int  amt,
int(*)(const void *)  measure_func 
)

Initialize the minheap using statically allocated components.

It is expected the caller will do any necessary cleanup on data before the components fall out of scope.

It is also expected that the caller ensured arr can hold amt elements.

Parameters
heapPointer to the heap we are initializing.
arrPointer to the array of elements we are using.
amtThe capacity of the heap
measure_funcPointer to the function that gives the calculation the minheap uses to organize elements.

Definition at line 162 of file minheap.cpp.

References MinHeap::arr, MinHeap::capacity, MinHeap::element_cleanup, MinHeap::get_measure, and MinHeap::len.

Referenced by monster_compute_path().

+ Here is the caller graph for this function:

◆ minheap_insert()

int minheap_insert ( MinHeap heap,
void *  ob 
)

Inserts an element into the min-heap.

Parameters
heapHeap to insert into.
obThe data object being inserted.
Returns
0 if successful, -1 if the heap is already full.

Definition at line 184 of file minheap.cpp.

References MinHeap::arr, MinHeap::capacity, MinHeap::len, minheap_get_parent(), and minheap_normalize().

Referenced by monster_compute_path().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minheap_remove()

void* minheap_remove ( MinHeap heap)

Pops the top of the minheap off.

Parameters
heapHeap to pop from.
Returns
The popped element, or NULL if the heap is empty.

Definition at line 209 of file minheap.cpp.

References MinHeap::arr, MinHeap::len, and minheap_normalize().

Referenced by monster_compute_path().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: