iter_heap.h 1.2 KB
Newer Older
1 2 3 4 5
//  Copyright (c) 2013, Facebook, Inc.  All rights reserved.
//  This source code is licensed under the BSD-style license found in the
//  LICENSE file in the root directory of this source tree. An additional grant
//  of patent rights can be found in the PATENTS file in the same directory.
//
6

7
#pragma once
8

9
#include "rocksdb/comparator.h"
10 11
#include "table/iterator_wrapper.h"

12
namespace rocksdb {
13

14 15
// When used with std::priority_queue, this comparison functor puts the
// iterator with the max/largest key on top.
16 17 18 19 20
class MaxIteratorComparator {
 public:
  MaxIteratorComparator(const Comparator* comparator) :
    comparator_(comparator) {}

21 22
  bool operator()(IteratorWrapper* a, IteratorWrapper* b) const {
    return comparator_->Compare(a->key(), b->key()) < 0;
23 24 25 26 27
  }
 private:
  const Comparator* comparator_;
};

28 29
// When used with std::priority_queue, this comparison functor puts the
// iterator with the min/smallest key on top.
30 31 32 33 34
class MinIteratorComparator {
 public:
  MinIteratorComparator(const Comparator* comparator) :
    comparator_(comparator) {}

35
  bool operator()(IteratorWrapper* a, IteratorWrapper* b) const {
36 37 38 39 40 41
    return comparator_->Compare(a->key(), b->key()) > 0;
  }
 private:
  const Comparator* comparator_;
};

42
}  // namespace rocksdb