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