/src/rocksdb/utilities/merge_operators/max.cc
Line | Count | Source (jump to first uncovered line) |
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 | | #include <memory> |
7 | | |
8 | | #include "rocksdb/merge_operator.h" |
9 | | #include "rocksdb/slice.h" |
10 | | #include "utilities/merge_operators.h" |
11 | | #include "utilities/merge_operators/max_operator.h" |
12 | | |
13 | | namespace ROCKSDB_NAMESPACE { |
14 | | |
15 | | bool MaxOperator::FullMergeV2(const MergeOperationInput& merge_in, |
16 | 0 | MergeOperationOutput* merge_out) const { |
17 | 0 | Slice& max = merge_out->existing_operand; |
18 | 0 | if (merge_in.existing_value) { |
19 | 0 | max = |
20 | 0 | Slice(merge_in.existing_value->data(), merge_in.existing_value->size()); |
21 | 0 | } else if (max.data() == nullptr) { |
22 | 0 | max = Slice(); |
23 | 0 | } |
24 | |
|
25 | 0 | for (const auto& op : merge_in.operand_list) { |
26 | 0 | if (max.compare(op) < 0) { |
27 | 0 | max = op; |
28 | 0 | } |
29 | 0 | } |
30 | |
|
31 | 0 | return true; |
32 | 0 | } |
33 | | |
34 | | bool MaxOperator::PartialMerge(const Slice& /*key*/, const Slice& left_operand, |
35 | | const Slice& right_operand, |
36 | | std::string* new_value, |
37 | 0 | Logger* /*logger*/) const { |
38 | 0 | if (left_operand.compare(right_operand) >= 0) { |
39 | 0 | new_value->assign(left_operand.data(), left_operand.size()); |
40 | 0 | } else { |
41 | 0 | new_value->assign(right_operand.data(), right_operand.size()); |
42 | 0 | } |
43 | 0 | return true; |
44 | 0 | } |
45 | | |
46 | | bool MaxOperator::PartialMergeMulti(const Slice& /*key*/, |
47 | | const std::deque<Slice>& operand_list, |
48 | | std::string* new_value, |
49 | 0 | Logger* /*logger*/) const { |
50 | 0 | Slice max; |
51 | 0 | for (const auto& operand : operand_list) { |
52 | 0 | if (max.compare(operand) < 0) { |
53 | 0 | max = operand; |
54 | 0 | } |
55 | 0 | } |
56 | |
|
57 | 0 | new_value->assign(max.data(), max.size()); |
58 | 0 | return true; |
59 | 0 | } |
60 | | |
61 | 0 | std::shared_ptr<MergeOperator> MergeOperators::CreateMaxOperator() { |
62 | 0 | return std::make_shared<MaxOperator>(); |
63 | 0 | } |
64 | | } // namespace ROCKSDB_NAMESPACE |