diff options
Diffstat (limited to 'gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_')
8 files changed, 1295 insertions, 0 deletions
diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..a01b121 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,105 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/constructors_destructor_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +template<typename It> +void +PB_DS_CLASS_C_DEC:: +copy_from_range(It first_it, It last_it) +{ + while (first_it != last_it) + push(*(first_it++)); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +thin_heap() : m_p_max(0) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +thin_heap(const Cmp_Fn& r_cmp_fn) +: base_type(r_cmp_fn), m_p_max(0) +{ + initialize(); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +thin_heap(const PB_DS_CLASS_C_DEC& other) +: base_type(other) +{ + initialize(); + m_p_max = base_type::m_p_root; + for (node_pointer p_nd = base_type::m_p_root; p_nd != 0; + p_nd = p_nd->m_p_next_sibling) + if (Cmp_Fn::operator()(m_p_max->m_value, p_nd->m_value)) + m_p_max = p_nd; + + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +swap(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + base_type::swap(other); + std::swap(m_p_max, other.m_p_max); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~thin_heap() +{ } + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +initialize() +{ std::fill(m_a_aux, m_a_aux + max_rank, static_cast<node_pointer>(0)); } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/debug_fn_imps.hpp new file mode 100644 index 0000000..f99fcaf --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/debug_fn_imps.hpp @@ -0,0 +1,119 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/debug_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + base_type::assert_valid(__file, __line); + assert_node_consistent(base_type::m_p_root, true, __file, __line); + assert_max(__file, __line); + assert_aux_null(__file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_aux_null(const char* __file, int __line) const +{ + for (size_type i = 0; i < max_rank; ++i) + PB_DS_DEBUG_VERIFY(m_a_aux[i] == 0); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_max(const char* __file, int __line) const +{ + if (m_p_max == 0) + { + PB_DS_DEBUG_VERIFY(base_type::empty()); + return; + } + + PB_DS_DEBUG_VERIFY(!base_type::empty()); + PB_DS_DEBUG_VERIFY(base_type::parent(m_p_max) == 0); + PB_DS_DEBUG_VERIFY(m_p_max->m_p_prev_or_parent == 0); + for (const_iterator it = base_type::begin(); it != base_type::end(); ++it) + PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(m_p_max->m_value, it.m_p_nd->m_value)); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_node_consistent(node_const_pointer p_nd, bool root, + const char* __file, int __line) const +{ + base_type::assert_node_consistent(p_nd, root, __file, __line); + if (p_nd == 0) + return; + + assert_node_consistent(p_nd->m_p_next_sibling, root, __file, __line); + assert_node_consistent(p_nd->m_p_l_child, false, __file, __line); + if (!root) + { + if (p_nd->m_metadata == 0) + PB_DS_DEBUG_VERIFY(p_nd->m_p_next_sibling == 0); + else + PB_DS_DEBUG_VERIFY(p_nd->m_metadata == p_nd->m_p_next_sibling->m_metadata + 1); + } + + if (p_nd->m_p_l_child != 0) + PB_DS_DEBUG_VERIFY(p_nd->m_p_l_child->m_metadata + 1 == base_type::degree(p_nd)); + + const bool unmarked_valid = + (p_nd->m_p_l_child == 0 && p_nd->m_metadata == 0) + || (p_nd->m_p_l_child != 0 + && p_nd->m_metadata == p_nd->m_p_l_child->m_metadata + 1); + + const bool marked_valid = + (p_nd->m_p_l_child == 0 && p_nd->m_metadata == 1) + || (p_nd->m_p_l_child != 0 + && p_nd->m_metadata == p_nd->m_p_l_child->m_metadata + 2); + + PB_DS_DEBUG_VERIFY(unmarked_valid || marked_valid); + if (root) + PB_DS_DEBUG_VERIFY(unmarked_valid); +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/erase_fn_imps.hpp new file mode 100644 index 0000000..fbdbbf3 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/erase_fn_imps.hpp @@ -0,0 +1,255 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/erase_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +pop() +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + _GLIBCXX_DEBUG_ASSERT(m_p_max != 0); + + node_pointer p_nd = m_p_max; + remove_max_node(); + base_type::actual_erase_node(p_nd); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +remove_max_node() +{ + to_aux_except_max(); + make_from_aux(); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +to_aux_except_max() +{ + node_pointer p_add = base_type::m_p_root; + while (p_add != m_p_max) + { + node_pointer p_next_add = p_add->m_p_next_sibling; + add_to_aux(p_add); + p_add = p_next_add; + } + + p_add = m_p_max->m_p_l_child; + while (p_add != 0) + { + node_pointer p_next_add = p_add->m_p_next_sibling; + p_add->m_metadata = p_add->m_p_l_child == 0 ? + 0 : p_add->m_p_l_child->m_metadata + 1; + + add_to_aux(p_add); + p_add = p_next_add; + } + + p_add = m_p_max->m_p_next_sibling; + while (p_add != 0) + { + node_pointer p_next_add = p_add->m_p_next_sibling; + add_to_aux(p_add); + p_add = p_next_add; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +add_to_aux(node_pointer p_nd) +{ + size_type r = p_nd->m_metadata; + while (m_a_aux[r] != 0) + { + _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata < rank_bound()); + if (Cmp_Fn::operator()(m_a_aux[r]->m_value, p_nd->m_value)) + make_child_of(m_a_aux[r], p_nd); + else + { + make_child_of(p_nd, m_a_aux[r]); + p_nd = m_a_aux[r]; + } + + m_a_aux[r] = 0; + ++r; + } + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata < rank_bound()); + + m_a_aux[r] = p_nd; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +make_child_of(node_pointer p_nd, node_pointer p_new_parent) +{ + _GLIBCXX_DEBUG_ASSERT(p_nd->m_metadata == p_new_parent->m_metadata); + _GLIBCXX_DEBUG_ASSERT(m_a_aux[p_nd->m_metadata] == p_nd || + m_a_aux[p_nd->m_metadata] == p_new_parent); + + ++p_new_parent->m_metadata; + base_type::make_child_of(p_nd, p_new_parent); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +make_from_aux() +{ + base_type::m_p_root = m_p_max = 0; + const size_type rnk_bnd = rank_bound(); + size_type i = 0; + while (i < rnk_bnd) + { + if (m_a_aux[i] != 0) + { + make_root_and_link(m_a_aux[i]); + m_a_aux[i] = 0; + } + ++i; + } + + PB_DS_ASSERT_AUX_NULL((*this)) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +remove_node(node_pointer p_nd) +{ + node_pointer p_parent = p_nd; + while (base_type::parent(p_parent) != 0) + p_parent = base_type::parent(p_parent); + + base_type::bubble_to_top(p_nd); + m_p_max = p_nd; + + node_pointer p_fix = base_type::m_p_root; + while (p_fix != 0&& p_fix->m_p_next_sibling != p_parent) + p_fix = p_fix->m_p_next_sibling; + + if (p_fix != 0) + p_fix->m_p_next_sibling = p_nd; + + remove_max_node(); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +clear() +{ + base_type::clear(); + m_p_max = 0; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +erase(point_iterator it) +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + + node_pointer p_nd = it.m_p_nd; + remove_node(p_nd); + base_type::actual_erase_node(p_nd); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +erase_if(Pred pred) +{ + PB_DS_ASSERT_VALID((*this)) + if (base_type::empty()) + { + PB_DS_ASSERT_VALID((*this)) + return 0; + } + + base_type::to_linked_list(); + node_pointer p_out = base_type::prune(pred); + size_type ersd = 0; + while (p_out != 0) + { + ++ersd; + node_pointer p_next = p_out->m_p_next_sibling; + base_type::actual_erase_node(p_out); + p_out = p_next; + } + + node_pointer p_cur = base_type::m_p_root; + m_p_max = base_type::m_p_root = 0; + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + make_root_and_link(p_cur); + p_cur = p_next; + } + + PB_DS_ASSERT_VALID((*this)) + return ersd; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +rank_bound() +{ + using namespace std; + const size_t* const p_upper = + std::upper_bound(g_a_rank_bounds, + g_a_rank_bounds + num_distinct_rank_bounds, + base_type::m_size); + + if (p_upper == g_a_rank_bounds + num_distinct_rank_bounds) + return max_rank; + + return (p_upper - g_a_rank_bounds); +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/find_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/find_fn_imps.hpp new file mode 100644 index 0000000..9089aef --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/find_fn_imps.hpp @@ -0,0 +1,51 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/find_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_reference +PB_DS_CLASS_C_DEC:: +top() const +{ + PB_DS_ASSERT_VALID((*this)) + _GLIBCXX_DEBUG_ASSERT(!base_type::empty()); + + _GLIBCXX_DEBUG_ASSERT(m_p_max != 0); + return m_p_max->m_value; +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/insert_fn_imps.hpp new file mode 100644 index 0000000..60eaffa --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/insert_fn_imps.hpp @@ -0,0 +1,280 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/insert_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::point_iterator +PB_DS_CLASS_C_DEC:: +push(const_reference r_val) +{ + PB_DS_ASSERT_VALID((*this)) + node_pointer p_nd = base_type::get_new_node_for_insert(r_val); + p_nd->m_metadata = 0; + p_nd->m_p_prev_or_parent = p_nd->m_p_l_child = 0; + if (base_type::m_p_root == 0) + { + p_nd->m_p_next_sibling = 0; + m_p_max = base_type::m_p_root = p_nd; + PB_DS_ASSERT_VALID((*this)) + return point_iterator(p_nd); + } + + p_nd->m_p_next_sibling = base_type::m_p_root; + base_type::m_p_root->m_p_prev_or_parent = 0; + base_type::m_p_root = p_nd; + update_max(p_nd); + PB_DS_ASSERT_VALID((*this)) + return point_iterator(p_nd); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +make_root(node_pointer p_nd) +{ + p_nd->m_metadata = p_nd->m_p_l_child == 0 + ? 0 : 1 + p_nd->m_p_l_child->m_metadata; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +make_root_and_link(node_pointer p_nd) +{ + make_root(p_nd); + p_nd->m_p_prev_or_parent = 0; + p_nd->m_p_next_sibling = base_type::m_p_root; + if (base_type::m_p_root != 0) + base_type::m_p_root->m_p_prev_or_parent = 0; + + base_type::m_p_root = p_nd; + update_max(p_nd); +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix(node_pointer p_y) +{ + while (true) + { + if (p_y->m_p_prev_or_parent == 0) + { + fix_root(p_y); + return; + } + else if (p_y->m_metadata == 1&& p_y->m_p_next_sibling == 0) + { + if (p_y->m_p_l_child != 0) + { + fix_sibling_rank_1_unmarked(p_y); + return; + } + + fix_sibling_rank_1_marked(p_y); + p_y = p_y->m_p_prev_or_parent; + } + else if (p_y->m_metadata > p_y->m_p_next_sibling->m_metadata + 1) + { + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_l_child != 0); + if (p_y->m_metadata != p_y->m_p_l_child->m_metadata + 2) + { + fix_sibling_general_unmarked(p_y); + return; + } + + fix_sibling_general_marked(p_y); + p_y = p_y->m_p_prev_or_parent; + } + else if ((p_y->m_p_l_child == 0&& + p_y->m_metadata == 2) ||(p_y->m_p_l_child != 0&& + p_y->m_metadata == p_y->m_p_l_child->m_metadata + 3)) + { + node_pointer p_z = p_y->m_p_prev_or_parent; + fix_child(p_y); + p_y = p_z; + } + else + return; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_root(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent == 0); + make_root(p_y); + PB_DS_ASSERT_NODE_CONSISTENT(p_y, true) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_sibling_rank_1_unmarked(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + + _GLIBCXX_DEBUG_ONLY(node_pointer p_w = p_y->m_p_l_child;) + _GLIBCXX_DEBUG_ASSERT(p_w != 0); + _GLIBCXX_DEBUG_ASSERT(p_w->m_p_next_sibling == 0); + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_next_sibling == 0); + + p_y->m_p_next_sibling = p_y->m_p_l_child; + p_y->m_p_next_sibling->m_p_prev_or_parent = p_y; + p_y->m_p_l_child = 0; + PB_DS_ASSERT_NODE_CONSISTENT(p_y, false) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_sibling_rank_1_marked(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_l_child == 0); + p_y->m_metadata = 0; + PB_DS_ASSERT_NODE_CONSISTENT(p_y, false) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_sibling_general_unmarked(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + + node_pointer p_w = p_y->m_p_l_child; + _GLIBCXX_DEBUG_ASSERT(p_w != 0); + _GLIBCXX_DEBUG_ASSERT(p_w->m_p_next_sibling != 0); + + p_y->m_p_l_child = p_w->m_p_next_sibling; + p_w->m_p_next_sibling->m_p_prev_or_parent = p_y; + + p_w->m_p_next_sibling = p_y->m_p_next_sibling; + _GLIBCXX_DEBUG_ASSERT(p_w->m_p_next_sibling != 0); + p_w->m_p_next_sibling->m_p_prev_or_parent = p_w; + + p_y->m_p_next_sibling = p_w; + p_w->m_p_prev_or_parent = p_y; + + PB_DS_ASSERT_NODE_CONSISTENT(p_y, false) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_sibling_general_marked(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + --p_y->m_metadata; + PB_DS_ASSERT_NODE_CONSISTENT(p_y, false) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +fix_child(node_pointer p_y) +{ + _GLIBCXX_DEBUG_ASSERT(p_y->m_p_prev_or_parent != 0); + + if (p_y->m_p_next_sibling != 0) + p_y->m_p_next_sibling->m_p_prev_or_parent = p_y->m_p_prev_or_parent; + + if (p_y->m_p_prev_or_parent->m_p_l_child == p_y) + p_y->m_p_prev_or_parent->m_p_l_child = p_y->m_p_next_sibling; + else + p_y->m_p_prev_or_parent->m_p_next_sibling = p_y->m_p_next_sibling; + + make_root_and_link(p_y); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +modify(point_iterator it, const_reference r_new_val) +{ + PB_DS_ASSERT_VALID((*this)) + node_pointer p_nd = it.m_p_nd; + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + + const bool smaller = Cmp_Fn::operator()(r_new_val, p_nd->m_value); + p_nd->m_value = r_new_val; + if (smaller) + { + remove_node(p_nd); + p_nd->m_p_l_child = 0; + make_root_and_link(p_nd); + PB_DS_ASSERT_VALID((*this)) + return; + } + + if (p_nd->m_p_prev_or_parent == 0) + { + update_max(p_nd); + PB_DS_ASSERT_VALID((*this)) + return; + } + + node_pointer p_y = p_nd->m_p_prev_or_parent; + _GLIBCXX_DEBUG_ASSERT(p_y != 0); + + if (p_nd->m_p_next_sibling != 0) + p_nd->m_p_next_sibling->m_p_prev_or_parent = p_y; + + if (p_y->m_p_l_child == p_nd) + p_y->m_p_l_child = p_nd->m_p_next_sibling; + else + p_y->m_p_next_sibling = p_nd->m_p_next_sibling; + + fix(p_y); + make_root_and_link(p_nd); + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +update_max(node_pointer p_nd) +{ + if (m_p_max == 0 || Cmp_Fn::operator()(m_p_max->m_value, p_nd->m_value)) + m_p_max = p_nd; +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/split_join_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/split_join_fn_imps.hpp new file mode 100644 index 0000000..222ecd1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/split_join_fn_imps.hpp @@ -0,0 +1,108 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/split_join_fn_imps.hpp + * Contains an implementation for thin_heap_. + */ + +PB_DS_CLASS_T_DEC +template<typename Pred> +void +PB_DS_CLASS_C_DEC:: +split(Pred pred, PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + other.clear(); + if (base_type::empty()) + { + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + return; + } + + base_type::to_linked_list(); + node_pointer p_out = base_type::prune(pred); + + while (p_out != 0) + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_size > 0); + --base_type::m_size; + ++other.m_size; + node_pointer p_next = p_out->m_p_next_sibling; + other.make_root_and_link(p_out); + p_out = p_next; + } + + PB_DS_ASSERT_VALID(other) + node_pointer p_cur = base_type::m_p_root; + m_p_max = 0; + base_type::m_p_root = 0; + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + make_root_and_link(p_cur); + p_cur = p_next; + } + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +join(PB_DS_CLASS_C_DEC& other) +{ + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) + + node_pointer p_other = other.m_p_root; + while (p_other != 0) + { + node_pointer p_next = p_other->m_p_next_sibling; + make_root_and_link(p_other); + p_other = p_next; + } + base_type::m_size += other.m_size; + other.m_p_root = 0; + other.m_size = 0; + other.m_p_max = 0; + + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/thin_heap_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/thin_heap_.hpp new file mode 100644 index 0000000..f37c5e4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/thin_heap_.hpp @@ -0,0 +1,324 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/thin_heap_.hpp + * Contains an implementation class for a thin heap. + */ + +#ifndef PB_DS_THIN_HEAP_HPP +#define PB_DS_THIN_HEAP_HPP + +#include <algorithm> +#include <ext/pb_ds/detail/cond_dealtor.hpp> +#include <ext/pb_ds/detail/type_utils.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + thin_heap<Value_Type, Cmp_Fn, _Alloc> + +#ifdef _GLIBCXX_DEBUG +#define PB_DS_BASE_T_P \ + <Value_Type, Cmp_Fn, typename _Alloc::size_type, _Alloc, true> +#else +#define PB_DS_BASE_T_P \ + <Value_Type, Cmp_Fn, typename _Alloc::size_type, _Alloc> +#endif + + + /** + * Thin heap. + * + * @ingroup heap-detail + * + * See Tarjan and Kaplan. + */ + template<typename Value_Type, typename Cmp_Fn, typename _Alloc> + class thin_heap + : public left_child_next_sibling_heap PB_DS_BASE_T_P + { + private: + typedef typename _Alloc::template rebind<Value_Type>::other __rebind_a; + typedef left_child_next_sibling_heap PB_DS_BASE_T_P base_type; + + protected: + typedef typename base_type::node node; + typedef typename base_type::node_pointer node_pointer; + typedef typename base_type::node_const_pointer node_const_pointer; + + public: + typedef Value_Type value_type; + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + + typedef typename __rebind_a::pointer pointer; + typedef typename __rebind_a::const_pointer const_pointer; + typedef typename __rebind_a::reference reference; + typedef typename __rebind_a::const_reference const_reference; + + typedef typename base_type::point_iterator point_iterator; + typedef typename base_type::point_const_iterator point_const_iterator; + typedef typename base_type::iterator iterator; + typedef typename base_type::const_iterator const_iterator; + + + inline point_iterator + push(const_reference); + + void + modify(point_iterator, const_reference); + + inline const_reference + top() const; + + void + pop(); + + void + erase(point_iterator); + + inline void + clear(); + + template<typename Pred> + size_type + erase_if(Pred); + + template<typename Pred> + void + split(Pred, PB_DS_CLASS_C_DEC&); + + void + join(PB_DS_CLASS_C_DEC&); + + protected: + thin_heap(); + + thin_heap(const Cmp_Fn&); + + thin_heap(const PB_DS_CLASS_C_DEC&); + + void + swap(PB_DS_CLASS_C_DEC&); + + ~thin_heap(); + + template<typename It> + void + copy_from_range(It, It); + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; + + void + assert_max(const char*, int) const; +#endif + +#ifdef PB_DS_THIN_HEAP_TRACE_ + void + trace() const; +#endif + + private: + enum + { + max_rank = (sizeof(size_type) << 4) + 2 + }; + + void + initialize(); + + inline void + update_max(node_pointer); + + inline void + fix(node_pointer); + + inline void + fix_root(node_pointer); + + inline void + fix_sibling_rank_1_unmarked(node_pointer); + + inline void + fix_sibling_rank_1_marked(node_pointer); + + inline void + fix_sibling_general_unmarked(node_pointer); + + inline void + fix_sibling_general_marked(node_pointer); + + inline void + fix_child(node_pointer); + + inline static void + make_root(node_pointer); + + inline void + make_root_and_link(node_pointer); + + inline void + remove_max_node(); + + void + to_aux_except_max(); + + inline void + add_to_aux(node_pointer); + + inline void + make_from_aux(); + + inline size_type + rank_bound(); + + inline void + make_child_of(node_pointer, node_pointer); + + inline void + remove_node(node_pointer); + + inline node_pointer + join(node_pointer, node_pointer) const; + +#ifdef _GLIBCXX_DEBUG + void + assert_node_consistent(node_const_pointer, bool, const char*, int) const; + + void + assert_aux_null(const char*, int) const; +#endif + + node_pointer m_p_max; + node_pointer m_a_aux[max_rank]; + }; + + enum + { + num_distinct_rank_bounds = 48 + }; + + // Taken from the SGI implementation; acknowledged in the docs. + static const std::size_t g_a_rank_bounds[num_distinct_rank_bounds] = + { + /* Dealing cards... */ + /* 0 */ 0ul, + /* 1 */ 1ul, + /* 2 */ 1ul, + /* 3 */ 2ul, + /* 4 */ 4ul, + /* 5 */ 6ul, + /* 6 */ 11ul, + /* 7 */ 17ul, + /* 8 */ 29ul, + /* 9 */ 46ul, + /* 10 */ 76ul, + /* 11 */ 122ul, + /* 12 */ 199ul, + /* 13 */ 321ul, + /* 14 */ 521ul, + /* 15 */ 842ul, + /* 16 */ 1364ul, + /* 17 */ 2206ul, + /* 18 */ 3571ul, + /* 19 */ 5777ul, + /* 20 */ 9349ul, + /* 21 */ 15126ul, + /* 22 */ 24476ul, + /* 23 */ 39602ul, + /* 24 */ 64079ul, + /* 25 */ 103681ul, + /* 26 */ 167761ul, + /* 27 */ 271442ul, + /* 28 */ 439204ul, + /* 29 */ 710646ul, + /* 30 */ 1149851ul, + /* 31 */ 1860497ul, + /* 32 */ 3010349ul, + /* 33 */ 4870846ul, + /* 34 */ 7881196ul, + /* 35 */ 12752042ul, + /* 36 */ 20633239ul, + /* 37 */ 33385282ul, + /* 38 */ 54018521ul, + /* 39 */ 87403803ul, + /* 40 */ 141422324ul, + /* 41 */ 228826127ul, + /* 42 */ 370248451ul, + /* 43 */ 599074578ul, + /* 44 */ 969323029ul, + /* 45 */ 1568397607ul, + /* 46 */ 2537720636ul, + /* 47 */ 4106118243ul + /* Pot's good, let's play */ + }; + +#define PB_DS_ASSERT_NODE_CONSISTENT(_Node, _Bool) \ + _GLIBCXX_DEBUG_ONLY(assert_node_consistent(_Node, _Bool, \ + __FILE__, __LINE__);) + +#define PB_DS_ASSERT_AUX_NULL(X) \ + _GLIBCXX_DEBUG_ONLY(X.assert_aux_null(__FILE__, __LINE__);) + +#include <ext/pb_ds/detail/thin_heap_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/trace_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/find_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/thin_heap_/split_join_fn_imps.hpp> + +#undef PB_DS_ASSERT_AUX_NULL +#undef PB_DS_ASSERT_NODE_CONSISTENT +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_BASE_T_P + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/trace_fn_imps.hpp new file mode 100644 index 0000000..cb6a623 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/thin_heap_/trace_fn_imps.hpp @@ -0,0 +1,53 @@ +// -*- C++ -*- + +// Copyright (C) 2005-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file thin_heap_/trace_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +#ifdef PB_DS_THIN_HEAP_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + std::cerr << std::endl; + std::cerr << "m_p_max " << m_p_max << std::endl; + base_type::trace(); +} + +#endif // #ifdef PB_DS_THIN_HEAP_TRACE_ |