Pqueue.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //***************************************************************************
  2. //
  3. // PQueue.h -- Prototype for priority queues
  4. //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. #ifndef PQUEUE_H
  9. #define PQUEUE_H
  10. //***************************************************************************
  11. //--------------
  12. // Include Files
  13. //--------------------------------
  14. // Structure and Class Definitions
  15. typedef struct _PQNode {
  16. long key; // sort value
  17. unsigned long id; // hash value for this map position
  18. long row; // HB-specific
  19. long col; // HB-specific
  20. } PQNode;
  21. class PriorityQueue {
  22. protected:
  23. PQNode* pqList;
  24. long maxItems;
  25. long numItems;
  26. long keyMin;
  27. void downHeap (long curIndex);
  28. void upHeap (long curIndex);
  29. public:
  30. void init (void) {
  31. pqList = NULL;
  32. numItems = 0;
  33. }
  34. PriorityQueue (void) {
  35. init();
  36. }
  37. long init (long maxItems, long keyMinValue = -2000000);
  38. long insert (PQNode& item);
  39. void remove (PQNode& item);
  40. void change (long itemIndex, long newValue);
  41. long find (long id);
  42. void clear (void) {
  43. numItems = 0;
  44. }
  45. long getNumItems (void) { return(numItems); }
  46. bool isEmpty (void) {
  47. return(numItems == 0);
  48. }
  49. PQNode* getItem (long itemIndex) {
  50. return(&pqList[itemIndex]);
  51. }
  52. void destroy (void);
  53. ~PriorityQueue (void) {
  54. destroy();
  55. }
  56. };
  57. typedef PriorityQueue* PriorityQueuePtr;
  58. //***************************************************************************
  59. #endif