SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
SpecsKeyIntervals.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
7 #ifndef swcdb_db_cells_SpecsKeyIntervals_h
8 #define swcdb_db_cells_SpecsKeyIntervals_h
9 
10 
11 #include "swcdb/db/Types/KeySeq.h"
13 
14 
15 namespace SWC { namespace DB { namespace Specs {
16 
17 
18 struct KeyInterval {
20 
22  KeyInterval() noexcept
23  : start(),
24  finish() {
25  }
26 
28  KeyInterval(const KeyInterval& other)
29  : start(other.start),
30  finish(other.finish) {
31  }
32 
34  KeyInterval(KeyInterval&& other) noexcept
35  : start(std::move(other.start)),
36  finish(std::move(other.finish)) {
37  }
38 
40  KeyInterval(const Key& a_start, const Key& a_finish)
41  : start(a_start),
42  finish(a_finish) {
43  }
44 
46  KeyInterval(Key&& a_start, Key&& a_finish) noexcept
47  : start(std::move(a_start)),
48  finish(std::move(a_finish)) {
49  }
50 
52  KeyInterval(const uint8_t** bufp, size_t* remainp)
53  : start(bufp, remainp),
54  finish(bufp, remainp) {
55  }
56 
57  ~KeyInterval() noexcept;
58 
60  KeyInterval& operator=(const KeyInterval& other) {
61  start.copy(other.start);
62  finish.copy(other.finish);
63  return *this;
64  }
65 
67  KeyInterval& operator=(KeyInterval&& other) noexcept {
68  start.move(other.start);
69  finish.move(other.finish);
70  return *this;
71  }
72 
74  size_t encoded_length() const noexcept {
76  }
77 
79  void encode(uint8_t** bufp) const {
80  start.encode(bufp);
81  finish.encode(bufp);
82  }
83 
85  void decode(const uint8_t** bufp, size_t* remainp) {
86  start.decode(bufp, remainp);
87  finish.decode(bufp, remainp);
88  }
89 
90 };
91 
92 
93 
94 class KeyIntervals : public Core::Vector<KeyInterval> {
95  public:
96 
98  using Vec::insert;
99  using Vec::emplace_back;
100 
102  KeyIntervals() noexcept { }
103 
105  KeyIntervals(const uint8_t** bufp, size_t* remainp) {
106  decode(bufp, remainp);
107  }
108 
110  KeyIntervals(KeyIntervals&& other) noexcept
111  : Vec(std::move(other)) {
112  }
113 
114  ~KeyIntervals() noexcept;
115 
117  KeyIntervals& operator=(const KeyIntervals& other) {
118  copy(other);
119  return *this;
120  }
121 
123  KeyIntervals& operator=(KeyIntervals&& other) noexcept {
124  move(other);
125  return *this;
126  }
127 
129  void move(KeyIntervals& other) noexcept {
130  Vec::operator=(std::move(other));
131  }
132 
133  KeyIntervals(const KeyIntervals& other);
134 
135  void copy(const KeyIntervals& other);
136 
137  KeyInterval& add();
138 
139  KeyInterval& add(const KeyInterval& other);
140 
141  KeyInterval& add(KeyInterval&& other);
142 
143  KeyInterval& add(const Key& start, const Key& finish);
144 
145  KeyInterval& add(Key&& start, Key&& finish);
146 
147  size_t size_of_internal() const noexcept;
148 
149  bool SWC_PURE_FUNC equal(const KeyIntervals& other) const noexcept;
150 
151  bool is_matching(const Types::KeySeq key_seq,
152  const DB::Cell::Key& cellkey) const;
153 
154  bool is_matching_start(const Types::KeySeq key_seq,
155  const DB::Cell::Key& cellkey) const;
156 
158  size_t encoded_length() const noexcept {
160  for(const auto& key : *this)
161  sz += key.encoded_length();
162  return sz;
163  }
164 
166  void encode(uint8_t** bufp) const {
168  for(const auto& key : *this)
169  key.encode(bufp);
170  }
171 
173  void decode(const uint8_t** bufp, size_t* remainp) {
174  clear();
175  resize(Serialization::decode_vi64(bufp, remainp));
176  for(auto& key : *this)
177  key.decode(bufp, remainp);
178  }
179 
180  void print(std::ostream& out) const;
181 
182  void display(std::ostream& out, bool pretty,
183  const std::string& offset) const;
184 
185 };
186 
187 
188 
190 size_t KeyIntervals::size_of_internal() const noexcept {
191  size_t sz = 0;
192  for(const auto& key : *this) {
193  sz += sizeof(key);
194  sz += key.start.size_of_internal();
195  sz += key.finish.size_of_internal();
196  }
197  return sz;
198 }
199 
202  const DB::Cell::Key& cellkey) const {
203  if(empty())
204  return true;
205 
206  switch(key_seq) {
207  case Types::KeySeq::LEXIC:
208  case Types::KeySeq::FC_LEXIC:
209  for(const auto& key : *this) {
210  if(!key.start.is_matching_lexic(cellkey) ||
211  !key.finish.is_matching_lexic(cellkey))
212  return false;
213  }
214  return true;
215  case Types::KeySeq::VOLUME:
217  for(const auto& key : *this) {
218  if(!key.start.is_matching_volume(cellkey) ||
219  !key.finish.is_matching_volume(cellkey))
220  return false;
221  }
222  return true;
223  default:
224  return false;
225  }
226 }
227 
230  const DB::Cell::Key& cellkey) const {
231  switch(key_seq) {
232  case Types::KeySeq::LEXIC:
233  case Types::KeySeq::FC_LEXIC:
234  for(const auto& key : *this) {
235  if(!key.start.is_matching_lexic(cellkey))
236  return false;
237  }
238  return true;
239  case Types::KeySeq::VOLUME:
241  for(const auto& key : *this) {
242  if(!key.start.is_matching_volume(cellkey))
243  return false;
244  }
245  return true;
246  default:
247  return false;
248  }
249 }
250 
251 
252 
253 }}}
254 
255 
256 
257 #ifdef SWC_IMPL_SOURCE
259 #endif
260 
261 
262 #endif // swcdb_db_cells_SpecsKeyIntervals_h
SWC::DB::Specs::KeyInterval::KeyInterval
SWC_CAN_INLINE KeyInterval(Key &&a_start, Key &&a_finish) noexcept
Definition: SpecsKeyIntervals.h:46
SWC::DB::Specs::KeyIntervals::is_matching
bool is_matching(const Types::KeySeq key_seq, const DB::Cell::Key &cellkey) const
Definition: SpecsKeyIntervals.h:201
SWC::Core::Vector< KeyInterval >::resize
SWC_CAN_INLINE void resize(size_type sz, ArgsT &&... args)
Definition: Vector.h:308
SWC::DB::Specs::KeyIntervals::size_of_internal
size_t size_of_internal() const noexcept
Definition: SpecsKeyIntervals.h:190
SWC::DB::Specs::KeyInterval::finish
Key finish
Definition: SpecsKeyIntervals.h:19
SWC::DB::Specs::KeyInterval::start
Key start
Definition: SpecsKeyIntervals.h:19
SWC::Core::Vector< KeyInterval >::clear
SWC_CAN_INLINE void clear() noexcept(_NoExceptDestructor)
Definition: Vector.h:120
SWC::DB::Specs::KeyIntervals
Definition: SpecsKeyIntervals.h:94
SWC::DB::Specs::Key::encoded_length
SWC_CAN_INLINE uint32_t encoded_length() const noexcept
Definition: SpecsKey.h:269
SWC::DB::Specs::KeyInterval::KeyInterval
SWC_CAN_INLINE KeyInterval(const Key &a_start, const Key &a_finish)
Definition: SpecsKeyIntervals.h:40
SWC::Core::Vector< KeyInterval >::operator=
SWC_CAN_INLINE Vector & operator=(Vector &&other) noexcept
Definition: Vector.h:141
SWC::DB::Specs::KeyInterval
Definition: SpecsKeyIntervals.h:18
KeySeq.h
SWC::DB::Specs::KeyIntervals::move
SWC_CAN_INLINE void move(KeyIntervals &other) noexcept
Definition: SpecsKeyIntervals.h:129
SWC::DB::Specs::Key::copy
void copy(const Key &other)
Definition: SpecsKey.cc:40
SWC::DB::Specs::KeyInterval::~KeyInterval
~KeyInterval() noexcept
Definition: SpecsKeyIntervals.cc:15
SWC::DB::Cell::Key
Definition: CellKey.h:24
SWC::DB::Specs::Key
Definition: SpecsKey.h:136
SWC::DB::Specs::KeyIntervals::copy
void copy(const KeyIntervals &other)
Definition: SpecsKeyIntervals.cc:24
SWC::DB::Specs::KeyInterval::KeyInterval
SWC_CAN_INLINE KeyInterval(const uint8_t **bufp, size_t *remainp)
Definition: SpecsKeyIntervals.h:52
SWC::DB::Specs::KeyIntervals::equal
bool SWC_PURE_FUNC equal(const KeyIntervals &other) const noexcept
Definition: SpecsKeyIntervals.cc:48
SWC::DB::Types::KeySeq
KeySeq
Definition: KeySeq.h:13
SWC::DB::Types::KeySeq::UNKNOWN
@ UNKNOWN
SWC::DB::Specs::Key::decode
SWC_CAN_INLINE void decode(const uint8_t **bufp, size_t *remainp)
Definition: SpecsKey.h:284
SWC::Core::Vector< KeyInterval >::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: Vector.h:168
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::DB::Specs::KeyIntervals::decode
SWC_CAN_INLINE void decode(const uint8_t **bufp, size_t *remainp)
Definition: SpecsKeyIntervals.h:173
SWC::DB::Specs::KeyIntervals::KeyIntervals
SWC_CAN_INLINE KeyIntervals() noexcept
Definition: SpecsKeyIntervals.h:102
SWC::DB::Specs::KeyIntervals::add
KeyInterval & add()
Definition: SpecsKeyIntervals.cc:28
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::DB::Specs::KeyInterval::KeyInterval
SWC_CAN_INLINE KeyInterval(const KeyInterval &other)
Definition: SpecsKeyIntervals.h:28
SWC_PURE_FUNC
#define SWC_PURE_FUNC
Definition: Compat.h:108
SWC::DB::Specs::KeyIntervals::encoded_length
SWC_CAN_INLINE size_t encoded_length() const noexcept
Definition: SpecsKeyIntervals.h:158
SWC::DB::Specs::KeyIntervals::encode
SWC_CAN_INLINE void encode(uint8_t **bufp) const
Definition: SpecsKeyIntervals.h:166
SWC::Serialization::encoded_length_vi64
constexpr SWC_CAN_INLINE uint8_t encoded_length_vi64(uint64_t val) noexcept
Definition: Serialization.h:272
SWC::DB::Specs::KeyInterval::operator=
SWC_CAN_INLINE KeyInterval & operator=(KeyInterval &&other) noexcept
Definition: SpecsKeyIntervals.h:67
SWC::DB::Specs::KeyInterval::decode
SWC_CAN_INLINE void decode(const uint8_t **bufp, size_t *remainp)
Definition: SpecsKeyIntervals.h:85
SWC::DB::Specs::KeyIntervals::KeyIntervals
SWC_CAN_INLINE KeyIntervals(KeyIntervals &&other) noexcept
Definition: SpecsKeyIntervals.h:110
SpecsKey.h
SWC::Core::Vector
Definition: Vector.h:14
SWC::DB::Specs::KeyIntervals::display
void display(std::ostream &out, bool pretty, const std::string &offset) const
Definition: SpecsKeyIntervals.cc:72
SWC::DB::Specs::KeyIntervals::~KeyIntervals
~KeyIntervals() noexcept
Definition: SpecsKeyIntervals.cc:22
SWC::DB::Specs::Key::encode
SWC_CAN_INLINE void encode(uint8_t **bufp) const
Definition: SpecsKey.h:277
SWC::DB::Specs::KeyIntervals::is_matching_start
bool is_matching_start(const Types::KeySeq key_seq, const DB::Cell::Key &cellkey) const
Definition: SpecsKeyIntervals.h:229
SWC::Serialization::decode_vi64
constexpr SWC_CAN_INLINE uint64_t decode_vi64(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:302
SWC::DB::Specs::KeyInterval::KeyInterval
SWC_CAN_INLINE KeyInterval() noexcept
Definition: SpecsKeyIntervals.h:22
SWC::DB::Specs::KeyInterval::KeyInterval
SWC_CAN_INLINE KeyInterval(KeyInterval &&other) noexcept
Definition: SpecsKeyIntervals.h:34
SWC::DB::Specs::KeyIntervals::KeyIntervals
SWC_CAN_INLINE KeyIntervals(const uint8_t **bufp, size_t *remainp)
Definition: SpecsKeyIntervals.h:105
SWC::DB::Specs::KeyIntervals::print
void print(std::ostream &out) const
Definition: SpecsKeyIntervals.cc:59
SWC::Serialization::encode_vi64
constexpr SWC_CAN_INLINE void encode_vi64(uint8_t **bufp, uint64_t val)
Definition: Serialization.h:286
SWC::DB::Specs::KeyInterval::encode
SWC_CAN_INLINE void encode(uint8_t **bufp) const
Definition: SpecsKeyIntervals.h:79
SpecsKeyIntervals.cc
SWC::DB::Specs::KeyIntervals::operator=
SWC_CAN_INLINE KeyIntervals & operator=(KeyIntervals &&other) noexcept
Definition: SpecsKeyIntervals.h:123
SWC::Core::Vector< KeyInterval >::size
constexpr SWC_CAN_INLINE size_type size() const noexcept
Definition: Vector.h:189
SWC::DB::Specs::KeyInterval::encoded_length
SWC_CAN_INLINE size_t encoded_length() const noexcept
Definition: SpecsKeyIntervals.h:74
SWC::Core::Vector< KeyInterval >::emplace_back
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
Definition: Vector.h:349
SWC::DB::Specs::Key::move
SWC_CAN_INLINE void move(Key &other) noexcept
Definition: SpecsKey.h:175
SWC::DB::Specs::KeyIntervals::Vec
Core::Vector< KeyInterval > Vec
Definition: SpecsKeyIntervals.h:97
SWC::Core::Vector< KeyInterval >::insert
SWC_CAN_INLINE iterator insert(size_type offset, ArgsT &&... args)
Definition: Vector.h:367