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 
7 #pragma once
8 
9 #include "db/dbformat.h"
10 #include "table/iterator_wrapper.h"
11 
12 namespace ROCKSDB_NAMESPACE {
13 
14 // When used with std::priority_queue, this comparison functor puts the
15 // iterator with the max/largest key on top.
16 class MaxIteratorComparator {
17  public:
MaxIteratorComparator(const InternalKeyComparator * comparator)18   MaxIteratorComparator(const InternalKeyComparator* comparator)
19       : comparator_(comparator) {}
20 
operator()21   bool operator()(IteratorWrapper* a, IteratorWrapper* b) const {
22     return comparator_->Compare(a->key(), b->key()) < 0;
23   }
24  private:
25   const InternalKeyComparator* comparator_;
26 };
27 
28 // When used with std::priority_queue, this comparison functor puts the
29 // iterator with the min/smallest key on top.
30 class MinIteratorComparator {
31  public:
MinIteratorComparator(const InternalKeyComparator * comparator)32   MinIteratorComparator(const InternalKeyComparator* comparator)
33       : comparator_(comparator) {}
34 
operator()35   bool operator()(IteratorWrapper* a, IteratorWrapper* b) const {
36     return comparator_->Compare(a->key(), b->key()) > 0;
37   }
38  private:
39   const InternalKeyComparator* comparator_;
40 };
41 
42 }  // namespace ROCKSDB_NAMESPACE
43