bytesxor.h 1.3 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. virtual bool Merge(const Slice& key,
  22. const Slice* existing_value,
  23. const Slice& value,
  24. std::string* new_value,
  25. Logger* logger) const override;
  26. virtual const char* Name() const override {
  27. return "BytesXOR";
  28. }
  29. void XOR(const Slice* existing_value, const Slice& value,
  30. std::string* new_value) const;
  31. };
  32. } // namespace ROCKSDB_NAMESPACE