#ifdef PB_DS_PAT_TRIE_DEBUG_
#include <cassert>
-#endif // #ifdef PB_DS_PAT_TRIE_DEBUG_
+#endif
namespace pb_ds
{
namespace detail
{
+#define PB_DS_CLASS_T_DEC \
+ template<typename Type_Traits, typename E_Access_Traits, \
+ typename Metadata, typename Allocator>
+
+#define PB_DS_CLASS_C_DEC \
+ pat_trie_internal_node<Type_Traits, E_Access_Traits, Metadata, Allocator>
+
+#define PB_DS_BASE_C_DEC \
+ pat_trie_node_base<Type_Traits, E_Access_Traits, Metadata, Allocator>
+
+#define PB_DS_LEAF_C_DEC \
+ pat_trie_leaf<Type_Traits, E_Access_Traits, Metadata, Allocator>
-#define PB_DS_CLASS_T_DEC \
- template< \
- class Type_Traits, \
- class E_Access_Traits, \
- class Metadata, \
- class Allocator>
-
-#define PB_DS_CLASS_C_DEC \
- pat_trie_internal_node< \
- Type_Traits, \
- E_Access_Traits, \
- Metadata, \
- Allocator>
-
-#define PB_DS_BASE_C_DEC \
- pat_trie_node_base< \
- Type_Traits, \
- E_Access_Traits, \
- Metadata, \
- Allocator>
-
-#define PB_DS_LEAF_C_DEC \
- pat_trie_leaf< \
- Type_Traits, \
- E_Access_Traits, \
- Metadata, \
- Allocator>
-
-#define PB_DS_STATIC_ASSERT(UNIQUE, E) \
- typedef \
- static_assert_dumclass< \
- sizeof(static_assert<(bool)(E)>)> \
- UNIQUE##static_assert_type
+#define PB_DS_STATIC_ASSERT(UNIQUE, E) \
+ typedef static_assert_dumclass<sizeof(static_assert<(bool)(E)>)> UNIQUE##static_assert_type
#ifdef PB_DS_PAT_TRIE_DEBUG_
#define PB_DS_DBG_ASSERT(X) assert(X)
#define PB_DS_DBG_VERIFY(X) assert(X)
#define PB_DS_DBG_ONLY(X) X
-#else // #ifdef PB_DS_PAT_TRIE_DEBUG_
+#else
#define PB_DS_DBG_ASSERT(X)
-#define PB_DS_DBG_VERIFY(X) {if((X)==0);}
+#define PB_DS_DBG_VERIFY(X) { if((X)==0); }
#define PB_DS_DBG_ONLY(X) ;
-#endif // #ifdef PB_DS_PAT_TRIE_DEBUG_
+#endif
template<typename Type_Traits,
- class E_Access_Traits,
- class Metadata,
- class Allocator>
+ typename E_Access_Traits,
+ typename Metadata,
+ typename Allocator>
struct pat_trie_internal_node : public PB_DS_BASE_C_DEC
{
- public:
- enum
- {
- arr_size =
- E_Access_Traits::max_size + 1
- };
-
private:
- typedef typename Allocator::size_type size_type;
+ typedef PB_DS_BASE_C_DEC base_type;
+ typedef Type_Traits type_traits;
+ typedef typename type_traits::value_type value_type;
+ typedef typename Allocator::size_type size_type;
typedef E_Access_Traits e_access_traits;
-
- typedef
- typename Allocator::template rebind<
- e_access_traits>::other::const_pointer
- const_e_access_traits_pointer;
-
typedef typename e_access_traits::const_iterator const_e_iterator;
+ typedef typename Allocator::template rebind<e_access_traits>::other access_rebind;
+ typedef typename access_rebind::const_pointer const_e_access_traits_pointer;
- typedef
- typename Allocator::template rebind<
- PB_DS_BASE_C_DEC >::other::pointer
- node_pointer;
-
- typedef
- typename Allocator::template rebind<
- PB_DS_BASE_C_DEC >::other::const_pointer
- const_node_pointer;
+ typedef typename Allocator::template rebind<base_type>::other base_rebind;
+ typedef typename base_rebind::pointer node_pointer;
+ typedef typename base_rebind::const_pointer const_node_pointer;
typedef PB_DS_LEAF_C_DEC leaf;
+ typedef typename Allocator::template rebind<leaf>::other leaf_rebind;
+ typedef typename leaf_rebind::pointer leaf_pointer;
+ typedef typename leaf_rebind::const_pointer const_leaf_pointer;
- typedef
- typename Allocator::template rebind<
- leaf>::other
- leaf_allocator;
-
- typedef typename leaf_allocator::pointer leaf_pointer;
-
- typedef typename leaf_allocator::const_pointer const_leaf_pointer;
-
- typedef
- typename Allocator::template rebind<
- PB_DS_CLASS_C_DEC>::other
- internal_node_allocator;
-
- typedef
- typename Allocator::template rebind<
- PB_DS_CLASS_C_DEC>::other::const_pointer
- const_internal_node_pointer;
-
- typedef
- typename Allocator::template rebind<
- PB_DS_CLASS_C_DEC>::other::pointer
- internal_node_pointer;
-
- PB_DS_STATIC_ASSERT(min_arr_size, arr_size >= 2);
-
- typedef typename Type_Traits::value_type value_type;
+ typedef typename Allocator::template rebind<pat_trie_internal_node>::other internal_node_rebind;
+ typedef typename internal_node_rebind::pointer internal_node_pointer;
+ typedef typename internal_node_rebind::const_pointer const_internal_node_pointer;
#ifdef PB_DS_PAT_TRIE_DEBUG_
- typedef
- typename PB_DS_BASE_C_DEC::subtree_debug_info
- subtree_debug_info;
-#endif // #ifdef PB_DS_PAT_TRIE_DEBUG_
+ typedef typename base_type::subtree_debug_info subtree_debug_info;
- typedef PB_DS_BASE_C_DEC base_type;
+ virtual subtree_debug_info
+ assert_valid_imp(const_e_access_traits_pointer) const;
+#endif
- private:
inline size_type
- get_pref_pos(const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits) const;
-
-#ifdef PB_DS_PAT_TRIE_DEBUG_
- virtual subtree_debug_info
- assert_valid_imp(const_e_access_traits_pointer p_traits) const;
-#endif // #ifdef PB_DS_PAT_TRIE_DEBUG_
+ get_pref_pos(const_e_iterator, const_e_iterator,
+ const_e_access_traits_pointer) const;
public:
- typedef
- typename Allocator::template rebind<
- node_pointer>::other::pointer
- node_pointer_pointer;
+ typedef typename Allocator::template rebind<node_pointer>::other node_pointer_rebind;
+ typedef typename node_pointer_rebind::pointer node_pointer_pointer;
+ typedef typename node_pointer_rebind::reference node_pointer_reference;
- typedef
- typename Allocator::template rebind<
- node_pointer>::other::reference
- node_pointer_reference;
+ enum
+ {
+ arr_size = E_Access_Traits::max_size + 1
+ };
+ PB_DS_STATIC_ASSERT(min_arr_size, arr_size >= 2);
#include <ext/pb_ds/detail/pat_trie_/const_child_iterator.hpp>
#include <ext/pb_ds/detail/pat_trie_/child_iterator.hpp>
- public:
- pat_trie_internal_node(size_type e_ind, const const_e_iterator pref_b_it);
+ pat_trie_internal_node(size_type, const const_e_iterator);
void
- update_prefixes(const_e_access_traits_pointer p_traits);
+ update_prefixes(const_e_access_traits_pointer);
const_iterator
begin() const;
end();
inline node_pointer
- get_child_node(const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits);
+ get_child_node(const_e_iterator, const_e_iterator,
+ const_e_access_traits_pointer);
inline const_node_pointer
- get_child_node(const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits) const;
+ get_child_node(const_e_iterator, const_e_iterator,
+ const_e_access_traits_pointer) const;
inline iterator
- get_child_it(const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits);
+ get_child_it(const_e_iterator, const_e_iterator,
+ const_e_access_traits_pointer);
inline node_pointer
- get_lower_bound_child_node(const_e_iterator b_it, const_e_iterator e_it, size_type checked_ind, const_e_access_traits_pointer p_traits);
+ get_lower_bound_child_node(const_e_iterator, const_e_iterator,
+ size_type, const_e_access_traits_pointer);
inline node_pointer
- add_child(node_pointer p_nd, const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits);
+ add_child(node_pointer, const_e_iterator, const_e_iterator,
+ const_e_access_traits_pointer);
inline const_node_pointer
- get_join_child(const_node_pointer p_nd, const_e_access_traits_pointer p_traits) const;
+ get_join_child(const_node_pointer, const_e_access_traits_pointer) const;
inline node_pointer
- get_join_child(node_pointer p_nd, const_e_access_traits_pointer p_traits);
+ get_join_child(node_pointer, const_e_access_traits_pointer);
void
remove_child(node_pointer p_nd);
remove_child(iterator it);
void
- replace_child(node_pointer p_nd, const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits);
+ replace_child(node_pointer, const_e_iterator, const_e_iterator,
+ const_e_access_traits_pointer);
inline const_e_iterator
pref_b_it() const;
get_e_ind() const;
bool
- should_be_mine(const_e_iterator b_it, const_e_iterator e_it, size_type checked_ind, const_e_access_traits_pointer p_traits) const;
+ should_be_mine(const_e_iterator, const_e_iterator, size_type,
+ const_e_access_traits_pointer) const;
leaf_pointer
leftmost_descendant();
#ifdef PB_DS_PAT_TRIE_DEBUG_
size_type
e_ind() const;
-#endif // #ifdef PB_DS_PAT_TRIE_DEBUG_
+#endif
private:
- pat_trie_internal_node(const PB_DS_CLASS_C_DEC& other);
+ pat_trie_internal_node(const pat_trie_internal_node&);
size_type
get_begin_pos() const;
- private:
const size_type m_e_ind;
-
const_e_iterator m_pref_b_it;
const_e_iterator m_pref_e_it;
-
node_pointer m_a_p_children[arr_size];
-
- static leaf_allocator s_leaf_alloc;
-
- static internal_node_allocator s_internal_node_alloc;
+ static leaf_rebind s_leaf_alloc;
+ static internal_node_rebind s_internal_node_alloc;
};
PB_DS_CLASS_T_DEC
- typename PB_DS_CLASS_C_DEC::leaf_allocator
+ typename PB_DS_CLASS_C_DEC::leaf_rebind
PB_DS_CLASS_C_DEC::s_leaf_alloc;
PB_DS_CLASS_T_DEC
- typename PB_DS_CLASS_C_DEC::internal_node_allocator
+ typename PB_DS_CLASS_C_DEC::internal_node_rebind
PB_DS_CLASS_C_DEC::s_internal_node_alloc;
PB_DS_CLASS_T_DEC
inline typename PB_DS_CLASS_C_DEC::size_type
PB_DS_CLASS_C_DEC::
- get_pref_pos(const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits) const
+ get_pref_pos(const_e_iterator b_it, const_e_iterator e_it,
+ const_e_access_traits_pointer p_traits) const
{
if (static_cast<size_t>(std::distance(b_it, e_it)) <= m_e_ind)
- return (0);
-
+ return 0;
std::advance(b_it, m_e_ind);
-
- return (1 + p_traits->e_pos(*b_it));
+ return 1 + p_traits->e_pos(*b_it);
}
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
pat_trie_internal_node(size_type e_ind, const const_e_iterator pref_b_it) :
PB_DS_BASE_C_DEC(pat_trie_internal_node_type),
- m_e_ind(e_ind),
- m_pref_b_it(pref_b_it),
- m_pref_e_it(pref_b_it)
+ m_e_ind(e_ind), m_pref_b_it(pref_b_it), m_pref_e_it(pref_b_it)
{
std::advance(m_pref_e_it, m_e_ind);
-
std::fill(m_a_p_children, m_a_p_children + arr_size,
static_cast<node_pointer>(NULL));
}
PB_DS_CLASS_C_DEC::
update_prefixes(const_e_access_traits_pointer p_traits)
{
- node_pointer p_first =* begin();
-
+ node_pointer p_first = *begin();
if (p_first->m_type == pat_trie_leaf_node_type)
- m_pref_b_it =
- p_traits->begin(
- E_Access_Traits::extract_key(
- static_cast<const_leaf_pointer>(p_first)->value()));
+ {
+ const_leaf_pointer p = static_cast<const_leaf_pointer>(p_first);
+ m_pref_b_it = p_traits->begin(e_access_traits::extract_key(p->value()));
+ }
else
{
PB_DS_DBG_ASSERT(p_first->m_type == pat_trie_internal_node_type);
-
m_pref_b_it = static_cast<internal_node_pointer>(p_first)->pref_b_it();
}
-
m_pref_e_it = m_pref_b_it;
-
std::advance(m_pref_e_it, m_e_ind);
}
PB_DS_CLASS_C_DEC::
begin() const
{
- return (const_iterator(
- const_cast<node_pointer_pointer>(m_a_p_children) + get_begin_pos(),
- const_cast<node_pointer_pointer>(m_a_p_children) + arr_size));
+ typedef node_pointer_pointer pointer_type;
+ pointer_type p = const_cast<pointer_type>(m_a_p_children);
+ return const_iterator(p + get_begin_pos(), p + arr_size);
}
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
begin()
{
- return (iterator(
- m_a_p_children + get_begin_pos(),
- m_a_p_children + arr_size));
+ return iterator(m_a_p_children + get_begin_pos(),
+ m_a_p_children + arr_size);
}
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
end() const
{
- return (const_iterator(
- const_cast<node_pointer_pointer>(m_a_p_children) + arr_size,
- const_cast<node_pointer_pointer>(m_a_p_children) + arr_size));
+ typedef node_pointer_pointer pointer_type;
+ pointer_type p = const_cast<pointer_type>(m_a_p_children) + arr_size;
+ return const_iterator(p, p);
}
PB_DS_CLASS_T_DEC
typename PB_DS_CLASS_C_DEC::iterator
PB_DS_CLASS_C_DEC::
end()
- {
- return (iterator( m_a_p_children + arr_size, m_a_p_children + arr_size));
- }
+ { return iterator(m_a_p_children + arr_size, m_a_p_children + arr_size); }
PB_DS_CLASS_T_DEC
inline typename PB_DS_CLASS_C_DEC::node_pointer
PB_DS_CLASS_C_DEC::
- get_child_node(const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits)
+ get_child_node(const_e_iterator b_it, const_e_iterator e_it,
+ const_e_access_traits_pointer p_traits)
{
- const size_type i = get_pref_pos( b_it, e_it, p_traits);
-
+ const size_type i = get_pref_pos(b_it, e_it, p_traits);
PB_DS_DBG_ASSERT(i < arr_size);
-
- return (m_a_p_children[i]);
+ return m_a_p_children[i];
}
PB_DS_CLASS_T_DEC
inline typename PB_DS_CLASS_C_DEC::iterator
PB_DS_CLASS_C_DEC::
- get_child_it(const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits)
+ get_child_it(const_e_iterator b_it, const_e_iterator e_it,
+ const_e_access_traits_pointer p_traits)
{
- const size_type i = get_pref_pos( b_it, e_it, p_traits);
-
+ const size_type i = get_pref_pos(b_it, e_it, p_traits);
PB_DS_DBG_ASSERT(i < arr_size);
-
PB_DS_DBG_ASSERT(m_a_p_children[i] != NULL);
-
- return (iterator(m_a_p_children + i, m_a_p_children + i));
+ return iterator(m_a_p_children + i, m_a_p_children + i);
}
PB_DS_CLASS_T_DEC
inline typename PB_DS_CLASS_C_DEC::const_node_pointer
PB_DS_CLASS_C_DEC::
- get_child_node(const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits) const
- {
- return (const_cast<node_pointer>(get_child_node(b_it, e_it, p_traits)));
- }
+ get_child_node(const_e_iterator b_it, const_e_iterator e_it,
+ const_e_access_traits_pointer p_traits) const
+ { return const_cast<node_pointer>(get_child_node(b_it, e_it, p_traits)); }
PB_DS_CLASS_T_DEC
typename PB_DS_CLASS_C_DEC::node_pointer
PB_DS_CLASS_C_DEC::
- get_lower_bound_child_node(const_e_iterator b_it, const_e_iterator e_it, size_type checked_ind, const_e_access_traits_pointer p_traits)
+ get_lower_bound_child_node(const_e_iterator b_it, const_e_iterator e_it,
+ size_type checked_ind,
+ const_e_access_traits_pointer p_traits)
{
if (!should_be_mine(b_it, e_it, checked_ind, p_traits))
{
if (p_traits->cmp_prefixes(b_it, e_it, m_pref_b_it, m_pref_e_it, true))
- return (leftmost_descendant());
-
- return (rightmost_descendant());
+ return leftmost_descendant();
+ return rightmost_descendant();
}
- size_type i = get_pref_pos( b_it, e_it, p_traits);
-
+ size_type i = get_pref_pos(b_it, e_it, p_traits);
PB_DS_DBG_ASSERT(i < arr_size);
if (m_a_p_children[i] != NULL)
- return (m_a_p_children[i]);
+ return m_a_p_children[i];
while (++i < arr_size)
if (m_a_p_children[i] != NULL)
{
if (m_a_p_children[i]->m_type == pat_trie_leaf_node_type)
- return (m_a_p_children[i]);
+ return m_a_p_children[i];
- PB_DS_DBG_ASSERT(m_a_p_children[i]->m_type ==
- pat_trie_internal_node_type);
+ PB_DS_DBG_ASSERT(m_a_p_children[i]->m_type == pat_trie_internal_node_type);
- return (static_cast<internal_node_pointer>(
- m_a_p_children[i])->leftmost_descendant());
+ return static_cast<internal_node_pointer>(m_a_p_children[i])->leftmost_descendant();
}
- return (rightmost_descendant());
+ return rightmost_descendant();
}
PB_DS_CLASS_T_DEC
inline typename PB_DS_CLASS_C_DEC::node_pointer
PB_DS_CLASS_C_DEC::
- add_child(node_pointer p_nd, const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits)
+ add_child(node_pointer p_nd, const_e_iterator b_it, const_e_iterator e_it,
+ const_e_access_traits_pointer p_traits)
{
- const size_type i = get_pref_pos( b_it, e_it, p_traits);
-
+ const size_type i = get_pref_pos(b_it, e_it, p_traits);
PB_DS_DBG_ASSERT(i < arr_size);
-
if (m_a_p_children[i] == NULL)
{
m_a_p_children[i] = p_nd;
-
p_nd->m_p_parent = this;
-
- return (p_nd);
+ return p_nd;
}
-
- return (m_a_p_children[i]);
+ return m_a_p_children[i];
}
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
get_join_child(const_node_pointer p_nd, const_e_access_traits_pointer p_traits) const
{
- return (const_cast<internal_node_pointer>(this)->get_join_child(
- const_cast<node_pointer>(p_nd),
- p_traits));
+ node_pointer p = const_cast<node_pointer>(p_nd);
+ return const_cast<internal_node_pointer>(this)->get_join_child(p, p_traits);
}
PB_DS_CLASS_T_DEC
get_join_child(node_pointer p_nd, const_e_access_traits_pointer p_traits)
{
size_type i;
-
const_e_iterator b_it;
const_e_iterator e_it;
-
if (p_nd->m_type == pat_trie_leaf_node_type)
{
typename Type_Traits::const_key_reference r_key =
- e_access_traits::extract_key(
- static_cast<const_leaf_pointer>(p_nd)->value());
+ e_access_traits::extract_key(static_cast<const_leaf_pointer>(p_nd)->value());
b_it = p_traits->begin(r_key);
e_it = p_traits->end(r_key);
b_it = static_cast<internal_node_pointer>(p_nd)->pref_b_it();
e_it = static_cast<internal_node_pointer>(p_nd)->pref_e_it();
}
-
i = get_pref_pos(b_it, e_it, p_traits);
-
PB_DS_DBG_ASSERT(i < arr_size);
-
- return (m_a_p_children[i]);
+ return m_a_p_children[i];
}
PB_DS_CLASS_T_DEC
remove_child(node_pointer p_nd)
{
size_type i = 0;
-
for (; i < arr_size; ++i)
if (m_a_p_children[i] == p_nd)
{
m_a_p_children[i] = NULL;
-
return;
}
-
PB_DS_DBG_ASSERT(i != arr_size);
}
remove_child(iterator it)
{
iterator ret = it;
-
++ret;
-
* it.m_p_p_cur = NULL;
-
- return (ret);
+ return ret;
}
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
- replace_child(node_pointer p_nd, const_e_iterator b_it, const_e_iterator e_it, const_e_access_traits_pointer p_traits)
+ replace_child(node_pointer p_nd, const_e_iterator b_it,
+ const_e_iterator e_it,
+ const_e_access_traits_pointer p_traits)
{
- const size_type i = get_pref_pos( b_it, e_it, p_traits);
-
+ const size_type i = get_pref_pos(b_it, e_it, p_traits);
PB_DS_DBG_ASSERT(i < arr_size);
-
m_a_p_children[i] = p_nd;
-
p_nd->m_p_parent = this;
}
inline typename PB_DS_CLASS_C_DEC::const_e_iterator
PB_DS_CLASS_C_DEC::
pref_b_it() const
- {
- return (m_pref_b_it);
- }
+ { return m_pref_b_it; }
PB_DS_CLASS_T_DEC
inline typename PB_DS_CLASS_C_DEC::const_e_iterator
PB_DS_CLASS_C_DEC::
pref_e_it() const
- {
- return (m_pref_e_it);
- }
+ { return m_pref_e_it; }
PB_DS_CLASS_T_DEC
inline typename PB_DS_CLASS_C_DEC::size_type
PB_DS_CLASS_C_DEC::
get_e_ind() const
- {
- return (m_e_ind);
- }
+ { return m_e_ind; }
PB_DS_CLASS_T_DEC
bool
PB_DS_CLASS_C_DEC::
- should_be_mine(const_e_iterator b_it, const_e_iterator e_it, size_type checked_ind, const_e_access_traits_pointer p_traits) const
+ should_be_mine(const_e_iterator b_it, const_e_iterator e_it,
+ size_type checked_ind,
+ const_e_access_traits_pointer p_traits) const
{
if (m_e_ind == 0)
- return (true);
+ return true;
const size_type num_es = std::distance(b_it, e_it);
-
if (num_es < m_e_ind)
- return (false);
+ return false;
const_e_iterator key_b_it = b_it;
std::advance(key_b_it, checked_ind);
const_e_iterator value_e_it = m_pref_b_it;
std::advance(value_e_it, m_e_ind);
- return (p_traits->equal_prefixes( key_b_it, key_e_it, value_b_it, value_e_it));
+ return p_traits->equal_prefixes(key_b_it, key_e_it, value_b_it,
+ value_e_it);
}
PB_DS_CLASS_T_DEC
leftmost_descendant()
{
node_pointer p_pot =* begin();
-
if (p_pot->m_type == pat_trie_leaf_node_type)
return (static_cast<leaf_pointer>(p_pot));
-
PB_DS_DBG_ASSERT(p_pot->m_type == pat_trie_internal_node_type);
-
- return (static_cast<internal_node_pointer>(p_pot)->leftmost_descendant());
+ return static_cast<internal_node_pointer>(p_pot)->leftmost_descendant();
}
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
leftmost_descendant() const
{
- return (const_cast<internal_node_pointer>(this)->leftmost_descendant());
+ return const_cast<internal_node_pointer>(this)->leftmost_descendant();
}
PB_DS_CLASS_T_DEC
rightmost_descendant()
{
const size_type num_children = std::distance(begin(), end());
-
PB_DS_DBG_ASSERT(num_children >= 2);
iterator it = begin();
std::advance(it, num_children - 1);
-
node_pointer p_pot =* it;
-
if (p_pot->m_type == pat_trie_leaf_node_type)
- return (static_cast<leaf_pointer>(p_pot));
-
+ return static_cast<leaf_pointer>(p_pot);
PB_DS_DBG_ASSERT(p_pot->m_type == pat_trie_internal_node_type);
-
- return (static_cast<internal_node_pointer>(p_pot)->rightmost_descendant());
+ return static_cast<internal_node_pointer>(p_pot)->rightmost_descendant();
}
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
rightmost_descendant() const
{
- return (const_cast<internal_node_pointer>(this)->rightmost_descendant());
+ return const_cast<internal_node_pointer>(this)->rightmost_descendant();
}
#ifdef PB_DS_PAT_TRIE_DEBUG_
typename PB_DS_CLASS_C_DEC::size_type
PB_DS_CLASS_C_DEC::
e_ind() const
- {
- return (m_e_ind);
- }
+ { return m_e_ind; }
#endif // #ifdef PB_DS_PAT_TRIE_DEBUG_
PB_DS_CLASS_T_DEC
get_begin_pos() const
{
size_type i;
-
- for (i = 0; i < arr_size&& m_a_p_children[i] == NULL; ++i)
+ for (i = 0; i < arr_size && m_a_p_children[i] == NULL; ++i)
;
-
- return (i);
+ return i;
}
#ifdef PB_DS_PAT_TRIE_DEBUG_
assert_valid_imp(const_e_access_traits_pointer p_traits) const
{
PB_DS_DBG_ASSERT(base_type::m_type == pat_trie_internal_node_type);
-
- PB_DS_DBG_ASSERT(
- static_cast<size_type>(std::distance(pref_b_it(), pref_e_it())) ==
- m_e_ind);
-
- PB_DS_DBG_ASSERT(
- std::distance(begin(), end()) >= 2);
+ PB_DS_DBG_ASSERT(static_cast<size_type>(std::distance(pref_b_it(), pref_e_it())) == m_e_ind);
+ PB_DS_DBG_ASSERT(std::distance(begin(), end()) >= 2);
for (typename pat_trie_internal_node::const_iterator it = begin();
it != end(); ++it)
{
const_node_pointer p_nd =* it;
-
PB_DS_DBG_ASSERT(p_nd->m_p_parent == this);
-
subtree_debug_info child_ret = p_nd->assert_valid_imp(p_traits);
- PB_DS_DBG_ASSERT(
- static_cast<size_type>(std::distance(child_ret.first, child_ret.second)) >=
- m_e_ind);
-
+ PB_DS_DBG_ASSERT(static_cast<size_type>(std::distance(child_ret.first, child_ret.second)) >= m_e_ind);
PB_DS_DBG_ASSERT(should_be_mine(child_ret.first, child_ret.second, 0, p_traits));
-
- PB_DS_DBG_ASSERT(
- get_pref_pos(child_ret.first, child_ret.second, p_traits) ==
- static_cast<size_type>(it.m_p_p_cur - m_a_p_children));
+ PB_DS_DBG_ASSERT(get_pref_pos(child_ret.first, child_ret.second, p_traits) == static_cast<size_type>(it.m_p_p_cur - m_a_p_children));
}
-
- return (std::make_pair(pref_b_it(), pref_e_it()));
+ return std::make_pair(pref_b_it(), pref_e_it());
}
#endif // #ifdef PB_DS_PAT_TRIE_DEBUG_
#undef PB_DS_CLASS_T_DEC
-
#undef PB_DS_CLASS_C_DEC
-
#undef PB_DS_BASE_C_DEC
-
#undef PB_DS_LEAF_C_DEC
-
#undef PB_DS_STATIC_ASSERT
#undef PB_DS_DBG_ASSERT
} // namespace detail
} // namespace pb_ds
-#endif // #ifndef PB_DS_PAT_TRIE_NODE_BASE_HPP
-
+#endif
* Contains a resize trigger implementation.
*/
-#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_STATIC_ASSERT(UNIQUE, E) \
+ typedef detail::static_assert_dumclass<sizeof(detail::static_assert<(bool)(E)>)> UNIQUE##static_assert_type
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
-hash_load_check_resize_trigger(float load_min, float load_max) :
- m_load_min(load_min),
- m_load_max(load_max),
- m_next_shrink_size(0),
- m_next_grow_size(0),
- m_resize_needed(false)
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+hash_load_check_resize_trigger(float load_min, float load_max)
+: m_load_min(load_min), m_load_max(load_max), m_next_shrink_size(0),
+ m_next_grow_size(0), m_resize_needed(false)
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
notify_find_search_start()
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
notify_find_search_collision()
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
notify_find_search_end()
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
notify_insert_search_start()
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
notify_insert_search_collision()
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
notify_insert_search_end()
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
notify_erase_search_start()
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
notify_erase_search_collision()
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
notify_erase_search_end()
-{
- PB_DS_DBG_ONLY(assert_valid();)
- }
+{ PB_DS_DBG_ONLY(assert_valid();) }
PB_DS_CLASS_T_DEC
inline void
notify_inserted(size_type num_entries)
{
m_resize_needed = (num_entries >= m_next_grow_size);
-
size_base::set_size(num_entries);
-
PB_DS_DBG_ONLY(assert_valid();)
- }
+}
PB_DS_CLASS_T_DEC
inline void
notify_erased(size_type num_entries)
{
size_base::set_size(num_entries);
-
- m_resize_needed =
- num_entries <= m_next_shrink_size;
-
+ m_resize_needed = num_entries <= m_next_shrink_size;
PB_DS_DBG_ONLY(assert_valid();)
- }
+}
PB_DS_CLASS_T_DEC
inline bool
is_resize_needed() const
{
PB_DS_DBG_ONLY(assert_valid();)
-
- return (m_resize_needed);
+ return m_resize_needed;
}
PB_DS_CLASS_T_DEC
is_grow_needed(size_type /*size*/, size_type num_entries) const
{
PB_DS_DBG_ASSERT(m_resize_needed);
-
- return (num_entries >= m_next_grow_size);
+ return num_entries >= m_next_grow_size;
}
PB_DS_CLASS_T_DEC
PB_DS_CLASS_C_DEC::
-~hash_load_check_resize_trigger()
-{ }
+~hash_load_check_resize_trigger() { }
PB_DS_CLASS_T_DEC
void
notify_resized(size_type new_size)
{
m_resize_needed = false;
-
- m_next_grow_size =
- size_type(m_load_max* new_size - 1);
-
- m_next_shrink_size =
- size_type(m_load_min* new_size);
+ m_next_grow_size = size_type(m_load_max * new_size - 1);
+ m_next_shrink_size = size_type(m_load_min * new_size);
#ifdef PB_DS_HT_MAP_RESIZE_TRACE_
std::cerr << "hlcrt::notify_resized " <<
- static_cast<unsigned long>(new_size) << " " <<
- static_cast<unsigned long>(m_load_min) << " " <<
- static_cast<unsigned long>(m_load_max) << " " <<
+ static_cast<unsigned long>(new_size) << " " <<
+ static_cast<unsigned long>(m_load_min) << " " <<
+ static_cast<unsigned long>(m_load_max) << " " <<
static_cast<unsigned long>(m_next_shrink_size) << " " <<
- static_cast<unsigned long>(m_next_grow_size) << " " << std::endl;
-#endif // #ifdef PB_DS_HT_MAP_RESIZE_TRACE_
+ static_cast<unsigned long>(m_next_grow_size) << " " << std::endl;
+#endif
PB_DS_DBG_ONLY(assert_valid();)
- }
+}
PB_DS_CLASS_T_DEC
void
notify_externally_resized(size_type new_size)
{
m_resize_needed = false;
-
- size_type new_grow_size =
- size_type(m_load_max* new_size - 1);
-
- size_type new_shrink_size =
- size_type(m_load_min* new_size );
-
+ size_type new_grow_size = size_type(m_load_max * new_size - 1);
+ size_type new_shrink_size = size_type(m_load_min * new_size );
if (new_grow_size >= m_next_grow_size)
{
PB_DS_DBG_ASSERT(new_shrink_size > m_next_shrink_size);
-
m_next_grow_size = new_grow_size;
-
PB_DS_DBG_ONLY(assert_valid();)
#ifdef PB_DS_HT_MAP_RESIZE_TRACE_
std::cerr << "hlcrt::notify_externally_resized1 " <<
- static_cast<unsigned long>(new_size) << " " <<
- static_cast<unsigned long>(m_load_min) << " " <<
- static_cast<unsigned long>(m_load_max) << " " <<
+ static_cast<unsigned long>(new_size) << " " <<
+ static_cast<unsigned long>(m_load_min) << " " <<
+ static_cast<unsigned long>(m_load_max) << " " <<
static_cast<unsigned long>(m_next_shrink_size) << " " <<
- static_cast<unsigned long>(m_next_grow_size) << " " << std::endl;
-#endif // #ifdef PB_DS_HT_MAP_RESIZE_TRACE_
-
+ static_cast<unsigned long>(m_next_grow_size) << " " << std::endl;
+#endif
return;
}
PB_DS_DBG_ASSERT(new_shrink_size <= m_next_shrink_size);
-
m_next_shrink_size = new_shrink_size;
#ifdef PB_DS_HT_MAP_RESIZE_TRACE_
std::cerr << "hlcrt::notify_externally_resized2 " <<
- static_cast<unsigned long>(new_size) << " " <<
- static_cast<unsigned long>(m_load_min) << " " <<
- static_cast<unsigned long>(m_load_max) << " " <<
+ static_cast<unsigned long>(new_size) << " " <<
+ static_cast<unsigned long>(m_load_min) << " " <<
+ static_cast<unsigned long>(m_load_max) << " " <<
static_cast<unsigned long>(m_next_shrink_size) << " " <<
- static_cast<unsigned long>(m_next_grow_size) << " " << std::endl;
-#endif // #ifdef PB_DS_HT_MAP_RESIZE_TRACE_
+ static_cast<unsigned long>(m_next_grow_size) << " " << std::endl;
+#endif
PB_DS_DBG_ONLY(assert_valid();)
- }
+}
PB_DS_CLASS_T_DEC
void
notify_cleared()
{
PB_DS_DBG_ONLY(assert_valid();)
-
- size_base::set_size(0);
-
+ size_base::set_size(0);
m_resize_needed = (0 < m_next_shrink_size);
-
PB_DS_DBG_ONLY(assert_valid();)
- }
+}
PB_DS_CLASS_T_DEC
void
swap(PB_DS_CLASS_C_DEC& other)
{
PB_DS_DBG_ONLY(assert_valid();)
- PB_DS_DBG_ONLY(other.assert_valid();)
-
- size_base::swap(other);
-
+ PB_DS_DBG_ONLY(other.assert_valid();)
+
+ size_base::swap(other);
std::swap(m_load_min, other.m_load_min);
std::swap(m_load_max, other.m_load_max);
-
std::swap(m_resize_needed, other.m_resize_needed);
-
std::swap(m_next_grow_size, other.m_next_grow_size);
std::swap(m_next_shrink_size, other.m_next_shrink_size);
PB_DS_DBG_ONLY(assert_valid();)
- PB_DS_DBG_ONLY(other.assert_valid();)
- }
+ PB_DS_DBG_ONLY(other.assert_valid();)
+}
PB_DS_CLASS_T_DEC
inline std::pair<float, float>
get_loads() const
{
PB_DS_STATIC_ASSERT(access, external_load_access);
-
- return (std::make_pair(m_load_min, m_load_max));
+ return std::make_pair(m_load_min, m_load_max);
}
PB_DS_CLASS_T_DEC
set_loads(std::pair<float, float> load_pair)
{
PB_DS_STATIC_ASSERT(access, external_load_access);
-
const float old_load_min = m_load_min;
const float old_load_max = m_load_max;
const size_type old_next_shrink_size = m_next_shrink_size;
{
m_load_min = load_pair.first;
m_load_max = load_pair.second;
-
- do_resize(static_cast<size_type>(
- size_base::get_size() / ((m_load_min + m_load_max) / 2)));
+ do_resize(static_cast<size_type>(size_base::get_size() / ((m_load_min + m_load_max) / 2)));
}
- catch(...)
+ catch (...)
{
m_load_min = old_load_min;
m_load_max = old_load_max;
m_next_shrink_size = old_next_shrink_size;
m_next_grow_size = old_next_grow_size;
m_resize_needed = old_resize_needed;
-
throw;
}
}
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
-do_resize(size_type /*new_size*/)
-{
- abort();
-}
+do_resize(size_type)
+{ abort(); }
#ifdef PB_DS_HASH_POLICY_DEBUG
PB_DS_CLASS_T_DEC
assert_valid() const
{
PB_DS_DBG_ASSERT(m_load_max > m_load_min);
-
PB_DS_DBG_ASSERT(m_next_grow_size >= m_next_shrink_size);
}
-#endif // #ifdef PB_DS_HASH_POLICY_DEBUG
+#endif
#undef PB_DS_STATIC_ASSERT