SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Interval.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_Interval_h
8 #define swcdb_db_Cells_Interval_h
9 
11 #include "swcdb/db/Cells/Cell.h"
13 
14 
15 namespace SWC { namespace DB { namespace Cells {
16 
17 class Interval final {
18 
19  /* encoded-format:
20  key_begin-encoded key_end-encoded vi64(ts_earliest) vi64(ts_latest)
21  */
22 
23  public:
24 
26 
28  explicit Interval(const Types::KeySeq a_key_seq) noexcept
29  : key_seq(a_key_seq),
30  key_begin(), key_end(),
33  was_set(false) {
34  }
35 
37  explicit Interval(const Types::KeySeq a_key_seq,
38  const uint8_t **ptr, size_t *remain)
39  : key_seq(a_key_seq),
40  key_begin(ptr, remain, true),
41  key_end(ptr, remain, true),
42  ts_earliest(ptr, remain),
43  ts_latest(ptr, remain),
44  aligned_min(ptr, remain),
45  aligned_max(ptr, remain),
46  was_set(true) {
47  }
48 
50  explicit Interval(const Interval& other)
51  : key_seq(other.key_seq),
52  key_begin(other.key_begin),
53  key_end(other.key_end),
54  ts_earliest(other.ts_earliest),
55  ts_latest(other.ts_latest),
56  aligned_min(other.aligned_min),
57  aligned_max(other.aligned_max),
58  was_set(true) {
59  }
60 
62  explicit Interval(Interval&& other) noexcept
63  : key_seq(other.key_seq),
64  key_begin(std::move(other.key_begin)),
65  key_end(std::move(other.key_end)),
66  ts_earliest(std::move(other.ts_earliest)),
67  ts_latest(std::move(other.ts_latest)),
68  aligned_min(std::move(other.aligned_min)),
69  aligned_max(std::move(other.aligned_max)),
70  was_set(other.was_set) {
71  }
72 
73  Interval& operator=(const Interval&) = delete;
74 
75  ~Interval() noexcept;
76 
77  void copy(const Interval& other);
78 
79  void free() noexcept;
80 
82  size_t size_of_internal() const noexcept {
83  return key_begin.size + key_end.size +
86  }
87 
89  void set_key_begin(const DB::Cell::Key& key) {
90  key_begin.copy(key);
91  was_set = true;
92  }
93 
95  void set_key_end(const DB::Cell::Key& key) {
96  key_end.copy(key);
97  was_set = true;
98  }
99 
100  constexpr SWC_CAN_INLINE
102  ts_earliest.copy(ts);
103  was_set = true;
104  }
105 
106  constexpr SWC_CAN_INLINE
107  void set_ts_latest(const Specs::Timestamp& ts) {
108  ts_latest.copy(ts);
109  was_set = true;
110  }
111 
114  aligned_min.copy(key);
115  was_set = true;
116  }
117 
120  aligned_max.copy(key);
121  was_set = true;
122  }
123 
124  void expand(const Interval& other);
125 
126  void expand(const Cell& cell);
127 
129  void expand_begin(const Cell& cell) {
130  if(key_begin.empty() || !is_in_begin(cell.key))
131  key_begin.copy(cell.key);
132  was_set = true;
133  }
134 
136  void expand_end(const Cell& cell) {
137  if(key_end.empty() || !is_in_end(cell.key))
138  key_end.copy(cell.key);
139  was_set = true;
140  }
141 
143  void expand(const int64_t& ts) {
146  if(ts_latest.empty() || !ts_latest.is_matching(ts))
148  was_set = true;
149  }
150 
152  bool align(const Interval &other) {
153  return align(other.aligned_min, other.aligned_max);
154  }
155 
156  bool align(const DB::Cell::KeyVec& _min, const DB::Cell::KeyVec& _max);
157 
159  bool align(const DB::Cell::Key &key) {
161  }
162 
164  bool SWC_PURE_FUNC equal(const Interval& other) const noexcept {
165  return
166  was_set == other.was_set &&
167 
168  key_begin.equal(other.key_begin) &&
169  key_end.equal(other.key_end) &&
170 
171  ts_earliest.equal(other.ts_earliest) &&
172  ts_latest.equal(other.ts_latest) &&
173 
174  aligned_min.equal(other.aligned_min) &&
175  aligned_max.equal(other.aligned_max);
176  }
177 
179  bool is_in_begin(const DB::Cell::Key &key) const {
180  return key_begin.empty() ||
181  (!key.empty() &&
183  }
184 
186  bool is_in_end(const DB::Cell::Key &key) const {
187  return key_end.empty() ||
188  (!key.empty() &&
190  }
191 
192  /*
193  bool consist(const Interval& other) const;
194 
195  bool consist(const DB::Cell::Key& key) const;
196 
197  bool consist(const DB::Cell::Key& key, int64_t ts) const;
198 
199  SWC_CAN_INLINE
200  bool includes(const Interval& other) const {
201  return other.key_begin.empty() || other.key_end.empty() || consist(other);
202  }
203 
204  bool includes_begin(const Specs::Interval& interval) const;
205 
206  bool includes_end(const Specs::Interval& interval) const;
207 
208  bool includes(const Specs::Interval& interval) const;
209  */
210 
211  size_t SWC_PURE_FUNC encoded_length() const noexcept;
212 
213  void encode(uint8_t **ptr) const;
214 
215  void decode(const uint8_t **ptr, size_t *remain, bool owner);
216 
217  void print(std::ostream& out) const;
218 
219  friend std::ostream& operator<<(std::ostream& out, const Interval& intval) {
220  intval.print(out);
221  return out;
222  }
223 
230  bool was_set;
231 
232 };
233 
234 }}}
235 
236 #ifdef SWC_IMPL_SOURCE
238 #endif
239 
240 #endif // swcdb_db_Cells_Interval_h
SWC::Condition::LE
@ LE
Definition: Comparators.h:33
SWC::DB::Cells::Interval::encoded_length
size_t SWC_PURE_FUNC encoded_length() const noexcept
Definition: Interval.cc:117
SWC::DB::Cells::Interval::key_end
DB::Cell::Key key_end
Definition: Interval.h:225
Cell.h
SWC::DB::Cells::Interval::Interval
SWC_CAN_INLINE Interval(Interval &&other) noexcept
Definition: Interval.h:62
SWC::DB::KeySeq::align
bool align(const Types::KeySeq seq, const Cell::Key &key, Cell::KeyVec &start, Cell::KeyVec &finish) SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: KeyComparator.h:668
SWC::Condition::GE
@ GE
Definition: Comparators.h:31
SWC::DB::Cells::Interval::Interval
SWC_CAN_INLINE Interval(const Types::KeySeq a_key_seq) noexcept
Definition: Interval.h:28
SWC::DB::Cell::KeyVec
Definition: CellKeyVec.h:21
SWC::DB::Cells::Interval::set_aligned_min
SWC_CAN_INLINE void set_aligned_min(const DB::Cell::KeyVec &key)
Definition: Interval.h:113
SWC::DB::Cells::Interval::align
SWC_CAN_INLINE bool align(const Interval &other)
Definition: Interval.h:152
SWC::Condition::GT
@ GT
Definition: Comparators.h:30
SWC::DB::Cells::Interval::operator=
Interval & operator=(const Interval &)=delete
SWC::DB::Cells::Interval::aligned_max
DB::Cell::KeyVec aligned_max
Definition: Interval.h:229
SWC::DB::Cells::Interval::print
void print(std::ostream &out) const
Definition: Interval.cc:146
SWC::DB::Cells::Interval::expand_end
SWC_CAN_INLINE void expand_end(const Cell &cell)
Definition: Interval.h:136
SWC::DB::Specs::Timestamp::copy
constexpr SWC_CAN_INLINE void copy(const Timestamp &other) noexcept
Definition: SpecsTimestamp.h:49
SWC::DB::Cells::Interval::encode
void encode(uint8_t **ptr) const
Definition: Interval.cc:126
SWC::DB::Cells::Interval::key_seq
const Types::KeySeq key_seq
Definition: Interval.h:25
SWC::DB::Cells::Interval::is_in_begin
SWC_CAN_INLINE bool is_in_begin(const DB::Cell::Key &key) const
Definition: Interval.h:179
SWC::DB::Cells::Interval::decode
void decode(const uint8_t **ptr, size_t *remain, bool owner)
Definition: Interval.cc:135
SWC::DB::Cell::Key::equal
constexpr SWC_CAN_INLINE bool equal(const Key &other) const noexcept
Definition: CellKey.h:179
SWC::Condition::LT
@ LT
Definition: Comparators.h:34
SWC::DB::Cells::Interval::expand
void expand(const Interval &other)
Definition: Interval.cc:38
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::DB::Cell::Key
Definition: CellKey.h:24
SWC::DB::Cells::Interval::set_ts_latest
constexpr SWC_CAN_INLINE void set_ts_latest(const Specs::Timestamp &ts)
Definition: Interval.h:107
SWC::DB::Cells::Cell::key
DB::Cell::Key key
Definition: Cell.h:357
SWC::DB::Cells::Interval::is_in_end
SWC_CAN_INLINE bool is_in_end(const DB::Cell::Key &key) const
Definition: Interval.h:186
SWC::DB::Types::KeySeq
KeySeq
Definition: KeySeq.h:13
SWC::DB::Cell::Key::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: CellKey.h:186
SWC::DB::Cells::Interval::equal
SWC_CAN_INLINE bool SWC_PURE_FUNC equal(const Interval &other) const noexcept
Definition: Interval.h:164
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::DB::Cells::Interval::~Interval
~Interval() noexcept
Definition: Interval.cc:14
SWC::DB::Cells::Interval::aligned_min
DB::Cell::KeyVec aligned_min
Definition: Interval.h:228
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::DB::Cell::Key::size
uint32_t size
Definition: CellKey.h:256
SWC_PURE_FUNC
#define SWC_PURE_FUNC
Definition: Compat.h:108
SWC::DB::Specs::Timestamp
Definition: SpecsTimestamp.h:18
SWC::DB::Specs::Timestamp::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: SpecsTimestamp.h:68
SWC::DB::Cells::Interval::free
void free() noexcept
Definition: Interval.cc:28
SWC::DB::Cell::Key::copy
void copy(const Key &other)
Definition: CellKey.h:314
SWC::DB::Specs::Timestamp::equal
constexpr SWC_CAN_INLINE bool equal(const Timestamp &other) const noexcept
Definition: SpecsTimestamp.h:73
SWC::DB::Cells::Interval::set_ts_earliest
constexpr SWC_CAN_INLINE void set_ts_earliest(const Specs::Timestamp &ts)
Definition: Interval.h:101
SWC::DB::Cells::Interval::set_key_end
SWC_CAN_INLINE void set_key_end(const DB::Cell::Key &key)
Definition: Interval.h:95
SWC::DB::Cells::Interval::Interval
SWC_CAN_INLINE Interval(const Interval &other)
Definition: Interval.h:50
SWC::DB::Cell::KeyVec::size_of_internal
SWC_CAN_INLINE size_t size_of_internal() const noexcept
Definition: CellKeyVec.h:46
SpecsInterval.h
SWC::DB::Cells::Interval::copy
void copy(const Interval &other)
Definition: Interval.cc:16
SWC::DB::Cells::Interval::expand_begin
SWC_CAN_INLINE void expand_begin(const Cell &cell)
Definition: Interval.h:129
SWC::DB::Cell::KeyVec::copy
void copy(const KeyVec &other)
Definition: CellKeyVec.h:181
SWC::DB::Cells::Interval::Interval
SWC_CAN_INLINE Interval(const Types::KeySeq a_key_seq, const uint8_t **ptr, size_t *remain)
Definition: Interval.h:37
SWC::DB::Cells::Interval::expand
SWC_CAN_INLINE void expand(const int64_t &ts)
Definition: Interval.h:143
SWC::DB::Cells::Interval::ts_earliest
Specs::Timestamp ts_earliest
Definition: Interval.h:226
SWC::DB::Cell::KeyVec::equal
bool equal(const KeyVec &other) const noexcept
Definition: CellKeyVec.h:187
SWC::DB::Cells::Interval::set_aligned_max
SWC_CAN_INLINE void set_aligned_max(const DB::Cell::KeyVec &key)
Definition: Interval.h:119
KeyComparator.h
SWC::DB::Cells::Interval
Definition: Interval.h:17
SWC::DB::Cells::Interval::ts_latest
Specs::Timestamp ts_latest
Definition: Interval.h:227
SWC::DB::Specs::Timestamp::is_matching
SWC_CAN_INLINE bool is_matching(int64_t other) const noexcept
Definition: SpecsTimestamp.h:100
Interval.cc
SWC::DB::Specs::Timestamp::set
constexpr SWC_CAN_INLINE void set(int64_t timestamp, Condition::Comp comperator) noexcept
Definition: SpecsTimestamp.h:54
SWC::DB::KeySeq::compare
Condition::Comp compare(const Types::KeySeq seq, const Cell::Key &key, const Cell::Key &other) SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: KeyComparator.h:294
SWC::DB::Cells::Interval::size_of_internal
SWC_CAN_INLINE size_t size_of_internal() const noexcept
Definition: Interval.h:82
SWC::DB::Cells::Interval::key_begin
DB::Cell::Key key_begin
Definition: Interval.h:224
SWC::DB::Cells::Interval::was_set
bool was_set
Definition: Interval.h:230
SWC::DB::Cells::Interval::align
SWC_CAN_INLINE bool align(const DB::Cell::Key &key)
Definition: Interval.h:159
SWC::DB::Cells::Interval::set_key_begin
SWC_CAN_INLINE void set_key_begin(const DB::Cell::Key &key)
Definition: Interval.h:89