]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/util/user_comparator_wrapper.h
bump version to 15.2.11-pve1
[ceph.git] / ceph / src / rocksdb / util / user_comparator_wrapper.h
CommitLineData
494da23a
TL
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// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
6// Use of this source code is governed by a BSD-style license that can be
7// found in the LICENSE file. See the AUTHORS file for names of contributors.
8
9#pragma once
10
11#include "monitoring/perf_context_imp.h"
12#include "rocksdb/comparator.h"
13
14namespace rocksdb {
15
16// Wrapper of user comparator, with auto increment to
17// perf_context.user_key_comparison_count.
18class UserComparatorWrapper final : public Comparator {
19 public:
20 explicit UserComparatorWrapper(const Comparator* const user_cmp)
21 : user_comparator_(user_cmp) {}
22
23 ~UserComparatorWrapper() = default;
24
25 const Comparator* user_comparator() const { return user_comparator_; }
26
27 int Compare(const Slice& a, const Slice& b) const override {
28 PERF_COUNTER_ADD(user_key_comparison_count, 1);
29 return user_comparator_->Compare(a, b);
30 }
31
32 bool Equal(const Slice& a, const Slice& b) const override {
33 PERF_COUNTER_ADD(user_key_comparison_count, 1);
34 return user_comparator_->Equal(a, b);
35 }
36
37 const char* Name() const override { return user_comparator_->Name(); }
38
39 void FindShortestSeparator(std::string* start,
40 const Slice& limit) const override {
41 return user_comparator_->FindShortestSeparator(start, limit);
42 }
43
44 void FindShortSuccessor(std::string* key) const override {
45 return user_comparator_->FindShortSuccessor(key);
46 }
47
48 const Comparator* GetRootComparator() const override {
49 return user_comparator_->GetRootComparator();
50 }
51
52 bool IsSameLengthImmediateSuccessor(const Slice& s,
53 const Slice& t) const override {
54 return user_comparator_->IsSameLengthImmediateSuccessor(s, t);
55 }
56
57 bool CanKeysWithDifferentByteContentsBeEqual() const override {
58 return user_comparator_->CanKeysWithDifferentByteContentsBeEqual();
59 }
60
61 private:
62 const Comparator* user_comparator_;
63};
64
65} // namespace rocksdb