heap.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* LIBDGL -- a Directed Graph Library implementation
  2. * Copyright (C) 2002 Roberto Micarelli
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /* best view tabstop=4
  19. */
  20. #ifndef _DGL_HEAP_H_
  21. #define _DGL_HEAP_H_
  22. typedef union _dglHeapData
  23. {
  24. void *pv;
  25. int n;
  26. unsigned int un;
  27. long l;
  28. unsigned long ul;
  29. } dglHeapData_u;
  30. typedef struct _dglHeapNode
  31. {
  32. long key;
  33. dglHeapData_u value;
  34. unsigned char flags;
  35. } dglHeapNode_s;
  36. typedef struct _dglHeap
  37. {
  38. long index; /* last node / number of current nodes (complete-binary-tree array representation ...) */
  39. long count; /* number of allocated nodes in ->pnode array */
  40. long block; /* allocation block size expressed in number of nodes */
  41. dglHeapNode_s *pnode; /* the node-array */
  42. } dglHeap_s;
  43. extern void dglHeapInit(dglHeap_s * pheap);
  44. typedef void (*dglHeapCancelItem_fn) (dglHeap_s * pheap,
  45. dglHeapNode_s * pitem);
  46. extern void dglHeapFree(dglHeap_s * pheap,
  47. dglHeapCancelItem_fn pfnCancelItem);
  48. extern int dglHeapInsertMax(dglHeap_s * pheap,
  49. long key,
  50. unsigned char flags, dglHeapData_u value);
  51. extern int dglHeapExtractMax(dglHeap_s * pheap, dglHeapNode_s * pnoderet);
  52. extern int dglHeapInsertMin(dglHeap_s * pheap,
  53. long key,
  54. unsigned char flags, dglHeapData_u value);
  55. extern int dglHeapExtractMin(dglHeap_s * pheap, dglHeapNode_s * pnoderet);
  56. #endif