stringappend.h 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  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 string append.
  7. #pragma once
  8. #include "rocksdb/merge_operator.h"
  9. #include "rocksdb/slice.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. class StringAppendOperator : public AssociativeMergeOperator {
  12. public:
  13. // Constructor: specify delimiter
  14. explicit StringAppendOperator(char delim_char);
  15. explicit StringAppendOperator(const std::string& delim);
  16. bool Merge(const Slice& key, const Slice* existing_value, const Slice& value,
  17. std::string* new_value, Logger* logger) const override;
  18. static const char* kClassName() { return "StringAppendOperator"; }
  19. static const char* kNickName() { return "stringappend"; }
  20. const char* Name() const override { return kClassName(); }
  21. const char* NickName() const override { return kNickName(); }
  22. private:
  23. std::string delim_; // The delimiter is inserted between elements
  24. };
  25. } // namespace ROCKSDB_NAMESPACE