#ifndef PB_DS_TRIE_POLICY_HPP
#define PB_DS_TRIE_POLICY_HPP
#include <string>
#include <ext/pb_ds/detail/type_utils.hpp>
#include <ext/pb_ds/detail/trie_policy/trie_policy_base.hpp>
namespace pb_ds
{
template<typename Const_Node_Iterator,
typename Node_Iterator,
typename E_Access_Traits,
typename Allocator>
struct null_trie_node_update
{ };
#define PB_DS_STATIC_ASSERT(UNIQUE, E) \
typedef detail::static_assert_dumclass<sizeof(detail::static_assert<bool(E)>)> UNIQUE##_static_assert_type
#define PB_DS_CLASS_T_DEC \
template<typename String, typename String::value_type Min_E_Val, typename String::value_type Max_E_Val, bool Reverse, typename Allocator>
#define PB_DS_CLASS_C_DEC \
string_trie_e_access_traits<String, Min_E_Val,Max_E_Val,Reverse,Allocator>
template<typename String = std::string,
typename String::value_type Min_E_Val = detail::__numeric_traits<typename String::value_type>::__min,
typename String::value_type Max_E_Val = detail::__numeric_traits<typename String::value_type>::__max,
bool Reverse = false,
typename Allocator = std::allocator<char> >
struct string_trie_e_access_traits
{
public:
typedef typename Allocator::size_type size_type;
typedef String key_type;
typedef typename Allocator::template rebind<key_type>::other key_rebind;
typedef typename key_rebind::const_reference const_key_reference;
enum
{
reverse = Reverse
};
typedef typename detail::__conditional_type<Reverse, typename String::const_reverse_iterator, typename String::const_iterator>::__type const_iterator;
typedef typename std::iterator_traits<const_iterator>::value_type e_type;
enum
{
min_e_val = Min_E_Val,
max_e_val = Max_E_Val,
max_size = max_e_val - min_e_val + 1
};
PB_DS_STATIC_ASSERT(min_max_size, max_size >= 2);
inline static const_iterator
begin(const_key_reference);
inline static const_iterator
end(const_key_reference);
inline static size_type
e_pos(e_type e);
private:
inline static const_iterator
begin_imp(const_key_reference, detail::false_type);
inline static const_iterator
begin_imp(const_key_reference, detail::true_type);
inline static const_iterator
end_imp(const_key_reference, detail::false_type);
inline static const_iterator
end_imp(const_key_reference, detail::true_type);
static detail::integral_constant<int, Reverse> s_rev_ind;
};
#include <ext/pb_ds/detail/trie_policy/string_trie_e_access_traits_imp.hpp>
#undef PB_DS_CLASS_T_DEC
#undef PB_DS_CLASS_C_DEC
#define PB_DS_CLASS_T_DEC \
template<typename Const_Node_Iterator,typename Node_Iterator,class E_Access_Traits, typename Allocator>
#define PB_DS_CLASS_C_DEC \
trie_prefix_search_node_update<Const_Node_Iterator, Node_Iterator, E_Access_Traits,Allocator>
#define PB_DS_BASE_C_DEC \
detail::trie_policy_base<Const_Node_Iterator,Node_Iterator,E_Access_Traits, Allocator>
template<typename Const_Node_Iterator,
typename Node_Iterator,
typename E_Access_Traits,
typename Allocator>
class trie_prefix_search_node_update : private PB_DS_BASE_C_DEC
{
private:
typedef PB_DS_BASE_C_DEC base_type;
public:
typedef typename base_type::key_type key_type;
typedef typename base_type::const_key_reference const_key_reference;
typedef E_Access_Traits e_access_traits;
typedef typename e_access_traits::const_iterator const_e_iterator;
typedef Allocator allocator;
typedef typename allocator::size_type size_type;
typedef detail::null_node_metadata metadata_type;
typedef Const_Node_Iterator const_node_iterator;
typedef Node_Iterator node_iterator;
typedef typename const_node_iterator::value_type const_iterator;
typedef typename node_iterator::value_type iterator;
std::pair<const_iterator, const_iterator>
prefix_range(const_key_reference) const;
std::pair<iterator, iterator>
prefix_range(const_key_reference);
std::pair<const_iterator, const_iterator>
prefix_range(const_e_iterator, const_e_iterator) const;
std::pair<iterator, iterator>
prefix_range(const_e_iterator, const_e_iterator);
protected:
inline void
operator()(node_iterator node_it, const_node_iterator end_nd_it) const;
private:
virtual const_iterator
end() const = 0;
virtual iterator
end() = 0;
virtual const_node_iterator
node_begin() const = 0;
virtual node_iterator
node_begin() = 0;
virtual const_node_iterator
node_end() const = 0;
virtual node_iterator
node_end() = 0;
virtual const e_access_traits&
get_e_access_traits() const = 0;
node_iterator
next_child(node_iterator, const_e_iterator, const_e_iterator,
node_iterator, const e_access_traits&);
};
#include <ext/pb_ds/detail/trie_policy/prefix_search_node_update_imp.hpp>
#undef PB_DS_CLASS_C_DEC
#define PB_DS_CLASS_C_DEC \
trie_order_statistics_node_update<Const_Node_Iterator, Node_Iterator,E_Access_Traits, Allocator>
template<typename Const_Node_Iterator,
typename Node_Iterator,
typename E_Access_Traits,
typename Allocator>
class trie_order_statistics_node_update : private PB_DS_BASE_C_DEC
{
private:
typedef PB_DS_BASE_C_DEC base_type;
public:
typedef E_Access_Traits e_access_traits;
typedef typename e_access_traits::const_iterator const_e_iterator;
typedef Allocator allocator;
typedef typename allocator::size_type size_type;
typedef typename base_type::key_type key_type;
typedef typename base_type::const_key_reference const_key_reference;
typedef size_type metadata_type;
typedef Const_Node_Iterator const_node_iterator;
typedef Node_Iterator node_iterator;
typedef typename const_node_iterator::value_type const_iterator;
typedef typename node_iterator::value_type iterator;
inline const_iterator
find_by_order(size_type) const;
inline iterator
find_by_order(size_type);
inline size_type
order_of_key(const_key_reference) const;
inline size_type
order_of_prefix(const_e_iterator, const_e_iterator) const;
private:
typedef typename base_type::const_reference const_reference;
typedef typename base_type::const_pointer const_pointer;
typedef typename Allocator::template rebind<metadata_type>::other metadata_rebind;
typedef typename metadata_rebind::const_reference const_metadata_reference;
typedef typename metadata_rebind::reference metadata_reference;
virtual bool
empty() const = 0;
virtual iterator
begin() = 0;
virtual iterator
end() = 0;
virtual const_node_iterator
node_begin() const = 0;
virtual node_iterator
node_begin() = 0;
virtual const_node_iterator
node_end() const = 0;
virtual node_iterator
node_end() = 0;
virtual e_access_traits&
get_e_access_traits() = 0;
protected:
inline void
operator()(node_iterator, const_node_iterator) const;
virtual
~trie_order_statistics_node_update();
};
#include <ext/pb_ds/detail/trie_policy/order_statistics_imp.hpp>
#undef PB_DS_CLASS_T_DEC
#undef PB_DS_CLASS_C_DEC
#undef PB_DS_BASE_C_DEC
#undef PB_DS_STATIC_ASSERT
}
#endif