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.

92 lines
3.2 KiB

5 years ago
  1. #ifndef __priorityq_heap_h_
  2. #define __priorityq_heap_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. /* Use #define's so that another heap implementation can use this one */
  22. #define PQkey PQHeapKey
  23. #define PQhandle PQHeapHandle
  24. #define PriorityQ PriorityQHeap
  25. #define pqNewPriorityQ(leq) __gl_pqHeapNewPriorityQ(leq)
  26. #define pqDeletePriorityQ(pq) __gl_pqHeapDeletePriorityQ(pq)
  27. /* The basic operations are insertion of a new key (pqInsert),
  28. * and examination/extraction of a key whose value is minimum
  29. * (pqMinimum/pqExtractMin). Deletion is also allowed (pqDelete);
  30. * for this purpose pqInsert returns a "handle" which is supplied
  31. * as the argument.
  32. *
  33. * An initial heap may be created efficiently by calling pqInsert
  34. * repeatedly, then calling pqInit. In any case pqInit must be called
  35. * before any operations other than pqInsert are used.
  36. *
  37. * If the heap is empty, pqMinimum/pqExtractMin will return a NULL key.
  38. * This may also be tested with pqIsEmpty.
  39. */
  40. #define pqInit(pq) __gl_pqHeapInit(pq)
  41. #define pqInsert(pq,key) __gl_pqHeapInsert(pq,key)
  42. #define pqMinimum(pq) __gl_pqHeapMinimum(pq)
  43. #define pqExtractMin(pq) __gl_pqHeapExtractMin(pq)
  44. #define pqDelete(pq,handle) __gl_pqHeapDelete(pq,handle)
  45. #define pqIsEmpty(pq) __gl_pqHeapIsEmpty(pq)
  46. /* Since we support deletion the data structure is a little more
  47. * complicated than an ordinary heap. "nodes" is the heap itself;
  48. * active nodes are stored in the range 1..pq->size. When the
  49. * heap exceeds its allocated size (pq->max), its size doubles.
  50. * The children of node i are nodes 2i and 2i+1.
  51. *
  52. * Each node stores an index into an array "handles". Each handle
  53. * stores a key, plus a pointer back to the node which currently
  54. * represents that key (ie. nodes[handles[i].node].handle == i).
  55. */
  56. typedef void *PQkey;
  57. typedef long PQhandle;
  58. typedef struct PriorityQ PriorityQ;
  59. typedef struct { PQhandle handle; } PQnode;
  60. typedef struct { PQkey key; PQhandle node; } PQhandleElem;
  61. struct PriorityQ {
  62. PQnode *nodes;
  63. PQhandleElem *handles;
  64. long size, max;
  65. PQhandle freeList;
  66. int initialized;
  67. int (*leq)(PQkey key1, PQkey key2);
  68. };
  69. PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) );
  70. void pqDeletePriorityQ( PriorityQ *pq );
  71. void pqInit( PriorityQ *pq );
  72. PQhandle pqInsert( PriorityQ *pq, PQkey key );
  73. PQkey pqExtractMin( PriorityQ *pq );
  74. void pqDelete( PriorityQ *pq, PQhandle handle );
  75. #define __gl_pqHeapMinimum(pq) ((pq)->handles[(pq)->nodes[1].handle].key)
  76. #define __gl_pqHeapIsEmpty(pq) ((pq)->size == 0)
  77. #endif