]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/utilities/merge_operators/string_append/stringappend.cc
2 * A MergeOperator for rocksdb that implements string append.
3 * @author Deon Nicholas (dnicholas@fb.com)
4 * Copyright 2013 Facebook
7 #include "stringappend.h"
12 #include "rocksdb/slice.h"
13 #include "rocksdb/merge_operator.h"
14 #include "utilities/merge_operators.h"
18 // Constructor: also specify the delimiter character.
19 StringAppendOperator::StringAppendOperator(char delim_char
)
20 : delim_(delim_char
) {
23 // Implementation for the merge operation (concatenates two strings)
24 bool StringAppendOperator::Merge(const Slice
& key
,
25 const Slice
* existing_value
,
27 std::string
* new_value
,
28 Logger
* logger
) const {
30 // Clear the *new_value for writing.
34 if (!existing_value
) {
35 // No existing_value. Set *new_value = value
36 new_value
->assign(value
.data(),value
.size());
38 // Generic append (existing_value != null).
39 // Reserve *new_value to correct size, and apply concatenation.
40 new_value
->reserve(existing_value
->size() + 1 + value
.size());
41 new_value
->assign(existing_value
->data(),existing_value
->size());
42 new_value
->append(1,delim_
);
43 new_value
->append(value
.data(), value
.size());
49 const char* StringAppendOperator::Name() const {
50 return "StringAppendOperator";
53 std::shared_ptr
<MergeOperator
> MergeOperators::CreateStringAppendOperator() {
54 return std::make_shared
<StringAppendOperator
>(',');
57 } // namespace rocksdb