merge_operators.h 2.0 KB

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