SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
BaseUnorderedMap.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 client { namespace Query { namespace Update {
11 
12 namespace Handlers {
13 
14 
17  for(auto it = cbegin(); it != cend(); ++it)
18  if(!it->second->error() && !it->second->empty())
19  return true;
20  return false;
21 }
22 
23 bool BaseUnorderedMap::empty() noexcept {
25  for(auto it = cbegin(); it != cend(); ++it)
26  if(!it->second->empty())
27  return false;
28  return true;
29 }
30 
31 size_t BaseUnorderedMap::size() noexcept {
32  size_t total = 0;
34  for(auto it = cbegin(); it != cend(); ++it)
35  total += it->second->size();
36  return total;
37 }
38 
39 size_t BaseUnorderedMap::size_bytes() noexcept {
40  size_t total = 0;
42  for(auto it = cbegin(); it != cend(); ++it)
43  total += it->second->size_bytes();
44  return total;
45 }
46 
47 void BaseUnorderedMap::next(Base::Colms& cols) noexcept {
48  cols.clear();
49  Core::MutexSptd::scope lock(m_mutex);
50  cols.reserve(Map::size());
51  for(auto it = cbegin(); it != cend(); ++it) {
52  if(!it->second->error() && !it->second->empty())
53  cols.push_back(it->second.get());
54  }
55 }
56 
58  Core::MutexSptd::scope lock(m_mutex);
59  auto it = find(cid);
60  return it != cend() && !it->second->error() && !it->second->empty()
61  ? it->second.get() : nullptr;
62 }
63 
64 void BaseUnorderedMap::error(cid_t cid, int err) noexcept {
65  Core::MutexSptd::scope lock(m_mutex);
66  auto it = find(cid);
67  if(it != cend())
68  it->second->error(err);
69 }
70 
73  uint32_t versions,
74  uint32_t ttl_secs,
75  DB::Types::Column type) {
77  auto& col = (*this)[cid];
78  if(!col)
79  col.reset(new ColumnMutable(cid, seq, versions, ttl_secs, type));
80  return col;
81 }
82 
83 bool BaseUnorderedMap::exists(const cid_t cid) noexcept{
84  Core::MutexSptd::scope lock(m_mutex);
85  return find(cid) != cend();
86 }
87 
88 void BaseUnorderedMap::add(const cid_t cid, const DB::Cells::Cell& cell,
89  bool finalized) {
91  {
93  auto it = find(cid);
94  if(it == cend())
95  SWC_THROWF(ENOKEY, "Map Missing column=" SWC_FMT_LU " (1st do create)",
96  cid);
97  col = it->second;
98  }
99  col->add(cell, finalized);
100 }
101 
103  Core::MutexSptd::scope lock(m_mutex);
104  auto it = find(cid);
105  return it == cend() ? nullptr : it->second;
106 }
107 
109  Core::MutexSptd::scope lock(m_mutex);
110  auto it = find(cid);
111  return it == cend() ? nullptr : it->second.get();
112 }
113 
114 }}}}}
SWC::client::Query::Update::Handlers::BaseUnorderedMap::size
size_t size() noexcept
Definition: BaseUnorderedMap.cc:31
SWC::client::Query::Update::Handlers::BaseUnorderedMap::empty
virtual bool empty() noexcept override
Definition: BaseUnorderedMap.cc:23
SWC::Core::MutexSptd::scope
Definition: MutexSptd.h:96
SWC::client::Query::Update::Handlers::BaseUnorderedMap::exists
bool exists(const cid_t cid) noexcept
Definition: BaseUnorderedMap.cc:83
SWC::DB::Types::Column
Column
Definition: Column.h:18
SWC::client::Query::Update::Handlers::BaseUnorderedMap::m_mutex
Core::MutexSptd m_mutex
Definition: BaseUnorderedMap.h:73
SWC::client::Query::Update::Handlers::BaseUnorderedMap::next
virtual void next(Base::Colms &cols) noexcept override
Definition: BaseUnorderedMap.cc:47
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::client::Query::Update::Handlers::BaseUnorderedMap::get
ColumnMutable::Ptr get(const cid_t cid) noexcept
Definition: BaseUnorderedMap.cc:102
SWC::client::Query::Update::Handlers::BaseUnorderedMap::requires_commit
virtual bool requires_commit() noexcept override
Definition: BaseUnorderedMap.cc:15
SWC::DB::Types::KeySeq
KeySeq
Definition: KeySeq.h:13
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
size
uint32_t size
Buffer size.
Definition: HeaderBufferInfo.h:47
SWC::client::Query::Update::Handlers::Base::Column
Definition: Base.h:30
SWC_THROWF
#define SWC_THROWF(_code_, _fmt_,...)
Definition: Exception.h:136
SWC::client::Query::Update::Handlers::BaseUnorderedMap::size_bytes
virtual size_t size_bytes() noexcept override
Definition: BaseUnorderedMap.cc:39
SWC_FMT_LU
#define SWC_FMT_LU
Definition: Compat.h:98
SWC::cid_t
uint64_t cid_t
Definition: Identifiers.h:16
SWC::client::Query::Update::Handlers::Base::error
virtual int error() noexcept
Definition: Base.h:159
SWC::Core::Vector
Definition: Vector.h:14
SWC::client::Query::Update::Handlers::BaseUnorderedMap::add
void add(const cid_t cid, const DB::Cells::Cell &cell, bool finalized=false)
Definition: BaseUnorderedMap.cc:88
SWC::client::Query::Update::Handlers::BaseUnorderedMap::create
SWC_CAN_INLINE ColumnMutable::Ptr & create(const DB::Schema::Ptr &schema)
Definition: BaseUnorderedMap.h:49
SWC::client::Query::Update::Handlers::BaseUnorderedMap::get_base_ptr
Base::Column * get_base_ptr(cid_t cid) noexcept
Definition: BaseUnorderedMap.cc:108
SWC::client::Query::Update::Handlers::ColumnMutable
Definition: BaseColumnMutable.h:20
SWC::client::Query::Update::Handlers::ColumnMutable::Ptr
std::shared_ptr< ColumnMutable > Ptr
Definition: BaseColumnMutable.h:22
BaseUnorderedMap.h