|
|
@@ -43,8 +43,7 @@ template <typename Trie, typename Iter> class trie_reverse_iterator;
|
|
|
*/
|
|
|
template <typename K, typename V, typename Compare> class trie {
|
|
|
private:
|
|
|
- using self_t = trie<K, V, Compare>;
|
|
|
- using impl_value_type = const_propogating_ptr<value_ptr<self_t>>;
|
|
|
+ using impl_value_type = const_propogating_ptr<value_ptr<trie>>;
|
|
|
using backing_t = std::map<K, impl_value_type, Compare>;
|
|
|
template <typename KS>
|
|
|
using element_type = std::decay_t<decltype(*std::begin(std::declval<KS>()))>;
|
|
|
@@ -63,29 +62,32 @@ public:
|
|
|
using local_const_reverse_iterator =
|
|
|
typename backing_t::const_reverse_iterator;
|
|
|
|
|
|
- using iterator = trie_iterator<self_t, local_iterator>;
|
|
|
- using const_iterator = trie_iterator<self_t const, local_const_iterator>;
|
|
|
- using post_iterator = trie_reverse_iterator<self_t, local_iterator>;
|
|
|
+ using iterator = trie_iterator<trie, local_iterator>;
|
|
|
+ using const_iterator = trie_iterator<trie const, local_const_iterator>;
|
|
|
+ using post_iterator = trie_reverse_iterator<trie, local_iterator>;
|
|
|
using const_post_iterator =
|
|
|
- trie_reverse_iterator<self_t const, local_const_iterator>;
|
|
|
- using reverse_iterator =
|
|
|
- trie_reverse_iterator<self_t, local_reverse_iterator>;
|
|
|
+ trie_reverse_iterator<trie const, local_const_iterator>;
|
|
|
+ using reverse_iterator = trie_reverse_iterator<trie, local_reverse_iterator>;
|
|
|
using const_reverse_iterator =
|
|
|
- trie_reverse_iterator<self_t const, local_const_reverse_iterator>;
|
|
|
+ trie_reverse_iterator<trie const, local_const_reverse_iterator>;
|
|
|
|
|
|
private:
|
|
|
- using impl_iterator = detail::trie_iterator_base<self_t, local_iterator>;
|
|
|
+ using impl_iterator = detail::trie_iterator_base<trie, local_iterator>;
|
|
|
using impl_const_iterator =
|
|
|
- detail::trie_iterator_base<self_t const, local_const_iterator>;
|
|
|
+ detail::trie_iterator_base<trie const, local_const_iterator>;
|
|
|
+
|
|
|
+private:
|
|
|
+ mapped_type value_{};
|
|
|
+ backing_t impl_{};
|
|
|
|
|
|
public:
|
|
|
trie() {}
|
|
|
trie(trie const & other);
|
|
|
trie(trie && other) : trie() { swap(*this, other); }
|
|
|
~trie() { clear(); }
|
|
|
- self_t & operator=(mapped_type const & value);
|
|
|
- self_t & operator=(trie const & value);
|
|
|
- self_t & operator=(trie && value);
|
|
|
+ trie & operator=(mapped_type const & value);
|
|
|
+ trie & operator=(trie const & value);
|
|
|
+ trie & operator=(trie && value);
|
|
|
|
|
|
operator mapped_type &() { return value(); }
|
|
|
operator mapped_type const &() const { return value(); }
|
|
|
@@ -93,13 +95,13 @@ public:
|
|
|
mapped_type const & value() const { return value_; }
|
|
|
|
|
|
template <typename KS, typename = is_collection_t<KS>>
|
|
|
- self_t & operator[](KS const & keys) {
|
|
|
+ trie & operator[](KS const & keys) {
|
|
|
return *emplace(keys).first.parent_trie_.top();
|
|
|
}
|
|
|
- self_t & operator[](key_type const & key) {
|
|
|
+ trie & operator[](key_type const & key) {
|
|
|
return *emplace(key).first.parent_trie_.top();
|
|
|
}
|
|
|
- self_t & operator[](std::initializer_list<key_type> keys) {
|
|
|
+ trie & operator[](std::initializer_list<key_type> keys) {
|
|
|
return operator[]<>(keys);
|
|
|
}
|
|
|
|
|
|
@@ -207,12 +209,7 @@ private:
|
|
|
const_iterator it1 = lhs.begin(), it2 = rhs.begin();
|
|
|
const_iterator const end1 = lhs.end(), end2 = lhs.end();
|
|
|
for (; it1 != end1 && it2 != end2; ++it1, ++it2) {
|
|
|
- if (!it1.keys_.empty() && !it2.keys_.empty() &&
|
|
|
- it1.keys_.back() != it2.keys_.back()) {
|
|
|
- return false;
|
|
|
- } else if (it1.root().value_ != it2.root().value_) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if (it1 != it2) { return false; }
|
|
|
}
|
|
|
return it1 == end1 && it2 == end2;
|
|
|
}
|
|
|
@@ -226,9 +223,6 @@ private:
|
|
|
swap(lhs.value_, rhs.value_);
|
|
|
swap(lhs.impl_, rhs.impl_);
|
|
|
}
|
|
|
-
|
|
|
- mapped_type value_{};
|
|
|
- backing_t impl_{};
|
|
|
};
|
|
|
|
|
|
#include "trie.tpp"
|