is_heap.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. //=======================================================================
  3. // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
  4. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
  5. //
  6. // Distributed under the Boost Software License, Version 1.0. (See
  7. // accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //=======================================================================
  10. //
  11. #if __KCC
  12. namespace std
  13. {
  14. template < class RandomAccessIterator, class Distance >
  15. bool __is_heap(RandomAccessIterator first, RandomAccessIterator last, Distance*)
  16. {
  17. const Distance n = last - first;
  18. Distance parent = 0;
  19. for (Distance child = 1; child < n; ++child)
  20. {
  21. if (first[parent] < first[child])
  22. return false;
  23. if ((child & 1) == 0)
  24. ++parent;
  25. }
  26. return true;
  27. }
  28. template < class RandomAccessIterator >
  29. inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last)
  30. {
  31. return __is_heap(first, last, distance_type(first));
  32. }
  33. template < class RandomAccessIterator, class Distance,
  34. class StrictWeakOrdering >
  35. bool __is_heap(RandomAccessIterator first, RandomAccessIterator last,
  36. StrictWeakOrdering comp, Distance*)
  37. {
  38. const Distance n = last - first;
  39. Distance parent = 0;
  40. for (Distance child = 1; child < n; ++child)
  41. {
  42. if (comp(first[parent], first[child]))
  43. return false;
  44. if ((child & 1) == 0)
  45. ++parent;
  46. }
  47. return true;
  48. }
  49. template < class RandomAccessIterator, class StrictWeakOrdering >
  50. inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last,
  51. StrictWeakOrdering comp)
  52. {
  53. return __is_heap(first, last, comp, distance_type(first));
  54. }
  55. }
  56. #endif