24 #ifndef TSL_HTRIE_SET_H 25 #define TSL_HTRIE_SET_H 29 #include <initializer_list> 49 class Hash =
tsl::ah::str_hash<CharT>,
50 class KeySizeT = std::uint16_t>
54 using is_iterator =
tsl::detail_array_hash::is_iterator<U>;
59 using char_type =
typename ht::char_type;
60 using key_size_type =
typename ht::key_size_type;
61 using size_type =
typename ht::size_type;
62 using hasher =
typename ht::hasher;
63 using iterator =
typename ht::iterator;
64 using const_iterator =
typename ht::const_iterator;
65 using prefix_iterator =
typename ht::prefix_iterator;
66 using const_prefix_iterator =
typename ht::const_prefix_iterator;
69 explicit htrie_set(
const Hash& hash = Hash()): m_ht(hash, ht::HASH_NODE_DEFAULT_MAX_LOAD_FACTOR,
70 ht::DEFAULT_BURST_THRESHOLD)
75 const Hash& hash = Hash()): m_ht(hash, ht::HASH_NODE_DEFAULT_MAX_LOAD_FACTOR,
80 template<
class InputIt,
typename std::enable_if<is_iterator<InputIt>::value>::type* =
nullptr>
82 const Hash& hash = Hash()):
htrie_set(hash)
89 #ifdef TSL_HT_HAS_STRING_VIEW 97 const Hash& hash = Hash()):
htrie_set(hash)
105 #ifdef TSL_HT_HAS_STRING_VIEW 126 iterator
begin()
noexcept {
return m_ht.begin(); }
127 const_iterator
begin()
const noexcept {
return m_ht.begin(); }
128 const_iterator
cbegin()
const noexcept {
return m_ht.cbegin(); }
130 iterator
end()
noexcept {
return m_ht.end(); }
131 const_iterator
end()
const noexcept {
return m_ht.end(); }
132 const_iterator
cend()
const noexcept {
return m_ht.cend(); }
138 bool empty()
const noexcept {
return m_ht.empty(); }
139 size_type
size()
const noexcept {
return m_ht.size(); }
140 size_type
max_size()
const noexcept {
return m_ht.max_size(); }
141 size_type
max_key_size()
const noexcept {
return m_ht.max_key_size(); }
152 void clear()
noexcept { m_ht.clear(); }
156 std::pair<iterator,
bool>
insert_ks(
const CharT* key, size_type key_size) {
157 return m_ht.insert(key, key_size);
159 #ifdef TSL_HT_HAS_STRING_VIEW 164 std::pair<iterator,
bool>
insert(
const CharT* key) {
165 return m_ht.insert(key, std::strlen(key));
168 std::pair<iterator,
bool>
insert(
const std::basic_string<CharT>& key) {
169 return m_ht.insert(key.data(), key.size());
175 template<
class InputIt,
typename std::enable_if<is_iterator<InputIt>::value>::type* =
nullptr>
176 void insert(InputIt first, InputIt last) {
177 for(
auto it = first; it != last; ++it) {
184 #ifdef TSL_HT_HAS_STRING_VIEW 189 void insert(std::initializer_list<
const CharT*> ilist) {
190 insert(ilist.begin(), ilist.end());
196 std::pair<iterator,
bool>
emplace_ks(
const CharT* key, size_type key_size) {
197 return m_ht.insert(key, key_size);
199 #ifdef TSL_HT_HAS_STRING_VIEW 204 std::pair<iterator,
bool>
emplace(
const CharT* key) {
205 return m_ht.insert(key, std::strlen(key));
208 std::pair<iterator,
bool>
emplace(
const std::basic_string<CharT>& key) {
209 return m_ht.insert(key.data(), key.size());
215 iterator
erase(const_iterator pos) {
return m_ht.erase(pos); }
216 iterator
erase(const_iterator first, const_iterator last) {
return m_ht.erase(first, last); }
220 size_type
erase_ks(
const CharT* key, size_type key_size) {
221 return m_ht.erase(key, key_size);
223 #ifdef TSL_HT_HAS_STRING_VIEW 229 return m_ht.erase(key, std::strlen(key));
232 size_type
erase(
const std::basic_string<CharT>& key) {
233 return m_ht.erase(key.data(), key.size());
243 return m_ht.erase_prefix(prefix, prefix_size);
245 #ifdef TSL_HT_HAS_STRING_VIEW 257 return m_ht.erase_prefix(prefix, std::strlen(prefix));
264 return m_ht.erase_prefix(prefix.data(), prefix.size());
276 size_type
count_ks(
const CharT* key, size_type key_size)
const {
return m_ht.count(key, key_size); }
277 #ifdef TSL_HT_HAS_STRING_VIEW 280 size_type
count(
const CharT* key)
const {
return m_ht.count(key, std::strlen(key)); }
281 size_type
count(
const std::basic_string<CharT>& key)
const {
return m_ht.count(key.data(), key.size()); }
286 iterator
find_ks(
const CharT* key, size_type key_size) {
287 return m_ht.find(key, key_size);
290 const_iterator
find_ks(
const CharT* key, size_type key_size)
const {
291 return m_ht.find(key, key_size);
293 #ifdef TSL_HT_HAS_STRING_VIEW 302 iterator
find(
const CharT* key) {
303 return m_ht.find(key, std::strlen(key));
306 const_iterator
find(
const CharT* key)
const {
307 return m_ht.find(key, std::strlen(key));
310 iterator
find(
const std::basic_string<CharT>& key) {
311 return m_ht.find(key.data(), key.size());
314 const_iterator
find(
const std::basic_string<CharT>& key)
const {
315 return m_ht.find(key.data(), key.size());
321 std::pair<iterator, iterator>
equal_range_ks(
const CharT* key, size_type key_size) {
322 return m_ht.equal_range(key, key_size);
325 std::pair<const_iterator, const_iterator>
equal_range_ks(
const CharT* key, size_type key_size)
const {
326 return m_ht.equal_range(key, key_size);
328 #ifdef TSL_HT_HAS_STRING_VIEW 338 return m_ht.equal_range(key, std::strlen(key));
341 std::pair<const_iterator, const_iterator>
equal_range(
const CharT* key)
const {
342 return m_ht.equal_range(key, std::strlen(key));
345 std::pair<iterator, iterator>
equal_range(
const std::basic_string<CharT>& key) {
346 return m_ht.equal_range(key.data(), key.size());
349 std::pair<const_iterator, const_iterator>
equal_range(
const std::basic_string<CharT>& key)
const {
350 return m_ht.equal_range(key.data(), key.size());
361 return m_ht.equal_prefix_range(prefix, prefix_size);
367 std::pair<const_prefix_iterator, const_prefix_iterator>
equal_prefix_range_ks(
const CharT* prefix, size_type prefix_size)
const {
368 return m_ht.equal_prefix_range(prefix, prefix_size);
370 #ifdef TSL_HT_HAS_STRING_VIEW 389 return m_ht.equal_prefix_range(prefix, std::strlen(prefix));
395 std::pair<const_prefix_iterator, const_prefix_iterator>
equal_prefix_range(
const CharT* prefix)
const {
396 return m_ht.equal_prefix_range(prefix, std::strlen(prefix));
402 std::pair<prefix_iterator, prefix_iterator>
equal_prefix_range(
const std::basic_string<CharT>& prefix) {
403 return m_ht.equal_prefix_range(prefix.data(), prefix.size());
409 std::pair<const_prefix_iterator, const_prefix_iterator>
equal_prefix_range(
const std::basic_string<CharT>& prefix)
const {
410 return m_ht.equal_prefix_range(prefix.data(), prefix.size());
432 return m_ht.longest_prefix(key, key_size);
439 return m_ht.longest_prefix(key, key_size);
441 #ifdef TSL_HT_HAS_STRING_VIEW 460 return m_ht.longest_prefix(key, std::strlen(key));
467 return m_ht.longest_prefix(key, std::strlen(key));
474 return m_ht.longest_prefix(key.data(), key.size());
481 return m_ht.longest_prefix(key.data(), key.size());
522 template<
class Serializer>
524 m_ht.serialize(serializer);
546 template<
class Deserializer>
549 set.m_ht.deserialize(deserializer, hash_compatible);
555 if(lhs.size() != rhs.size()) {
559 std::string key_buffer;
560 for(
auto it = lhs.cbegin(); it != lhs.cend(); ++it) {
563 const auto it_element_rhs = rhs.find(key_buffer);
564 if(it_element_rhs == rhs.cend()) {
573 return !operator==(lhs, rhs);
const_iterator cend() const noexcept
Definition: htrie_set.h:132
std::pair< prefix_iterator, prefix_iterator > equal_prefix_range_ks(const CharT *prefix, size_type prefix_size)
Definition: htrie_set.h:360
size_type count(const std::basic_string< CharT > &key) const
Definition: htrie_set.h:281
static htrie_set deserialize(Deserializer &deserializer, bool hash_compatible=false)
Definition: htrie_set.h:547
iterator find(const CharT *key)
Definition: htrie_set.h:302
size_type max_key_size() const noexcept
Definition: htrie_set.h:141
std::pair< const_prefix_iterator, const_prefix_iterator > equal_prefix_range(const CharT *prefix) const
Definition: htrie_set.h:395
Definition: htrie_hash.h:68
const_iterator begin() const noexcept
Definition: htrie_set.h:127
void shrink_to_fit()
Definition: htrie_set.h:146
htrie_set(size_type burst_threshold, const Hash &hash=Hash())
Definition: htrie_set.h:74
void max_load_factor(float ml)
Definition: htrie_set.h:491
size_type erase(const CharT *key)
Definition: htrie_set.h:228
void burst_threshold(size_type threshold)
Definition: htrie_set.h:498
htrie_set(const Hash &hash=Hash())
Definition: htrie_set.h:69
size_type erase(const std::basic_string< CharT > &key)
Definition: htrie_set.h:232
std::pair< iterator, bool > emplace(const std::basic_string< CharT > &key)
Definition: htrie_set.h:208
size_type erase_ks(const CharT *key, size_type key_size)
Definition: htrie_set.h:220
std::pair< const_prefix_iterator, const_prefix_iterator > equal_prefix_range_ks(const CharT *prefix, size_type prefix_size) const
Definition: htrie_set.h:367
std::pair< iterator, iterator > equal_range_ks(const CharT *key, size_type key_size)
Definition: htrie_set.h:321
std::pair< iterator, iterator > equal_range(const CharT *key)
Definition: htrie_set.h:337
void serialize(Serializer &serializer) const
Definition: htrie_set.h:523
void insert(std::initializer_list< const CharT *> ilist)
Definition: htrie_set.h:189
iterator erase(const_iterator pos)
Definition: htrie_set.h:215
htrie_set(InputIt first, InputIt last, const Hash &hash=Hash())
Definition: htrie_set.h:81
size_type size() const noexcept
Definition: htrie_set.h:139
std::pair< iterator, bool > insert_ks(const CharT *key, size_type key_size)
Definition: htrie_set.h:156
std::pair< iterator, iterator > equal_range(const std::basic_string< CharT > &key)
Definition: htrie_set.h:345
void insert(InputIt first, InputIt last)
Definition: htrie_set.h:176
const_iterator end() const noexcept
Definition: htrie_set.h:131
size_type erase_prefix(const CharT *prefix)
Definition: htrie_set.h:256
size_type count(const CharT *key) const
Definition: htrie_set.h:280
void clear() noexcept
Definition: htrie_set.h:152
iterator end() noexcept
Definition: htrie_set.h:130
std::pair< iterator, bool > insert(const std::basic_string< CharT > &key)
Definition: htrie_set.h:168
std::pair< const_iterator, const_iterator > equal_range_ks(const CharT *key, size_type key_size) const
Definition: htrie_set.h:325
std::pair< const_iterator, const_iterator > equal_range(const CharT *key) const
Definition: htrie_set.h:341
std::pair< const_iterator, const_iterator > equal_range(const std::basic_string< CharT > &key) const
Definition: htrie_set.h:349
iterator find(const std::basic_string< CharT > &key)
Definition: htrie_set.h:310
std::pair< iterator, bool > emplace_ks(const CharT *key, size_type key_size)
Definition: htrie_set.h:196
size_type burst_threshold() const
Definition: htrie_set.h:497
Definition: htrie_set.h:51
size_type erase_prefix_ks(const CharT *prefix, size_type prefix_size)
Definition: htrie_set.h:242
size_type erase_prefix(const std::basic_string< CharT > &prefix)
Definition: htrie_set.h:263
friend void swap(htrie_set &lhs, htrie_set &rhs)
Definition: htrie_set.h:576
friend bool operator==(const htrie_set &lhs, const htrie_set &rhs)
Definition: htrie_set.h:554
iterator find_ks(const CharT *key, size_type key_size)
Definition: htrie_set.h:286
hasher hash_function() const
Definition: htrie_set.h:504
std::pair< const_prefix_iterator, const_prefix_iterator > equal_prefix_range(const std::basic_string< CharT > &prefix) const
Definition: htrie_set.h:409
const_iterator longest_prefix_ks(const CharT *key, size_type key_size) const
Definition: htrie_set.h:438
void swap(htrie_set &other)
Definition: htrie_set.h:270
std::pair< iterator, bool > insert(const CharT *key)
Definition: htrie_set.h:164
size_type count_ks(const CharT *key, size_type key_size) const
Definition: htrie_set.h:276
std::pair< prefix_iterator, prefix_iterator > equal_prefix_range(const std::basic_string< CharT > &prefix)
Definition: htrie_set.h:402
iterator longest_prefix(const std::basic_string< CharT > &key)
Definition: htrie_set.h:473
std::pair< iterator, bool > emplace(const CharT *key)
Definition: htrie_set.h:204
iterator longest_prefix(const CharT *key)
Definition: htrie_set.h:459
const_iterator find(const std::basic_string< CharT > &key) const
Definition: htrie_set.h:314
htrie_set(std::initializer_list< const CharT *> init, const Hash &hash=Hash())
Definition: htrie_set.h:96
float max_load_factor() const
Definition: htrie_set.h:490
iterator longest_prefix_ks(const CharT *key, size_type key_size)
Definition: htrie_set.h:431
Definition: htrie_hash.h:130
iterator begin() noexcept
Definition: htrie_set.h:126
size_type max_size() const noexcept
Definition: htrie_set.h:140
Definition: htrie_hash.h:70
const_iterator longest_prefix(const CharT *key) const
Definition: htrie_set.h:466
const_iterator find_ks(const CharT *key, size_type key_size) const
Definition: htrie_set.h:290
htrie_set & operator=(std::initializer_list< const CharT *> ilist)
Definition: htrie_set.h:113
bool empty() const noexcept
Definition: htrie_set.h:138
friend bool operator!=(const htrie_set &lhs, const htrie_set &rhs)
Definition: htrie_set.h:572
std::pair< prefix_iterator, prefix_iterator > equal_prefix_range(const CharT *prefix)
Definition: htrie_set.h:388
const_iterator cbegin() const noexcept
Definition: htrie_set.h:128
const_iterator find(const CharT *key) const
Definition: htrie_set.h:306
iterator erase(const_iterator first, const_iterator last)
Definition: htrie_set.h:216
const_iterator longest_prefix(const std::basic_string< CharT > &key) const
Definition: htrie_set.h:480