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 // A MergeOperator for RocksDB that implements Merge Sort. 7 // It is built using the MergeOperator interface. The operator works by taking 8 // an input which contains one or more merge operands where each operand is a 9 // list of sorted ints and merges them to form a large sorted list. 10 #pragma once 11 12 #include "rocksdb/merge_operator.h" 13 #include "rocksdb/slice.h" 14 15 namespace ROCKSDB_NAMESPACE { 16 17 class SortList : public MergeOperator { 18 public: 19 bool FullMergeV2(const MergeOperationInput& merge_in, 20 MergeOperationOutput* merge_out) const override; 21 22 bool PartialMerge(const Slice& /*key*/, const Slice& left_operand, 23 const Slice& right_operand, std::string* new_value, 24 Logger* /*logger*/) const override; 25 26 bool PartialMergeMulti(const Slice& key, 27 const std::deque<Slice>& operand_list, 28 std::string* new_value, Logger* logger) const override; 29 30 const char* Name() const override; 31 32 void MakeVector(std::vector<int>& operand, Slice slice) const; 33 34 private: 35 std::vector<int> Merge(std::vector<int>& left, std::vector<int>& right) const; 36 }; 37 38 } // namespace ROCKSDB_NAMESPACE 39