SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Result.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 namespace SWC { namespace DB { namespace Cells {
11 
12 
13 
14 void Result::write(DynamicBuffer& cells) const {
15  cells.ensure(bytes);
16  for(auto cell : *this) {
17  if(!cell->has_expired(ttl))
18  cell->write(cells);
19  }
20 }
21 
22 void Result::write_and_free(DynamicBuffer& cells, uint32_t& cell_count,
23  Interval& intval, uint32_t threshold,
24  uint32_t max_cells) {
25  if(empty())
26  return;
27 
28  cells.ensure(bytes < threshold? bytes: threshold);
29  Cell* first = nullptr;
30  Cell* last = nullptr;
31  auto it = cbegin();
32  for(Cell* cell; it != cend() && (
33  (!threshold || threshold > cells.fill()) &&
34  (!max_cells || max_cells > cell_count) ); ++it) {
35  if((cell = *it)->has_expired(ttl))
36  continue;
37 
38  cell->write(cells);
39  intval.expand(cell->get_timestamp());
40  intval.align(cell->key);
41  (first ? last : first) = cell;
42  ++cell_count;
43  }
44 
45  if(first) {
46  intval.expand_begin(*first);
47  intval.expand_end(*(last ? last : first));
48  }
49 
50  if(it == cend()) {
51  free();
52  return;
53  }
54  auto it_end = it;
55  do {
56  --it;
57  bytes -= (*it)->encoded_length();
58  delete *it;
59  } while(it != cbegin());
60  erase(cbegin(), it_end);
61 }
62 
63 
64 void Result::print(std::ostream& out, Types::Column col_type,
65  bool with_cells) const {
66  out << "CellsResult(size=" << size()
67  << " bytes=" << bytes << " ttl=" << ttl;
68  if(with_cells) {
69  out << " cells=[";
70  for(auto cell : *this)
71  cell->print(out << '\n', col_type);
72  out << "\n]";
73  }
74  out << ')';
75 }
76 
77 
78 }}}
SWC::DB::Cells::Interval::align
SWC_CAN_INLINE bool align(const Interval &other)
Definition: Interval.h:152
SWC::DB::Cells::Interval::expand_end
SWC_CAN_INLINE void expand_end(const Cell &cell)
Definition: Interval.h:136
SWC::Core::BufferDyn::ensure
SWC_CAN_INLINE void ensure(size_t len)
Definition: Buffer.h:212
SWC::DB::Cells::Result::bytes
size_t bytes
Definition: Result.h:32
SWC::DB::Types::Column
Column
Definition: Column.h:18
SWC::DB::Cells::Interval::expand
void expand(const Interval &other)
Definition: Interval.cc:38
SWC::DB::Cells::Cell
Definition: Cell.h:92
Result.h
SWC::DB::Cells::Result::ttl
uint64_t ttl
Definition: Result.h:33
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Core::BufferDyn< StaticBuffer >
size
uint32_t size
Buffer size.
Definition: HeaderBufferInfo.h:47
SWC::DB::Cells::Result::free
void free() noexcept
Definition: Result.h:56
SWC::DB::Cells::Result::write_and_free
void write_and_free(DynamicBuffer &cells, uint32_t &cell_count, Interval &intval, uint32_t threshold, uint32_t max_cells)
Definition: Result.cc:22
SWC::Core::BufferDyn::fill
constexpr SWC_CAN_INLINE size_t fill() const noexcept
Definition: Buffer.h:192
SWC::DB::Cells::Interval::expand_begin
SWC_CAN_INLINE void expand_begin(const Cell &cell)
Definition: Interval.h:129
SWC::DB::Cells::Result::write
void write(DynamicBuffer &cells) const
Definition: Result.cc:14
SWC::DB::Cells::Result::print
void print(std::ostream &out, Types::Column col_type=Types::Column::PLAIN, bool with_cells=false) const
Definition: Result.cc:64
SWC::DB::Cells::Interval
Definition: Interval.h:17