pq.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /****************************************************************
  2. *
  3. * MODULE: v.generalize
  4. *
  5. * AUTHOR(S): Daniel Bundala
  6. *
  7. * PURPOSE: priority queue / binary max heap
  8. *
  9. *
  10. * COPYRIGHT: (C) 2002-2005 by the GRASS Development Team
  11. *
  12. * This program is free software under the
  13. * GNU General Public License (>=v2).
  14. * Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. ****************************************************************/
  18. #ifndef PQ_H
  19. #define PQ_H
  20. #include <grass/vector.h>
  21. /* None of the functions below tests overflows,
  22. * only extract_max treats underflow */
  23. typedef struct
  24. {
  25. int items;
  26. double *key;
  27. int *value;
  28. } binary_heap;
  29. /* initializes new empty binary heap. Returns 1
  30. * on success, 0 otherwise */
  31. int binary_heap_init(int size, binary_heap * bh);
  32. /* frees the memory occupied by a heap */
  33. void binary_heap_free(binary_heap * bh);
  34. /* this function pushes (key, value) to the heap */
  35. void binary_heap_push(double key, int value, binary_heap * bh);
  36. /* passes the key of the element with the highest key and
  37. * deletes this key. Returns 1 on success, 0 on empty heap */
  38. int binary_heap_extract_max(binary_heap * bh, int *value);
  39. #endif