-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpika_bit.h
142 lines (129 loc) · 4.04 KB
/
pika_bit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright (c) 2015-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_BIT_H_
#define PIKA_BIT_H_
#include "storage/storage.h"
#include "include/pika_command.h"
#include "include/pika_partition.h"
/*
* bitoperation
*/
class BitGetCmd : public Cmd {
public:
BitGetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitGetCmd(*this); }
private:
std::string key_;
int64_t bit_offset_ = -1;
virtual void Clear() {
key_ = "";
bit_offset_ = -1;
}
virtual void DoInitial() override;
};
class BitSetCmd : public Cmd {
public:
BitSetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitSetCmd(*this); }
private:
std::string key_;
int64_t bit_offset_;
int64_t on_;
virtual void Clear() {
key_ = "";
bit_offset_ = -1;
on_ = -1;
}
virtual void DoInitial() override;
};
class BitCountCmd : public Cmd {
public:
BitCountCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitCountCmd(*this); }
private:
std::string key_;
bool count_all_;
int64_t start_offset_;
int64_t end_offset_;
virtual void Clear() {
key_ = "";
count_all_ = false;
start_offset_ = -1;
end_offset_ = -1;
}
virtual void DoInitial() override;
};
class BitPosCmd : public Cmd {
public:
BitPosCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual std::vector<std::string> current_key() const {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitPosCmd(*this); }
private:
std::string key_;
bool pos_all_;
bool endoffset_set_;
int64_t bit_val_;
int64_t start_offset_;
int64_t end_offset_;
virtual void Clear() {
key_ = "";
pos_all_ = false;
endoffset_set_ = false;
bit_val_ = -1;
start_offset_ = -1;
end_offset_ = -1;
}
virtual void DoInitial() override;
};
class BitOpCmd : public Cmd {
public:
BitOpCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitOpCmd(*this); }
private:
std::string dest_key_;
std::vector<std::string> src_keys_;
storage::BitOpType op_;
virtual void Clear() {
dest_key_ = "";
src_keys_.clear();
op_ = storage::kBitOpDefault;
}
virtual void DoInitial() override;
};
#endif