Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.3 KiB

5 years ago
  1. #ifndef __priorityq_sort_h_
  2. #define __priorityq_sort_h_
  3. /*
  4. ** Copyright 1994, Silicon Graphics, Inc.
  5. ** All Rights Reserved.
  6. **
  7. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  8. ** the contents of this file may not be disclosed to third parties, copied or
  9. ** duplicated in any form, in whole or in part, without the prior written
  10. ** permission of Silicon Graphics, Inc.
  11. **
  12. ** RESTRICTED RIGHTS LEGEND:
  13. ** Use, duplication or disclosure by the Government is subject to restrictions
  14. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  15. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  16. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  17. ** rights reserved under the Copyright Laws of the United States.
  18. **
  19. ** Author: Eric Veach, July 1994.
  20. */
  21. #ifdef NT
  22. #include "prq-heap.h"
  23. #else
  24. #include "priorityq-heap.h"
  25. #endif
  26. #undef PQkey
  27. #undef PQhandle
  28. #undef PriorityQ
  29. #undef pqNewPriorityQ
  30. #undef pqDeletePriorityQ
  31. #undef pqInit
  32. #undef pqInsert
  33. #undef pqMinimum
  34. #undef pqExtractMin
  35. #undef pqDelete
  36. #undef pqIsEmpty
  37. /* Use #define's so that another heap implementation can use this one */
  38. #define PQkey PQSortKey
  39. #define PQhandle PQSortHandle
  40. #define PriorityQ PriorityQSort
  41. #define pqNewPriorityQ(leq) __gl_pqSortNewPriorityQ(leq)
  42. #define pqDeletePriorityQ(pq) __gl_pqSortDeletePriorityQ(pq)
  43. /* The basic operations are insertion of a new key (pqInsert),
  44. * and examination/extraction of a key whose value is minimum
  45. * (pqMinimum/pqExtractMin). Deletion is also allowed (pqDelete);
  46. * for this purpose pqInsert returns a "handle" which is supplied
  47. * as the argument.
  48. *
  49. * An initial heap may be created efficiently by calling pqInsert
  50. * repeatedly, then calling pqInit. In any case pqInit must be called
  51. * before any operations other than pqInsert are used.
  52. *
  53. * If the heap is empty, pqMinimum/pqExtractMin will return a NULL key.
  54. * This may also be tested with pqIsEmpty.
  55. */
  56. #define pqInit(pq) __gl_pqSortInit(pq)
  57. #define pqInsert(pq,key) __gl_pqSortInsert(pq,key)
  58. #define pqMinimum(pq) __gl_pqSortMinimum(pq)
  59. #define pqExtractMin(pq) __gl_pqSortExtractMin(pq)
  60. #define pqDelete(pq,handle) __gl_pqSortDelete(pq,handle)
  61. #define pqIsEmpty(pq) __gl_pqSortIsEmpty(pq)
  62. /* Since we support deletion the data structure is a little more
  63. * complicated than an ordinary heap. "nodes" is the heap itself;
  64. * active nodes are stored in the range 1..pq->size. When the
  65. * heap exceeds its allocated size (pq->max), its size doubles.
  66. * The children of node i are nodes 2i and 2i+1.
  67. *
  68. * Each node stores an index into an array "handles". Each handle
  69. * stores a key, plus a pointer back to the node which currently
  70. * represents that key (ie. nodes[handles[i].node].handle == i).
  71. */
  72. typedef PQHeapKey PQkey;
  73. typedef PQHeapHandle PQhandle;
  74. typedef struct PriorityQ PriorityQ;
  75. struct PriorityQ {
  76. PriorityQHeap *heap;
  77. PQkey *keys;
  78. PQkey **order;
  79. PQhandle size, max;
  80. int initialized;
  81. int (*leq)(PQkey key1, PQkey key2);
  82. };
  83. PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) );
  84. void pqDeletePriorityQ( PriorityQ *pq );
  85. void pqInit( PriorityQ *pq );
  86. PQhandle pqInsert( PriorityQ *pq, PQkey key );
  87. PQkey pqExtractMin( PriorityQ *pq );
  88. void pqDelete( PriorityQ *pq, PQhandle handle );
  89. PQkey pqMinimum( PriorityQ *pq );
  90. int pqIsEmpty( PriorityQ *pq );
  91. #endif