iter_heap.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. #pragma once
  7. #include "db/dbformat.h"
  8. #include "table/iterator_wrapper.h"
  9. namespace ROCKSDB_NAMESPACE {
  10. // When used with std::priority_queue, this comparison functor puts the
  11. // iterator with the max/largest key on top.
  12. class MaxIteratorComparator {
  13. public:
  14. MaxIteratorComparator(const InternalKeyComparator* comparator)
  15. : comparator_(comparator) {}
  16. bool operator()(IteratorWrapper* a, IteratorWrapper* b) const {
  17. return comparator_->Compare(a->key(), b->key()) < 0;
  18. }
  19. private:
  20. const InternalKeyComparator* comparator_;
  21. };
  22. // When used with std::priority_queue, this comparison functor puts the
  23. // iterator with the min/smallest key on top.
  24. class MinIteratorComparator {
  25. public:
  26. MinIteratorComparator(const InternalKeyComparator* comparator)
  27. : comparator_(comparator) {}
  28. bool operator()(IteratorWrapper* a, IteratorWrapper* b) const {
  29. return comparator_->Compare(a->key(), b->key()) > 0;
  30. }
  31. private:
  32. const InternalKeyComparator* comparator_;
  33. };
  34. } // namespace ROCKSDB_NAMESPACE