libtcod
Loading...
Searching...
No Matches
heapq.h File Reference

Internal heap queue module. More...

#include <stdbool.h>
#include <stddef.h>
#include "config.h"

Go to the source code of this file.

Classes

struct  TCOD_Heap
 

Functions

int TCOD_heap_init (struct TCOD_Heap *heap, size_t data_size)
 Initialize a heap with the given data_size.
 
void TCOD_heap_uninit (struct TCOD_Heap *heap)
 Clear a heap and free its data.
 
void TCOD_heap_clear (struct TCOD_Heap *heap)
 Clear all elements from this heap.
 
int TCOD_minheap_push (struct TCOD_Heap *minheap, int priority, const void *data)
 Push an element onto this minumum heap.
 
void TCOD_minheap_pop (struct TCOD_Heap *minheap, void *out)
 Remove the smallest element from the heap and keep it sorted.
 
void TCOD_minheap_heapify (struct TCOD_Heap *minheap)
 Sort the heap elements into a valid heap.
 

Detailed Description

Internal heap queue module.

Function Documentation

◆ TCOD_heap_clear()

void TCOD_heap_clear ( struct TCOD_Heap * heap)

Clear all elements from this heap.

Parameters
heapA TCOD_Heap pointer.

◆ TCOD_heap_init()

int TCOD_heap_init ( struct TCOD_Heap * heap,
size_t data_size )

Initialize a heap with the given data_size.

Parameters
heapA pointer to an existing TCOD_Heap struct.
data_sizeThe size of the user data in bytes.
Returns
int Returns a negative value on error.

◆ TCOD_heap_uninit()

void TCOD_heap_uninit ( struct TCOD_Heap * heap)

Clear a heap and free its data.

Parameters
heapA pointer to a TCOD_Heap struct, the struct itself is not freed.

◆ TCOD_minheap_heapify()

void TCOD_minheap_heapify ( struct TCOD_Heap * minheap)

Sort the heap elements into a valid heap.

Parameters
minheapA TCOD_Heap pointer.

◆ TCOD_minheap_pop()

void TCOD_minheap_pop ( struct TCOD_Heap * minheap,
void * out )

Remove the smallest element from the heap and keep it sorted.

Parameters
minheapA TCOD_Heap pointer.
outAn optional pointer to store the data from the removed element.

◆ TCOD_minheap_push()

int TCOD_minheap_push ( struct TCOD_Heap * minheap,
int priority,
const void * data )

Push an element onto this minumum heap.

Parameters
minheapA TCOD_Heap pointer.
priorityThe priority of the new element.
dataThe data to push onto the heap. Can not be NULL.
Returns
Returns a negative error code on failures.