Akumuli
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
stringpool.h
1 
17 #pragma once
18 
19 #include <atomic>
20 #include <deque>
21 #include <mutex>
22 #include <unordered_map>
23 #include <unordered_set>
24 #include <vector>
25 
26 #include "akumuli_def.h"
27 
28 namespace Akumuli {
29 
30 
34  size_t buffer_offset;
36  size_t offset;
37 };
38 
39 struct StringPool {
40 
41  typedef std::pair<const char*, int> StringT;
42  const int MAX_BIN_SIZE = AKU_LIMITS_MAX_SNAME * 0x1000;
43 
44  std::deque<std::vector<char>> pool;
45  mutable std::mutex pool_mutex;
46  std::atomic<size_t> counter;
47 
48  StringPool();
49  StringPool(StringPool const&) = delete;
50  StringPool& operator=(StringPool const&) = delete;
51 
52  StringT add(const char* begin, const char* end, uint64_t payload);
53 
55  size_t size() const;
56 
62  std::vector<StringT> regex_match(const char* regex, StringPoolOffset* outoffset = nullptr,
63  size_t* psize = nullptr) const;
64 };
65 
66 struct StringTools {
68  typedef std::pair<const char*, int> StringT;
69 
70  static size_t hash(StringT str);
71  static bool equal(StringT lhs, StringT rhs);
72 
73  typedef std::unordered_map<StringT, uint64_t, decltype(&StringTools::hash),
74  decltype(&StringTools::equal)>
75  TableT;
76 
77  typedef std::unordered_set<StringT, decltype(&StringTools::hash), decltype(&StringTools::equal)>
78  SetT;
79 
81  typedef std::unordered_map<uint64_t, StringT> InvT;
82 
83  static TableT create_table(size_t size);
84 
85  static SetT create_set(size_t size);
86 
87  static uint64_t extract_id_from_pool(StringPool::StringT res);
88 };
89 }
std::vector< StringT > regex_match(const char *regex, StringPoolOffset *outoffset=nullptr, size_t *psize=nullptr) const
Definition: stringpool.cpp:70
std::pair< const char *, int > StringT
Pooled string.
Definition: stringpool.h:68
size_t offset
Offset inside buffer.
Definition: stringpool.h:36
std::unordered_map< uint64_t, StringT > InvT
Inverted table type (id to string mapping)
Definition: stringpool.h:81
size_t size() const
Get number of stored strings atomically.
Definition: stringpool.cpp:66
size_t buffer_offset
Offset of the buffer.
Definition: stringpool.h:34
Definition: stringpool.h:66
Definition: stringpool.h:39
Offset inside string-pool.
Definition: stringpool.h:32