#ifndef HEAP_H #define HEAP_H /* * Copyright (c) Alex Holden 2000. * * This code is public domain; you can do whatever you want with it, though I * would prefer you to contribute any bug fixes back to me if possible. * This software comes with NO WARRANTY WHATSOEVER, not even the implied * warranties of merchantability and fitness for a particular purpose. */ typedef int(*heap_comparefunc)(void *, void *); typedef struct { int size; /* Total size of heap array */ int nodes; /* Number of nodes in heap */ heap_comparefunc cmp; /* Node compare callback function */ void **hp; /* The heap array itself */ } heap; extern heap *heap_init(int size, heap_comparefunc cmp); /* Create a new heap */ extern void heap_destroy(heap *hp, int freenodes); /* Destroy a heap */ extern int heap_add_node(heap *hp, void *node); /* Add node to a heap */ extern void *heap_remove_node(heap *hp); /* Get the top node from a heap */ extern void heap_reorder(heap *hp); /* Reorder heap */ #define heap_nodes(A) ((A)->nodes) /* Find number of nodes in heap */ #define heap_clear(A) ((A)->nodes = 0) /* Clear a heap without destroying it */ #endif