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.cc
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 
8 
9 
10 
11 namespace SWC { namespace DB { namespace Cells {
12 
13 
14 Interval::~Interval() noexcept { }
15 
16 void Interval::copy(const Interval& other) {
17  set_key_begin(other.key_begin);
18  set_key_end(other.key_end);
19 
21  set_ts_latest(other.ts_latest);
22 
25  was_set = true;
26 }
27 
28 void Interval::free() noexcept {
29  key_begin.free();
30  key_end.free();
31  ts_earliest.free();
32  ts_latest.free();
33  was_set = false;
36 }
37 
38 void Interval::expand(const Interval& other) {
39  bool initiated = was_set;
40 
41  if(!initiated || !is_in_begin(other.key_begin))
42  set_key_begin(other.key_begin);
43 
44  if(!initiated || !is_in_end(other.key_end))
45  set_key_end(other.key_end);
46 
47  if(!initiated
48  || (!other.ts_earliest.empty()
49  && other.ts_earliest.comp == Condition::NONE)
52 
53  if(!initiated
54  || (!other.ts_latest.empty()
55  && other.ts_latest.comp == Condition::NONE)
57  set_ts_latest(other.ts_latest);
58 }
59 
60 void Interval::expand(const Cell& cell) {
61  expand_begin(cell);
62  expand_end(cell);
63  //expand(cell.get_timestamp());
64  was_set = true;
65 }
66 
69  const DB::Cell::KeyVec& _max) {
70  bool start = DB::KeySeq::align(key_seq, aligned_min, _min, Condition::LT);
71  bool finish = DB::KeySeq::align(key_seq, aligned_max, _max, Condition::GT);
72  return start || finish;
73 }
74 
75 /*
76 bool Interval::consist(const Interval& other) const {
77  return (other.key_end.empty() || is_in_begin(other.key_end))
78  && (other.key_begin.empty() || is_in_end(other.key_begin));
79 }
80 
81 bool Interval::consist(const DB::Cell::Key& key) const {
82  return is_in_begin(key) && is_in_end(key);
83 }
84 
85 bool Interval::consist(const DB::Cell::Key& key, int64_t ts) const {
86  return is_in_begin(key)
87  &&
88  is_in_end(key)
89  &&
90  (ts_earliest.empty() || ts_earliest.is_matching(ts))
91  &&
92  (ts_latest.empty() || ts_latest.is_matching(ts));
93 }
94 
95 bool Interval::includes_begin(const Specs::Interval& interval) const {
96  return key_begin.empty() || interval.is_matching_end(key_seq, key_begin);
97 }
98 
99 bool Interval::includes_end(const Specs::Interval& interval) const {
100  return key_end.empty() || interval.is_matching_begin(key_seq, key_end);
101 }
102 
103 bool Interval::includes(const Specs::Interval& interval) const {
104  return includes_begin(interval) && includes_end(interval);
105  // , bool ts=false
106  &&
107  (!ts || (
108  (ts_latest.empty() ||
109  interval.ts_start.is_matching(ts_latest.value) )
110  &&
111  (ts_earliest.empty() ||
112  interval.ts_finish.is_matching(ts_earliest.value) )
113  ) )
114 }
115 */
116 
117 size_t Interval::encoded_length() const noexcept {
118  return key_begin.encoded_length()
124 }
125 
126 void Interval::encode(uint8_t **ptr) const {
127  key_begin.encode(ptr);
128  key_end.encode(ptr);
129  ts_earliest.encode(ptr);
130  ts_latest.encode(ptr);
131  aligned_min.encode(ptr);
132  aligned_max.encode(ptr);
133 }
134 
135 void Interval::decode(const uint8_t **ptr, size_t *remain, bool owner){
136  key_begin.decode(ptr, remain, owner);
137  key_end.decode(ptr, remain, owner);
138  ts_earliest.decode(ptr, remain);
139  ts_latest.decode(ptr, remain);
140  aligned_min.decode(ptr, remain);
141  aligned_max.decode(ptr, remain);
142 
143  was_set = true;
144 }
145 
146 void Interval::print(std::ostream& out) const {
147  out
148  << "Interval("
149  << "begin=" << key_begin
150  << " end=" << key_end
151  << " earliest=" << ts_earliest
152  << " latest=" << ts_latest
153  << " min=" << aligned_min
154  << " max=" << aligned_max
155  << " was_set=" << (was_set? "true" : "false")
156  << ')';
157 }
158 
159 
160 }}}
SWC::DB::Cell::KeyVec::encoded_length
uint32_t encoded_length() const noexcept
Definition: CellKeyVec.h:215
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
SWC::DB::Specs::Timestamp::encoded_length
constexpr SWC_CAN_INLINE size_t encoded_length() const noexcept
Definition: SpecsTimestamp.h:78
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::Core::Vector::clear
SWC_CAN_INLINE void clear() noexcept(_NoExceptDestructor)
Definition: Vector.h:120
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::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::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::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::Specs::Timestamp::encode
SWC_CAN_INLINE void encode(uint8_t **bufp) const
Definition: SpecsTimestamp.h:86
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::Specs::Timestamp::decode
SWC_CAN_INLINE void decode(const uint8_t **bufp, size_t *remainp)
Definition: SpecsTimestamp.h:93
SWC::DB::Cell::Key::decode
void decode(const uint8_t **bufp, size_t *remainp, bool owner)
Definition: CellKey.h:337
SWC::DB::Specs::Timestamp::value
int64_t value
Definition: SpecsTimestamp.h:124
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::Specs::Timestamp::comp
Condition::Comp comp
Definition: SpecsTimestamp.h:125
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::Specs::Timestamp::free
constexpr SWC_CAN_INLINE void free() noexcept
Definition: SpecsTimestamp.h:61
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_SHOULD_INLINE
#define SWC_SHOULD_INLINE
Definition: Compat.h:63
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::Cell::Key::encoded_length
constexpr uint32_t encoded_length() const noexcept
Definition: CellKey.h:323
SWC::DB::Cells::Interval::set_key_end
SWC_CAN_INLINE void set_key_end(const DB::Cell::Key &key)
Definition: Interval.h:95
SWC::Condition::NONE
@ NONE
Definition: Comparators.h:28
SWC::DB::Cell::Key::free
SWC_CAN_INLINE void free() noexcept
Definition: CellKey.h:73
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::Cells::Interval::ts_earliest
Specs::Timestamp ts_earliest
Definition: Interval.h:226
SWC::DB::Cells::Interval::set_aligned_max
SWC_CAN_INLINE void set_aligned_max(const DB::Cell::KeyVec &key)
Definition: Interval.h:119
SWC::DB::Cells::Interval
Definition: Interval.h:17
SWC::DB::Cell::KeyVec::encode
void encode(uint8_t **bufp) const
Definition: CellKeyVec.h:223
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.h
SWC::DB::Cell::Key::encode
void encode(uint8_t **bufp) const
Definition: CellKey.h:328
SWC::DB::Cells::Interval::key_begin
DB::Cell::Key key_begin
Definition: Interval.h:224
SWC::DB::Cell::KeyVec::decode
void decode(const uint8_t **bufp, size_t *remainp)
Definition: CellKeyVec.h:234
SWC::DB::Cells::Interval::was_set
bool was_set
Definition: Interval.h:230
SWC::DB::Cells::Interval::set_key_begin
SWC_CAN_INLINE void set_key_begin(const DB::Cell::Key &key)
Definition: Interval.h:89