is_heap.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. template <class RandomAccessIterator, class Distance>
  14. bool __is_heap(RandomAccessIterator first, RandomAccessIterator last,
  15. Distance*)
  16. {
  17. const Distance n = last - first;
  18. Distance parent = 0;
  19. for (Distance child = 1; child < n; ++child) {
  20. if (first[parent] < first[child])
  21. return false;
  22. if ((child & 1) == 0)
  23. ++parent;
  24. }
  25. return true;
  26. }
  27. template <class RandomAccessIterator>
  28. inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last)
  29. {
  30. return __is_heap(first, last, distance_type(first));
  31. }
  32. template <class RandomAccessIterator, class Distance, class StrictWeakOrdering>
  33. bool __is_heap(RandomAccessIterator first, RandomAccessIterator last,
  34. StrictWeakOrdering comp,
  35. Distance*)
  36. {
  37. const Distance n = last - first;
  38. Distance parent = 0;
  39. for (Distance child = 1; child < n; ++child) {
  40. if (comp(first[parent], first[child]))
  41. return false;
  42. if ((child & 1) == 0)
  43. ++parent;
  44. }
  45. return true;
  46. }
  47. template <class RandomAccessIterator, class StrictWeakOrdering>
  48. inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last,
  49. StrictWeakOrdering comp)
  50. {
  51. return __is_heap(first, last, comp, distance_type(first));
  52. }
  53. }
  54. #endif