#pragma once
#include "db/dbformat.h"
#include "rocksdb/slice.h"
#include <string>
#include <deque>
namespace
rocksdb {
const
std::deque<std::string> empty_operand_list;
class
MergeContext {
public
:
void
Clear() {
if
(operand_list) {
operand_list->clear();
}
}
void
PushPartialMergeResult(std::string& merge_result) {
assert
(operand_list);
operand_list->pop_front();
swap(operand_list->front(), merge_result);
}
void
PushOperand(
const
Slice& operand_slice) {
Initialize();
operand_list->push_front(operand_slice.ToString());
}
size_t
GetNumOperands()
const
{
if
(!operand_list) {
return
0;
}
return
operand_list->size();
}
Slice GetOperand(
int
index)
const
{
assert
(operand_list);
return
(*operand_list)[index];
}
const
std::deque<std::string>& GetOperands()
const
{
if
(!operand_list) {
return
empty_operand_list;
}
return
*operand_list;
}
private
:
void
Initialize() {
if
(!operand_list) {
operand_list.reset(
new
std::deque<std::string>());
}
}
std::unique_ptr<std::deque<std::string>> operand_list;
};
}