 |
SWC-DB
v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
|
Go to the documentation of this file.
7 #ifndef swcdb_db_cells_CellKey_h
8 #define swcdb_db_cells_CellKey_h
17 namespace SWC {
namespace DB {
27 typedef std::shared_ptr<Key>
Ptr;
32 explicit Key(
const uint8_t** bufp,
size_t* remainp,
bool owner);
34 explicit Key(
const Key& other);
81 bool sane() const noexcept {
86 void add(
const std::string_view& fraction) {
87 add(fraction.data(), fraction.length());
91 void add(
const std::string& fraction) {
92 add(fraction.c_str(), fraction.length());
96 void add(
const char* fraction) {
97 add(fraction, strlen(fraction));
101 void add(
const char* fraction, uint32_t len) {
102 add(
reinterpret_cast<const uint8_t*
>(fraction), len);
109 void add(
const T cbegin,
const T cend) {
113 const uint8_t* old =
data;
114 uint32_t old_size =
size;
116 for(
auto it=cbegin; it != cend; ++it)
120 uint8_t* ptr =
data =
new uint8_t[
size];
122 memcpy(ptr, old, old_size);
127 for(
auto it=cbegin; it != cend; ++it) {
129 memcpy(ptr,
reinterpret_cast<const uint8_t*
>(it->c_str()), it->size());
132 count += cend - cbegin;
139 add(key.cbegin(), key.cend());
150 void insert(uint32_t idx,
const std::string& fraction) {
151 insert(idx, fraction.c_str(), fraction.length());
155 void insert(uint32_t idx,
const char* fraction) {
156 insert(idx, fraction, strlen(fraction));
160 void insert(uint32_t idx,
const char* fraction, uint32_t len) {
161 insert(idx,
reinterpret_cast<const uint8_t*
>(fraction), len);
166 void remove(uint32_t idx,
bool recursive=
false);
170 const char* fraction;
173 return std::string(fraction,
length);
176 void get(uint32_t idx,
const char** fraction, uint32_t*
length)
const;
180 return count == other.count &&
181 ((!
data && !other.data) ||
193 void encode(uint8_t** bufp) const;
195 void decode(const uint8_t** bufp,
size_t* remainp,
bool owner);
201 const uint8_t* ptr =
data;
204 for(
auto it = key.begin(); it != key.cend(); ++it, ptr+=len) {
207 reinterpret_cast<const typename T::value_type::value_type*
>(ptr),
216 if(key.size() !=
count)
220 const uint8_t* ptr =
data;
221 for(
auto it = key.cbegin(); it != key.cend(); ++it, ptr+=len) {
225 reinterpret_cast<const uint8_t*
>(it->c_str()), it->length()))
235 std::stringstream ss;
242 void display(std::ostream& out,
bool pretty=
true,
243 const char* sep =
",")
const;
247 void print(std::ostream& out)
const;
262 uint8_t*
_data(
const uint8_t* ptr) {
264 ?
static_cast<uint8_t*
>(memcpy(
new uint8_t[
size], ptr,
size))
272 Key::Key(
const uint8_t** bufp,
size_t* remainp,
bool owner)
278 const uint8_t* ptr_start = *bufp;
281 *remainp -= (
size = *bufp - ptr_start);
282 data =
own ?
_data(ptr_start) :
const_cast<uint8_t*
>(ptr_start);
291 : own(other.
size), count(other.count),
size(other.
size),
297 : own(a_own), count(other.count),
size(other.
size),
308 other.data =
nullptr;
337 void Key::decode(
const uint8_t** bufp,
size_t* remainp,
bool owner) {
341 const uint8_t* ptr_start = *bufp;
344 *remainp -= (
size = *bufp - ptr_start);
345 data = (
own = owner) ?
_data(ptr_start) :
const_cast<uint8_t*
>(ptr_start);
357 #ifdef SWC_IMPL_SOURCE
361 #endif // swcdb_db_Cells_CellKey_h
SWC_CAN_INLINE void add(const T &key)
SWC_CAN_INLINE std::string get_string(uint32_t idx) const
constexpr SWC_CAN_INLINE void encode_vi24(uint8_t **bufp, uint24_t val)
void get(uint32_t idx, const char **fraction, uint32_t *length) const
constexpr SWC_CAN_INLINE uint8_t encoded_length_vi24(uint24_t val) noexcept
constexpr SWC_CAN_INLINE bool sane() const noexcept
constexpr SWC_CAN_INLINE Key(Key &&other) noexcept
SWC_CAN_INLINE void insert(uint32_t idx, const std::string &fraction)
constexpr SWC_CAN_INLINE bool equal(const Key &other) const noexcept
SWC_CAN_INLINE ~Key() noexcept
Key & operator=(const Key &)=delete
SWC_CAN_INLINE bool eq(const uint8_t *p1, uint32_t p1_len, const uint8_t *p2, uint32_t p2_len) noexcept
SWC_CAN_INLINE void add(const char *fraction)
void decode(const uint8_t **bufp, size_t *remainp, bool owner)
SWC_CAN_INLINE void add(const std::string_view &fraction)
void display_details(std::ostream &out, bool pretty=true) const
SWC_CAN_INLINE void add(const T cbegin, const T cend)
constexpr SWC_CAN_INLINE bool empty() const noexcept
SWC_CAN_INLINE void convert_to(T &key) const
SWC_CAN_INLINE void insert(uint32_t idx, const char *fraction, uint32_t len)
SWC_CAN_INLINE void insert(uint32_t idx, const char *fraction)
The SWC-DB C++ namespace 'SWC'.
SWC_CAN_INLINE void _free() noexcept
constexpr SWC_CAN_INLINE Key() noexcept
constexpr SWC_CAN_INLINE uint24_t decode_vi24(const uint8_t **bufp, size_t *remainp)
SWC_CAN_INLINE std::string to_string() const
void copy(const Key &other)
void length(const ConnHandlerPtr &conn, const Event::Ptr &ev)
constexpr uint32_t encoded_length() const noexcept
SWC_CAN_INLINE void free() noexcept
SWC_CAN_INLINE void add(const std::string &fraction)
SWC_CAN_INLINE void read(const T &key)
SWC_CAN_INLINE uint8_t * _data(const uint8_t *ptr)
SWC_CAN_INLINE Key & operator=(Key &&other) noexcept
void print(std::ostream &out) const
void remove(uint32_t idx, bool recursive=false)
SWC_CAN_INLINE bool equal(const T &key) const
std::shared_ptr< Key > Ptr
void move(Key &other) noexcept
SWC_CAN_INLINE void add(const char *fraction, uint32_t len)
void display(std::ostream &out, bool pretty=true, const char *sep=",") const
friend std::ostream & operator<<(std::ostream &out, const Key &key)
void encode(uint8_t **bufp) const