SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
SpecsKey.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 
7 
9 
10 
11 namespace SWC { namespace DB { namespace Specs {
12 
13 
14 
15 void Fraction::print(std::ostream& out, bool pretty) const {
16  out << Condition::to_string(comp) << '"';
17  char hex[5];
18  hex[4] = 0;
19  uint8_t byte;
20  for(auto chrp = cbegin(); chrp != cend(); ++chrp) {
21  byte = *chrp;
22  if(byte == '"')
23  out << '\\';
24  if(!pretty || (31 < byte && byte < 127)) {
25  out << *chrp;
26  } else {
27  sprintf(hex, "0x%X", byte);
28  out << hex;
29  }
30  }
31  out << '"';
32 }
33 
34 
35 
36 Key::Key(const Key& other) : Vec(other) { }
37 
38 Key::~Key() noexcept { }
39 
40 void Key::copy(const Key &other) {
41  Vec::operator=(other);
42 }
43 
44 bool Key::equal(const Key &other) const noexcept {
45  return *this == other;
46 }
47 
48 void Key::set(const DB::Cell::Key &cell_key, Condition::Comp comp) {
49  clear();
50  resize(cell_key.count);
51 
52  uint32_t len;
53  const uint8_t* ptr = cell_key.data;
54  for(auto it=begin(); it != cend(); ++it) {
55  it->comp = comp;
56  if((len = Serialization::decode_vi32(&ptr))) {
57  it->append(reinterpret_cast<const char*>(ptr), len);
58  ptr += len;
59  }
60  }
61 }
62 
63 
65  return emplace_back(std::move(other));
66 }
67 
68 Fraction& Key::add(std::string&& fraction, Condition::Comp comp) {
69  return emplace_back(std::move(fraction), comp);
70 }
71 
72 Fraction& Key::add(const char* buf, uint32_t len,
73  Condition::Comp comp) {
74  return emplace_back(buf, len, comp);
75 }
76 
77 
78 Fraction& Key::insert(uint32_t idx, Fraction&& other) {
79  return *Vec::insert(idx, std::move(other));
80 }
81 
82 Fraction& Key::insert(uint32_t idx, std::string&& fraction,
83  Condition::Comp comp) {
84  return *Vec::insert(idx, std::move(fraction), comp);
85 }
86 
87 Fraction& Key::insert(uint32_t idx, const char* buf, uint32_t len,
88  Condition::Comp comp) {
89  return *Vec::insert(idx, buf, len, comp);
90 }
91 
92 
93 void Key::get(DB::Cell::Key& key) const {
94  key.free();
95  key.add(*this);
96 }
97 
98 void Key::remove(uint32_t idx, bool recursive) {
99  if(recursive)
100  erase(cbegin()+idx, cend());
101  else
102  erase(cbegin()+idx);
103 }
104 
105 void Key::print(std::ostream& out) const {
106  out << "Key(";
107  if(size())
108  display(out << "size=" << size() << " fractions=");
109  out << ')';
110 }
111 
112 void Key::display(std::ostream& out, bool pretty) const {
113  out << '[';
114  for(auto it = cbegin(); it != cend(); ) {
115  it->print(out, pretty);
116  if(++it != cend())
117  out << ", ";
118  }
119  out << "]";
120 }
121 
122 
123 }}}
SWC::Core::Vector< Fraction >::erase
SWC_CAN_INLINE iterator erase(size_type offset) noexcept(_NoExceptMoveAssign &&_NoExceptDestructor)
Definition: Vector.h:464
SWC::Core::Vector< Fraction >::resize
SWC_CAN_INLINE void resize(size_type sz, ArgsT &&... args)
Definition: Vector.h:308
SWC::Core::Vector< Fraction >::clear
SWC_CAN_INLINE void clear() noexcept(_NoExceptDestructor)
Definition: Vector.h:120
SWC::Core::Vector< Fraction >::operator=
SWC_CAN_INLINE Vector & operator=(Vector &&other) noexcept
Definition: Vector.h:141
SWC::DB::Specs::Key::~Key
~Key() noexcept
Definition: SpecsKey.cc:38
SWC::DB::Specs::Key::copy
void copy(const Key &other)
Definition: SpecsKey.cc:40
SWC::DB::Cell::Key
Definition: CellKey.h:24
SWC::DB::Specs::Key
Definition: SpecsKey.h:136
SWC::DB::Specs::Key::remove
void remove(uint32_t idx, bool recursive=false)
Definition: SpecsKey.cc:98
SWC::DB::Cell::Key::add
SWC_CAN_INLINE void add(const std::string_view &fraction)
Definition: CellKey.h:86
SWC::DB::Specs::Fraction
Definition: SpecsKey.h:18
SWC::DB::Specs::Fraction::print
void print(std::ostream &out, bool pretty=true) const
Definition: SpecsKey.cc:15
SWC::DB::Cell::Key::data
uint8_t * data
Definition: CellKey.h:257
SWC::Condition::Comp
Comp
Definition: Comparators.h:27
SWC::DB::Specs::Key::print
void print(std::ostream &out) const
Definition: SpecsKey.cc:105
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::DB::Specs::Key::equal
bool SWC_PURE_FUNC equal(const Key &other) const noexcept
Definition: SpecsKey.cc:44
SWC::DB::Specs::Key::set
void set(const DB::Cell::Key &cell_key, Condition::Comp comp)
Definition: SpecsKey.cc:48
SWC::DB::Specs::Fraction::comp
Condition::Comp comp
Definition: SpecsKey.h:20
SpecsKey.h
SWC::Core::Vector< Fraction >
SWC::DB::Cell::Key::free
SWC_CAN_INLINE void free() noexcept
Definition: CellKey.h:73
SWC::DB::Specs::Key::add
Fraction & add(Fraction &&other)
Definition: SpecsKey.cc:64
SWC::DB::Cell::Key::count
uint24_t count
Definition: CellKey.h:255
SWC::Core::Vector< Fraction >::cend
constexpr SWC_CAN_INLINE const_iterator cend() const noexcept
Definition: Vector.h:232
SWC::Condition::to_string
const char *SWC_CONST_FUNC to_string(Comp comp) noexcept
Definition: Comparators.cc:174
SWC::DB::Specs::Key::display
void display(std::ostream &out, bool pretty=true) const
Definition: SpecsKey.cc:112
SWC::DB::Specs::Key::Key
SWC_CAN_INLINE Key() noexcept
Definition: SpecsKey.h:143
SWC::Core::Vector< Fraction >::cbegin
constexpr SWC_CAN_INLINE const_iterator cbegin() const noexcept
Definition: Vector.h:216
SWC::Core::Vector< Fraction >::size
constexpr SWC_CAN_INLINE size_type size() const noexcept
Definition: Vector.h:189
SWC::Core::Vector< Fraction >::emplace_back
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
Definition: Vector.h:349
SWC::Core::Vector< Fraction >::insert
SWC_CAN_INLINE iterator insert(size_type offset, ArgsT &&... args)
Definition: Vector.h:367
SWC::DB::Specs::Key::get
SWC_CAN_INLINE std::string_view get(const uint32_t idx, Condition::Comp &comp) const
Definition: SpecsKey.h:251
SWC::DB::Specs::Key::insert
Fraction & insert(uint32_t idx, Fraction &&other)
Definition: SpecsKey.cc:78
SWC::Serialization::decode_vi32
constexpr SWC_CAN_INLINE uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:254
SWC::Core::Vector< Fraction >::begin
constexpr SWC_CAN_INLINE iterator begin() noexcept
Definition: Vector.h:211