uint64add.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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 'model' merge operator with uint64 addition semantics
  7. // Implemented as an AssociativeMergeOperator for simplicity and example.
  8. #pragma once
  9. #include "rocksdb/merge_operator.h"
  10. #include "utilities/merge_operators.h"
  11. namespace ROCKSDB_NAMESPACE {
  12. class Logger;
  13. class Slice;
  14. class UInt64AddOperator : public AssociativeMergeOperator {
  15. public:
  16. static const char* kClassName() { return "UInt64AddOperator"; }
  17. static const char* kNickName() { return "uint64add"; }
  18. const char* Name() const override { return kClassName(); }
  19. const char* NickName() const override { return kNickName(); }
  20. bool Merge(const Slice& /*key*/, const Slice* existing_value,
  21. const Slice& value, std::string* new_value,
  22. Logger* logger) const override;
  23. private:
  24. // Takes the string and decodes it into a uint64_t
  25. // On error, prints a message and returns 0
  26. uint64_t DecodeInteger(const Slice& value, Logger* logger) const;
  27. };
  28. } // namespace ROCKSDB_NAMESPACE