178 using traits_type = TraitsT;
180 typedef KeyT key_type;
181 typedef typename key_type::value_type key_unit_type;
182 typedef ValueT value_type;
183 typedef size_t size_type;
192 typedef std::map<key_unit_type, trie_node> children_type;
194 children_type children;
199 trie_node(
const trie_node& other);
200 trie_node(trie_node&& other);
202 void swap(trie_node& other);
205 template<
bool IsConst>
208 using _is_const = std::bool_constant<IsConst>;
210 using child_pos_type =
215 trie_node_type* node;
216 child_pos_type child_pos;
218 stack_item(trie_node_type* _node,
const child_pos_type& _child_pos) : node(_node), child_pos(_child_pos)
221 bool operator==(
const stack_item& r)
const
223 return node == r.node && child_pos == r.child_pos;
226 bool operator!=(
const stack_item& r)
const
228 return !operator==(r);
232 using const_node_stack_type = std::vector<stack_item<true>>;
233 using node_stack_type = std::vector<stack_item<false>>;
243 const trie_node* m_ref_node =
nullptr;
318 bool operator==(
const trie_map& other)
const;
319 bool operator!=(
const trie_map& other)
const;
336 void insert(
const key_type& key, value_type value);
346 void insert(
const key_unit_type* key, size_type len, value_type value);
357 bool erase(
const key_unit_type* key, size_type len);
436 bool empty() const noexcept;
464 void insert_into_tree(trie_node& node, const key_unit_type* key, const key_unit_type* key_end, value_type value);
466 const trie_node* find_prefix_node(
467 const trie_node& node, const key_unit_type* prefix, const key_unit_type* prefix_end) const;
469 template<
bool IsConst>
470 void find_prefix_node_with_stack(
471 std::vector<stack_item<IsConst>>& node_stack, mdds::detail::const_t<trie_node, IsConst>& node,
472 const key_unit_type* prefix, const key_unit_type* prefix_end) const;
474 template<
bool IsConst>
475 key_type build_key_buffer_from_node_stack(const std::vector<stack_item<IsConst>>& node_stack) const;
477 void count_values(size_type& n, const trie_node& node) const;
479 bool descend_for_equality(const trie_node& left, const trie_node& right) const;
498 using pack_value_type =
typename TraitsT::pack_value_type;
499 using packed_type = std::vector<pack_value_type>;
503 friend class trie_map<KeyT, ValueT, TraitsT>;
507 using traits_type = TraitsT;
508 typedef KeyT key_type;
509 typedef typename key_type::value_type key_unit_type;
510 typedef ValueT value_type;
511 typedef size_t size_type;
521 const key_unit_type* key;
525 entry(
const key_unit_type* _key, size_type _keylen, value_type _value)
526 : key(_key), keylen(_keylen), value(_value)
531 using value_store_type = std::deque<value_type>;
534 static constexpr auto null_value = std::numeric_limits<pack_value_type>::max();
536 static constexpr auto max_value_pos = null_value - 1u;
541 const value_type* value;
543 std::deque<trie_node*> children;
545 trie_node(key_unit_type _key) : key(_key), value(nullptr)
551 const value_store_type* value_store =
nullptr;
553 const pack_value_type* node_pos =
nullptr;
554 const pack_value_type* child_pos =
nullptr;
555 const pack_value_type* child_end =
nullptr;
558 const value_store_type* _value_store,
const pack_value_type* _node_pos,
const pack_value_type* _child_pos,
559 const pack_value_type* _child_end)
560 : value_store(_value_store), node_pos(_node_pos), child_pos(_child_pos), child_end(_child_end)
563 bool operator==(
const stack_item& other)
const
565 return value_store == other.value_store && node_pos == other.node_pos && child_pos == other.child_pos &&
566 child_end == other.child_end;
569 bool operator!=(
const stack_item& other)
const
571 return !operator==(other);
574 bool has_value()
const
576 return *node_pos != null_value;
579 pack_value_type get_value_pos()
const
585 typedef std::vector<stack_item> node_stack_type;
586 typedef std::deque<trie_node> node_pool_type;
587 typedef std::vector<std::tuple<size_t, key_unit_type>> child_offsets_type;
589 packed_trie_map(trie::detail::move_to_pack, trie_map<KeyT, ValueT, TraitsT>& from);
599 const packed_type* m_packed =
nullptr;
600 const value_store_type* m_value_store =
nullptr;
601 const pack_value_type* m_pos =
nullptr;
603 const_node_type(
const packed_type* packed,
const value_store_type* value_store,
const pack_value_type* p);
757 size_type
size() const noexcept;
759 bool empty() const noexcept;
775 template<typename FuncT = trie::value_serializer<value_type>>
776 void save_state(std::ostream& os) const;
784 template<typename FuncT = trie::value_serializer<value_type>>
785 void load_state(std::istream& is);
793 std::
string dump_structure(trie::dump_structure_type type) const;
796 void dump_trie_traversal(std::ostream& os) const;
798 node_stack_type get_root_stack() const;
801 trie_node& root, node_pool_type& node_pool, const
entry* start, const
entry* end, size_type pos);
803 size_type compact_node(const trie_node& node);
805 template<typename ModeT, typename NodeT>
806 size_type compact_node(ModeT, NodeT& node);
808 void check_value_size_or_throw() const;
810 size_type push_value_to_store(trie::detail::copy_to_pack, const value_type& value);
811 size_type push_value_to_store(trie::detail::move_to_pack, value_type& value);
813 void push_child_offsets(size_type offset, const child_offsets_type& child_offsets);
816 void compact(const trie_node& root);
818 template<typename ModeT, typename NodeT>
819 void compact(ModeT, NodeT& root);
821 template<typename _Handler>
822 void traverse_tree(_Handler hdl) const;
825 value_store_type m_value_store;
826 packed_type m_packed;
Definition trie_map.hpp:520