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 #pragma once
7 #include "rocksdb/merge_operator.h"
8 
9 #include <stdio.h>
10 
11 #include <memory>
12 #include <string>
13 
14 namespace ROCKSDB_NAMESPACE {
15 
16 class MergeOperators {
17  public:
18   static std::shared_ptr<MergeOperator> CreatePutOperator();
19   static std::shared_ptr<MergeOperator> CreateDeprecatedPutOperator();
20   static std::shared_ptr<MergeOperator> CreateUInt64AddOperator();
21   static std::shared_ptr<MergeOperator> CreateStringAppendOperator();
22   static std::shared_ptr<MergeOperator> CreateStringAppendOperator(char delim_char);
23   static std::shared_ptr<MergeOperator> CreateStringAppendTESTOperator();
24   static std::shared_ptr<MergeOperator> CreateMaxOperator();
25   static std::shared_ptr<MergeOperator> CreateBytesXOROperator();
26   static std::shared_ptr<MergeOperator> CreateSortOperator();
27 
28   // Will return a different merge operator depending on the string.
29   // TODO: Hook the "name" up to the actual Name() of the MergeOperators?
CreateFromStringId(const std::string & name)30   static std::shared_ptr<MergeOperator> CreateFromStringId(
31       const std::string& name) {
32     if (name == "put") {
33       return CreatePutOperator();
34     } else if (name == "put_v1") {
35       return CreateDeprecatedPutOperator();
36     } else if ( name == "uint64add") {
37       return CreateUInt64AddOperator();
38     } else if (name == "stringappend") {
39       return CreateStringAppendOperator();
40     } else if (name == "stringappendtest") {
41       return CreateStringAppendTESTOperator();
42     } else if (name == "max") {
43       return CreateMaxOperator();
44     } else if (name == "bytesxor") {
45       return CreateBytesXOROperator();
46     } else if (name == "sortlist") {
47       return CreateSortOperator();
48     } else {
49       // Empty or unknown, just return nullptr
50       return nullptr;
51     }
52   }
53 };
54 
55 }  // namespace ROCKSDB_NAMESPACE
56