_heap.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. *
  3. * Copyright (c) 1994
  4. * Hewlett-Packard Company
  5. *
  6. * Permission to use, copy, modify, distribute and sell this software
  7. * and its documentation for any purpose is hereby granted without fee,
  8. * provided that the above copyright notice appear in all copies and
  9. * that both that copyright notice and this permission notice appear
  10. * in supporting documentation. Hewlett-Packard Company makes no
  11. * representations about the suitability of this software for any
  12. * purpose. It is provided "as is" without express or implied warranty.
  13. *
  14. * Copyright (c) 1997
  15. * Silicon Graphics Computer Systems, Inc.
  16. *
  17. * Permission to use, copy, modify, distribute and sell this software
  18. * and its documentation for any purpose is hereby granted without fee,
  19. * provided that the above copyright notice appear in all copies and
  20. * that both that copyright notice and this permission notice appear
  21. * in supporting documentation. Silicon Graphics makes no
  22. * representations about the suitability of this software for any
  23. * purpose. It is provided "as is" without express or implied warranty.
  24. */
  25. /* NOTE: This is an internal header file, included by other STL headers.
  26. * You should not attempt to use it directly.
  27. */
  28. #ifndef _STLP_INTERNAL_HEAP_H
  29. #define _STLP_INTERNAL_HEAP_H
  30. _STLP_BEGIN_NAMESPACE
  31. // Heap-manipulation functions: push_heap, pop_heap, make_heap, sort_heap.
  32. template <class _RandomAccessIterator>
  33. void
  34. push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last);
  35. template <class _RandomAccessIterator, class _Compare>
  36. void
  37. push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
  38. _Compare __comp);
  39. template <class _RandomAccessIterator, class _Distance, class _Tp>
  40. void
  41. __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
  42. _Distance __len, _Tp __val);
  43. template <class _RandomAccessIterator, class _Tp, class _Distance>
  44. inline void
  45. __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
  46. _RandomAccessIterator __result, _Tp __val, _Distance*)
  47. {
  48. *__result = *__first;
  49. __adjust_heap(__first, _Distance(0), _Distance(__last - __first), __val);
  50. }
  51. template <class _RandomAccessIterator>
  52. void pop_heap(_RandomAccessIterator __first,
  53. _RandomAccessIterator __last);
  54. template <class _RandomAccessIterator, class _Distance,
  55. class _Tp, class _Compare>
  56. void
  57. __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
  58. _Distance __len, _Tp __val, _Compare __comp);
  59. template <class _RandomAccessIterator, class _Tp, class _Compare,
  60. class _Distance>
  61. inline void
  62. __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
  63. _RandomAccessIterator __result, _Tp __val, _Compare __comp,
  64. _Distance*)
  65. {
  66. *__result = *__first;
  67. __adjust_heap(__first, _Distance(0), _Distance(__last - __first),
  68. __val, __comp);
  69. }
  70. template <class _RandomAccessIterator, class _Compare>
  71. void
  72. pop_heap(_RandomAccessIterator __first,
  73. _RandomAccessIterator __last, _Compare __comp);
  74. template <class _RandomAccessIterator>
  75. void
  76. make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last);
  77. template <class _RandomAccessIterator, class _Compare>
  78. void
  79. make_heap(_RandomAccessIterator __first,
  80. _RandomAccessIterator __last, _Compare __comp);
  81. template <class _RandomAccessIterator>
  82. _STLP_INLINE_LOOP
  83. void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
  84. {
  85. while (__last - __first > 1)
  86. pop_heap(__first, __last--);
  87. }
  88. template <class _RandomAccessIterator, class _Compare>
  89. _STLP_INLINE_LOOP
  90. void
  91. sort_heap(_RandomAccessIterator __first,
  92. _RandomAccessIterator __last, _Compare __comp)
  93. {
  94. while (__last - __first > 1)
  95. pop_heap(__first, __last--, __comp);
  96. }
  97. _STLP_END_NAMESPACE
  98. # if !defined (_STLP_LINK_TIME_INSTANTIATION)
  99. # include <stl/_heap.c>
  100. # endif
  101. #endif /* _STLP_INTERNAL_HEAP_H */
  102. // Local Variables:
  103. // mode:C++
  104. // End: