bytesxor.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #pragma once
  6. #include <algorithm>
  7. #include <memory>
  8. #include <string>
  9. #include "rocksdb/env.h"
  10. #include "rocksdb/merge_operator.h"
  11. #include "rocksdb/slice.h"
  12. #include "util/coding.h"
  13. #include "utilities/merge_operators.h"
  14. namespace ROCKSDB_NAMESPACE {
  15. // A 'model' merge operator that XORs two (same sized) array of bytes.
  16. // Implemented as an AssociativeMergeOperator for simplicity and example.
  17. class BytesXOROperator : public AssociativeMergeOperator {
  18. public:
  19. // XORs the two array of bytes one byte at a time and stores the result
  20. // in new_value. len is the number of xored bytes, and the length of new_value
  21. bool Merge(const Slice& key, const Slice* existing_value, const Slice& value,
  22. std::string* new_value, Logger* logger) const override;
  23. static const char* kClassName() { return "BytesXOR"; }
  24. static const char* kNickName() { return "bytesxor"; }
  25. const char* NickName() const override { return kNickName(); }
  26. const char* Name() const override { return kClassName(); }
  27. void XOR(const Slice* existing_value, const Slice& value,
  28. std::string* new_value) const;
  29. };
  30. } // namespace ROCKSDB_NAMESPACE