diff options
Diffstat (limited to 'gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_')
12 files changed, 1592 insertions, 0 deletions
diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp new file mode 100644 index 0000000..477bcb9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp @@ -0,0 +1,159 @@ +// -*- 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 left_child_next_sibling_heap_/const_iterator.hpp + * Contains an iterator class returned by the table's const find and insert + * methods. + */ + +#ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_ITERATOR_HPP +#define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_ITERATOR_HPP + +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#define PB_DS_CLASS_C_DEC \ + left_child_next_sibling_heap_const_iterator_<Node, _Alloc> + +#define PB_DS_BASIC_HEAP_CIT_BASE \ + left_child_next_sibling_heap_node_point_const_iterator_<Node, _Alloc> + + /// Const point-type iterator. + template<typename Node, typename _Alloc> + class left_child_next_sibling_heap_const_iterator_ + : public PB_DS_BASIC_HEAP_CIT_BASE + { + private: + typedef PB_DS_BASIC_HEAP_CIT_BASE base_type; + typedef typename base_type::node_pointer node_pointer; + + public: + /// Category. + typedef std::forward_iterator_tag iterator_category; + + /// Difference type. + typedef typename _Alloc::difference_type difference_type; + + /// Iterator's value type. + typedef typename base_type::value_type value_type; + + /// Iterator's pointer type. + typedef typename base_type::pointer pointer; + + /// Iterator's const pointer type. + typedef typename base_type::const_pointer const_pointer; + + /// Iterator's reference type. + typedef typename base_type::reference reference; + + /// Iterator's const reference type. + typedef typename base_type::const_reference const_reference; + + inline + left_child_next_sibling_heap_const_iterator_(node_pointer p_nd) + : base_type(p_nd) + { } + + /// Default constructor. + inline + left_child_next_sibling_heap_const_iterator_() + { } + + /// Copy constructor. + inline + left_child_next_sibling_heap_const_iterator_(const PB_DS_CLASS_C_DEC& other) : base_type(other) + { } + + /// Compares content to a different iterator object. + bool + operator==(const PB_DS_CLASS_C_DEC& other) const + { return (base_type::m_p_nd == other.m_p_nd); } + + /// Compares content (negatively) to a different iterator object. + bool + operator!=(const PB_DS_CLASS_C_DEC& other) const + { return (base_type::m_p_nd != other.m_p_nd); } + + PB_DS_CLASS_C_DEC& + operator++() + { + _GLIBCXX_DEBUG_ASSERT(base_type::m_p_nd != 0); + inc(); + return (*this); + } + + PB_DS_CLASS_C_DEC + operator++(int) + { + PB_DS_CLASS_C_DEC ret_it(base_type::m_p_nd); + operator++(); + return (ret_it); + } + + private: + void + inc() + { + if (base_type::m_p_nd->m_p_next_sibling != 0) + { + base_type::m_p_nd = base_type::m_p_nd->m_p_next_sibling; + while (base_type::m_p_nd->m_p_l_child != 0) + base_type::m_p_nd = base_type::m_p_nd->m_p_l_child; + return; + } + + while (true) + { + node_pointer p_next = base_type::m_p_nd; + base_type::m_p_nd = base_type::m_p_nd->m_p_prev_or_parent; + if (base_type::m_p_nd == 0 + || base_type::m_p_nd->m_p_l_child == p_next) + return; + } + } + }; + +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_BASIC_HEAP_CIT_BASE + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp new file mode 100644 index 0000000..3539f58 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp @@ -0,0 +1,152 @@ +// -*- 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 left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_allocator +PB_DS_CLASS_C_DEC::s_node_allocator; + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::no_throw_copies_t +PB_DS_CLASS_C_DEC::s_no_throw_copies_ind; + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +left_child_next_sibling_heap() : + m_p_root(0), + m_size(0) +{ + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +left_child_next_sibling_heap(const Cmp_Fn& r_cmp_fn) : + Cmp_Fn(r_cmp_fn), + m_p_root(0), + m_size(0) +{ + PB_DS_ASSERT_VALID((*this)) +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +left_child_next_sibling_heap(const PB_DS_CLASS_C_DEC& other) +: Cmp_Fn(other), m_p_root(0), m_size(0) +{ + m_size = other.m_size; + PB_DS_ASSERT_VALID(other) + m_p_root = recursive_copy_node(other.m_p_root); + m_size = other.m_size; + 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)) + PB_DS_ASSERT_VALID(other) + value_swap(other); + std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )other); + PB_DS_ASSERT_VALID((*this)) + PB_DS_ASSERT_VALID(other) +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +value_swap(PB_DS_CLASS_C_DEC& other) +{ + std::swap(m_p_root, other.m_p_root); + std::swap(m_size, other.m_size); +} + +PB_DS_CLASS_T_DEC +PB_DS_CLASS_C_DEC:: +~left_child_next_sibling_heap() +{ + clear(); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +recursive_copy_node(node_const_pointer p_nd) +{ + if (p_nd == 0) + return (0); + + node_pointer p_ret = s_node_allocator.allocate(1); + + __try + { + new (p_ret) node(*p_nd); + } + __catch(...) + { + s_node_allocator.deallocate(p_ret, 1); + __throw_exception_again; + } + + p_ret->m_p_l_child = p_ret->m_p_next_sibling = + p_ret->m_p_prev_or_parent = 0; + + __try + { + p_ret->m_p_l_child = recursive_copy_node(p_nd->m_p_l_child); + p_ret->m_p_next_sibling = recursive_copy_node(p_nd->m_p_next_sibling); + } + __catch(...) + { + clear_imp(p_ret); + __throw_exception_again; + } + + if (p_ret->m_p_l_child != 0) + p_ret->m_p_l_child->m_p_prev_or_parent = p_ret; + + if (p_ret->m_p_next_sibling != 0) + p_ret->m_p_next_sibling->m_p_prev_or_parent = + p_nd->m_p_next_sibling->m_p_prev_or_parent == p_nd ? p_ret : 0; + + return p_ret; +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp new file mode 100644 index 0000000..fda9f27 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp @@ -0,0 +1,137 @@ +// -*- 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 left_child_next_sibling_heap_/debug_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +#ifdef _GLIBCXX_DEBUG + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_valid(const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(m_p_root == 0 || m_p_root->m_p_prev_or_parent == 0); + + if (m_p_root != 0) + assert_node_consistent(m_p_root, Single_Link_Roots, __file, __line); + assert_size(__file, __line); + assert_iterators(__file, __line); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_node_consistent(node_const_pointer p_nd, bool single_link, + const char* __file, int __line) const +{ + if (p_nd == 0) + return; + + assert_node_consistent(p_nd->m_p_l_child, false, __file, __line); + assert_node_consistent(p_nd->m_p_next_sibling, single_link, __file, __line); + + if (single_link) + PB_DS_DEBUG_VERIFY(p_nd->m_p_prev_or_parent == 0); + else if (p_nd->m_p_next_sibling != 0) + PB_DS_DEBUG_VERIFY(p_nd->m_p_next_sibling->m_p_prev_or_parent == p_nd); + + if (p_nd->m_p_l_child == 0) + return; + + node_const_pointer p_child = p_nd->m_p_l_child; + while (p_child != 0) + { + node_const_pointer p_next_child = p_child->m_p_next_sibling; + PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(p_nd->m_value, p_child->m_value)); + p_child = p_next_child; + } + PB_DS_DEBUG_VERIFY(p_nd->m_p_l_child->m_p_prev_or_parent == p_nd); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_iterators(const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(std::distance(begin(), end()) == size()); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +assert_size(const char* __file, int __line) const +{ + PB_DS_DEBUG_VERIFY(size_from_node(m_p_root) == m_size); +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size_under_node(node_const_pointer p_nd) +{ return 1 + size_from_node(p_nd->m_p_l_child); } + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size_from_node(node_const_pointer p_nd) +{ + size_type ret = 0; + while (p_nd != 0) + { + ret += 1 + size_from_node(p_nd->m_p_l_child); + p_nd = p_nd->m_p_next_sibling; + } + return ret; +} + +PB_DS_CLASS_T_DEC +typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +degree(node_const_pointer p_nd) +{ + size_type ret = 0; + node_const_pointer p_child = p_nd->m_p_l_child; + while (p_child != 0) + { + ++ret; + p_child = p_child->m_p_next_sibling; + } + return ret; +} + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp new file mode 100644 index 0000000..3106505 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp @@ -0,0 +1,150 @@ +// -*- 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 left_child_next_sibling_heap_/erase_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear() +{ + clear_imp(m_p_root); + _GLIBCXX_DEBUG_ASSERT(m_size == 0); + m_p_root = 0; +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +actual_erase_node(node_pointer p_nd) +{ + _GLIBCXX_DEBUG_ASSERT(m_size > 0); + --m_size; + p_nd->~node(); + s_node_allocator.deallocate(p_nd, 1); +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +clear_imp(node_pointer p_nd) +{ + while (p_nd != 0) + { + clear_imp(p_nd->m_p_l_child); + node_pointer p_next = p_nd->m_p_next_sibling; + actual_erase_node(p_nd); + p_nd = p_next; + } +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +to_linked_list() +{ + PB_DS_ASSERT_VALID((*this)) + node_pointer p_cur = m_p_root; + while (p_cur != 0) + if (p_cur->m_p_l_child != 0) + { + node_pointer p_child_next = p_cur->m_p_l_child->m_p_next_sibling; + p_cur->m_p_l_child->m_p_next_sibling = p_cur->m_p_next_sibling; + p_cur->m_p_next_sibling = p_cur->m_p_l_child; + p_cur->m_p_l_child = p_child_next; + } + else + p_cur = p_cur->m_p_next_sibling; + +#ifdef _GLIBCXX_DEBUG + node_const_pointer p_counter = m_p_root; + size_type count = 0; + while (p_counter != 0) + { + ++count; + _GLIBCXX_DEBUG_ASSERT(p_counter->m_p_l_child == 0); + p_counter = p_counter->m_p_next_sibling; + } + _GLIBCXX_DEBUG_ASSERT(count == m_size); +#endif +} + +PB_DS_CLASS_T_DEC +template<typename Pred> +typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +prune(Pred pred) +{ + node_pointer p_cur = m_p_root; + m_p_root = 0; + node_pointer p_out = 0; + while (p_cur != 0) + { + node_pointer p_next = p_cur->m_p_next_sibling; + if (pred(p_cur->m_value)) + { + p_cur->m_p_next_sibling = p_out; + if (p_out != 0) + p_out->m_p_prev_or_parent = p_cur; + p_out = p_cur; + } + else + { + p_cur->m_p_next_sibling = m_p_root; + if (m_p_root != 0) + m_p_root->m_p_prev_or_parent = p_cur; + m_p_root = p_cur; + } + p_cur = p_next; + } + return p_out; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +bubble_to_top(node_pointer p_nd) +{ + node_pointer p_parent = parent(p_nd); + while (p_parent != 0) + { + swap_with_parent(p_nd, p_parent); + p_parent = parent(p_nd); + } +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp new file mode 100644 index 0000000..2a122f8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp @@ -0,0 +1,64 @@ +// -*- 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 left_child_next_sibling_heap_/info_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +inline bool +PB_DS_CLASS_C_DEC:: +empty() const +{ + return (m_size == 0); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +size() const +{ + return (m_size); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::size_type +PB_DS_CLASS_C_DEC:: +max_size() const +{ + return (s_node_allocator.max_size()); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp new file mode 100644 index 0000000..8f275c0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp @@ -0,0 +1,175 @@ +// -*- 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 left_child_next_sibling_heap_/insert_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +get_new_node_for_insert(const_reference r_val) +{ + return get_new_node_for_insert(r_val, s_no_throw_copies_ind); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +get_new_node_for_insert(const_reference r_val, false_type) +{ + node_pointer p_new_nd = s_node_allocator.allocate(1); + + cond_dealtor_t cond(p_new_nd); + + new (const_cast<void* >( + static_cast<const void* >(&p_new_nd->m_value))) + typename node::value_type(r_val); + + cond.set_no_action(); + + ++m_size; + + return (p_new_nd); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +get_new_node_for_insert(const_reference r_val, true_type) +{ + node_pointer p_new_nd = s_node_allocator.allocate(1); + + new (const_cast<void* >( + static_cast<const void* >(&p_new_nd->m_value))) + typename node::value_type(r_val); + + ++m_size; + + return (p_new_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 != 0); + _GLIBCXX_DEBUG_ASSERT(p_new_parent != 0); + + p_nd->m_p_next_sibling = p_new_parent->m_p_l_child; + + if (p_new_parent->m_p_l_child != 0) + p_new_parent->m_p_l_child->m_p_prev_or_parent = p_nd; + + p_nd->m_p_prev_or_parent = p_new_parent; + + p_new_parent->m_p_l_child = p_nd; +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::node_pointer +PB_DS_CLASS_C_DEC:: +parent(node_pointer p_nd) +{ + while (true) + { + node_pointer p_pot = p_nd->m_p_prev_or_parent; + + if (p_pot == 0 || p_pot->m_p_l_child == p_nd) + return p_pot; + + p_nd = p_pot; + } +} + +PB_DS_CLASS_T_DEC +inline void +PB_DS_CLASS_C_DEC:: +swap_with_parent(node_pointer p_nd, node_pointer p_parent) +{ + if (p_parent == m_p_root) + m_p_root = p_nd; + + _GLIBCXX_DEBUG_ASSERT(p_nd != 0); + _GLIBCXX_DEBUG_ASSERT(p_parent != 0); + _GLIBCXX_DEBUG_ASSERT(parent(p_nd) == p_parent); + + const bool nd_direct_child = p_parent->m_p_l_child == p_nd; + const bool parent_root = p_parent->m_p_prev_or_parent == 0; + const bool parent_direct_child = + !parent_root&& p_parent->m_p_prev_or_parent->m_p_l_child == p_parent; + + std::swap(p_parent->m_p_prev_or_parent, p_nd->m_p_prev_or_parent); + std::swap(p_parent->m_p_next_sibling, p_nd->m_p_next_sibling); + std::swap(p_parent->m_p_l_child, p_nd->m_p_l_child); + std::swap(p_parent->m_metadata, p_nd->m_metadata); + + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_l_child != 0); + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_prev_or_parent != 0); + + if (p_nd->m_p_next_sibling != 0) + p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd; + + if (p_parent->m_p_next_sibling != 0) + p_parent->m_p_next_sibling->m_p_prev_or_parent = p_parent; + + if (p_parent->m_p_l_child != 0) + p_parent->m_p_l_child->m_p_prev_or_parent = p_parent; + + if (parent_direct_child) + p_nd->m_p_prev_or_parent->m_p_l_child = p_nd; + else if (!parent_root) + p_nd->m_p_prev_or_parent->m_p_next_sibling = p_nd; + + if (!nd_direct_child) + { + p_nd->m_p_l_child->m_p_prev_or_parent = p_nd; + + p_parent->m_p_prev_or_parent->m_p_next_sibling = p_parent; + } + else + { + _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_l_child == p_nd); + _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_prev_or_parent == p_parent); + + p_nd->m_p_l_child = p_parent; + p_parent->m_p_prev_or_parent = p_nd; + } + + _GLIBCXX_DEBUG_ASSERT(parent(p_parent) == p_nd); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp new file mode 100644 index 0000000..55d3eba --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp @@ -0,0 +1,88 @@ +// -*- 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 left_child_next_sibling_heap_/iterators_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +begin() +{ + node_pointer p_nd = m_p_root; + + if (p_nd == 0) + return (iterator(0)); + + while (p_nd->m_p_l_child != 0) + p_nd = p_nd->m_p_l_child; + + return (iterator(p_nd)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +begin() const +{ + node_pointer p_nd = m_p_root; + + if (p_nd == 0) + return (const_iterator(0)); + + while (p_nd->m_p_l_child != 0) + p_nd = p_nd->m_p_l_child; + + return (const_iterator(p_nd)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::iterator +PB_DS_CLASS_C_DEC:: +end() +{ + return (iterator(0)); +} + +PB_DS_CLASS_T_DEC +inline typename PB_DS_CLASS_C_DEC::const_iterator +PB_DS_CLASS_C_DEC:: +end() const +{ + return (const_iterator(0)); +} + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp new file mode 100644 index 0000000..7ced08f --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp @@ -0,0 +1,286 @@ +// -*- 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 left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp + * Contains an implementation class for a basic heap. + */ + +#ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_HPP +#define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_HPP + +/* + * Based on CLRS. + */ + +#include <iterator> +#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_/node.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp> +#ifdef PB_DS_LC_NS_HEAP_TRACE_ +#include <iostream> +#endif +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { +#ifdef _GLIBCXX_DEBUG +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename Node_Metadata, \ + typename _Alloc, bool Single_Link_Roots> + +#define PB_DS_CLASS_C_DEC \ + left_child_next_sibling_heap<Value_Type, Cmp_Fn, Node_Metadata, \ + _Alloc, Single_Link_Roots> +#else +#define PB_DS_CLASS_T_DEC \ + template<typename Value_Type, typename Cmp_Fn, typename Node_Metadata, \ + typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + left_child_next_sibling_heap<Value_Type, Cmp_Fn, Node_Metadata, _Alloc> +#endif + + /// Base class for a basic heap. + template<typename Value_Type, + typename Cmp_Fn, + typename Node_Metadata, + typename _Alloc +#ifdef _GLIBCXX_DEBUG + ,bool Single_Link_Roots> +#else + > +#endif + class left_child_next_sibling_heap : public Cmp_Fn + { + protected: + typedef + typename _Alloc::template rebind< + left_child_next_sibling_heap_node_<Value_Type, Node_Metadata, + _Alloc> >::other + node_allocator; + + typedef typename node_allocator::value_type node; + typedef typename node_allocator::pointer node_pointer; + typedef typename node_allocator::const_pointer node_const_pointer; + typedef Node_Metadata node_metadata; + typedef std::pair< node_pointer, node_pointer> node_pointer_pair; + + private: + typedef cond_dealtor< node, _Alloc> cond_dealtor_t; + + enum + { + simple_value = is_simple<Value_Type>::value + }; + + typedef integral_constant<int, simple_value> no_throw_copies_t; + typedef typename _Alloc::template rebind<Value_Type> __rebind_v; + + public: + typedef typename _Alloc::size_type size_type; + typedef typename _Alloc::difference_type difference_type; + typedef Value_Type value_type; + + typedef typename __rebind_v::other::pointer pointer; + typedef typename __rebind_v::other::const_pointer const_pointer; + typedef typename __rebind_v::other::reference reference; + typedef typename __rebind_v::other::const_reference const_reference; + + typedef left_child_next_sibling_heap_node_point_const_iterator_<node, _Alloc> + point_const_iterator; + + typedef point_const_iterator point_iterator; + + typedef left_child_next_sibling_heap_const_iterator_<node, _Alloc> + const_iterator; + + typedef const_iterator iterator; + typedef Cmp_Fn cmp_fn; + typedef _Alloc allocator_type; + + left_child_next_sibling_heap(); + left_child_next_sibling_heap(const Cmp_Fn&); + left_child_next_sibling_heap(const left_child_next_sibling_heap&); + + void + swap(PB_DS_CLASS_C_DEC&); + + ~left_child_next_sibling_heap(); + + inline bool + empty() const; + + inline size_type + size() const; + + inline size_type + max_size() const; + + Cmp_Fn& + get_cmp_fn(); + + const Cmp_Fn& + get_cmp_fn() const; + + inline iterator + begin(); + + inline const_iterator + begin() const; + + inline iterator + end(); + + inline const_iterator + end() const; + + void + clear(); + +#ifdef PB_DS_LC_NS_HEAP_TRACE_ + void + trace() const; +#endif + + protected: + inline node_pointer + get_new_node_for_insert(const_reference); + + inline static void + make_child_of(node_pointer, node_pointer); + + void + value_swap(left_child_next_sibling_heap&); + + inline static node_pointer + parent(node_pointer); + + inline void + swap_with_parent(node_pointer, node_pointer); + + void + bubble_to_top(node_pointer); + + inline void + actual_erase_node(node_pointer); + + void + clear_imp(node_pointer); + + void + to_linked_list(); + + template<typename Pred> + node_pointer + prune(Pred); + +#ifdef _GLIBCXX_DEBUG + void + assert_valid(const char*, int) const; + + void + assert_node_consistent(node_const_pointer, bool, const char*, int) const; + + static size_type + size_under_node(node_const_pointer); + + static size_type + degree(node_const_pointer); +#endif + +#ifdef PB_DS_LC_NS_HEAP_TRACE_ + static void + trace_node(node_const_pointer, size_type); +#endif + + private: +#ifdef _GLIBCXX_DEBUG + void + assert_iterators(const char*, int) const; + + void + assert_size(const char*, int) const; + + static size_type + size_from_node(node_const_pointer); +#endif + + node_pointer + recursive_copy_node(node_const_pointer); + + inline node_pointer + get_new_node_for_insert(const_reference, false_type); + + inline node_pointer + get_new_node_for_insert(const_reference, true_type); + +#ifdef PB_DS_LC_NS_HEAP_TRACE_ + template<typename Metadata_> + static void + trace_node_metadata(node_const_pointer, type_to_type<Metadata_>); + + static void + trace_node_metadata(node_const_pointer, type_to_type<null_type>); +#endif + + static node_allocator s_node_allocator; + static no_throw_copies_t s_no_throw_copies_ind; + + protected: + node_pointer m_p_root; + size_type m_size; + }; + +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp> +#include <ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp> + +#undef PB_DS_CLASS_C_DEC +#undef PB_DS_CLASS_T_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/node.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/node.hpp new file mode 100644 index 0000000..27c70a8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/node.hpp @@ -0,0 +1,90 @@ +// -*- 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 left_child_next_sibling_heap_/node.hpp + * Contains an implementation struct for this type of heap's node. + */ + +#ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_NODE_HPP +#define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_NODE_HPP + +namespace __gnu_pbds +{ + namespace detail + { + /// Node. + template<typename _Value, typename _Metadata, typename _Alloc> + struct left_child_next_sibling_heap_node_ + { + private: + typedef left_child_next_sibling_heap_node_<_Value, _Metadata, _Alloc> this_type; + + public: + typedef _Value value_type; + typedef typename _Alloc::size_type size_type; + typedef _Metadata metadata_type; + + typedef typename _Alloc::template rebind<this_type>::other::pointer node_pointer; + + value_type m_value; + metadata_type m_metadata; + node_pointer m_p_l_child; + node_pointer m_p_next_sibling; + node_pointer m_p_prev_or_parent; + }; + + template<typename _Value, typename _Alloc> + struct left_child_next_sibling_heap_node_<_Value, null_type, _Alloc> + { + private: + typedef left_child_next_sibling_heap_node_<_Value, null_type, _Alloc> this_type; + + public: + typedef _Value value_type; + typedef typename _Alloc::size_type size_type; + + typedef typename _Alloc::template rebind<this_type>::other::pointer node_pointer; + + value_type m_value; + node_pointer m_p_l_child; + node_pointer m_p_next_sibling; + node_pointer m_p_prev_or_parent; + }; + + } // namespace detail +} // namespace __gnu_pbds + +#endif // #ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_NODE_HPP diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp new file mode 100644 index 0000000..8aa9ef9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp @@ -0,0 +1,149 @@ +// -*- 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 left_child_next_sibling_heap_/point_const_iterator.hpp + * Contains an iterator class returned by the table's const find and insert + * methods. + */ + +#ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_FIND_ITERATOR_HPP +#define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_FIND_ITERATOR_HPP + +#include <ext/pb_ds/tag_and_trait.hpp> +#include <debug/debug.h> + +namespace __gnu_pbds +{ + namespace detail + { + +#define PB_DS_CLASS_T_DEC \ + template<typename Node, typename _Alloc> + +#define PB_DS_CLASS_C_DEC \ + left_child_next_sibling_heap_node_point_const_iterator_<Node, _Alloc> + + /// Const point-type iterator. + template<typename Node, typename _Alloc> + class left_child_next_sibling_heap_node_point_const_iterator_ + { + protected: + typedef typename _Alloc::template rebind<Node>::other::pointer node_pointer; + + public: + /// Category. + typedef trivial_iterator_tag iterator_category; + + /// Difference type. + typedef trivial_iterator_difference_type difference_type; + + /// Iterator's value type. + typedef typename Node::value_type value_type; + + /// Iterator's pointer type. + typedef + typename _Alloc::template rebind< + value_type>::other::pointer + pointer; + + /// Iterator's const pointer type. + typedef + typename _Alloc::template rebind< + value_type>::other::const_pointer + const_pointer; + + /// Iterator's reference type. + typedef + typename _Alloc::template rebind< + value_type>::other::reference + reference; + + /// Iterator's const reference type. + typedef + typename _Alloc::template rebind< + value_type>::other::const_reference + const_reference; + + inline + left_child_next_sibling_heap_node_point_const_iterator_(node_pointer p_nd) : m_p_nd(p_nd) + { } + + /// Default constructor. + inline + left_child_next_sibling_heap_node_point_const_iterator_() : m_p_nd(0) + { } + + /// Copy constructor. + inline + left_child_next_sibling_heap_node_point_const_iterator_(const PB_DS_CLASS_C_DEC& other) : m_p_nd(other.m_p_nd) + { } + + /// Access. + const_pointer + operator->() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd != 0); + return &m_p_nd->m_value; + } + + /// Access. + const_reference + operator*() const + { + _GLIBCXX_DEBUG_ASSERT(m_p_nd != 0); + return m_p_nd->m_value; + } + + /// Compares content to a different iterator object. + bool + operator==(const PB_DS_CLASS_C_DEC& other) const + { return m_p_nd == other.m_p_nd; } + + /// Compares content (negatively) to a different iterator object. + bool + operator!=(const PB_DS_CLASS_C_DEC& other) const + { return m_p_nd != other.m_p_nd; } + + node_pointer m_p_nd; + }; + +#undef PB_DS_CLASS_T_DEC +#undef PB_DS_CLASS_C_DEC + + } // namespace detail +} // namespace __gnu_pbds + +#endif diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp new file mode 100644 index 0000000..3b296e7 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp @@ -0,0 +1,52 @@ +// -*- 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 left_child_next_sibling_heap_/policy_access_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +PB_DS_CLASS_T_DEC +Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() +{ return *this; } + +PB_DS_CLASS_T_DEC +const Cmp_Fn& +PB_DS_CLASS_C_DEC:: +get_cmp_fn() const +{ return *this; } + diff --git a/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp new file mode 100644 index 0000000..bb47b56 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp @@ -0,0 +1,90 @@ +// -*- 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 left_child_next_sibling_heap_/trace_fn_imps.hpp + * Contains an implementation class for left_child_next_sibling_heap_. + */ + +#ifdef PB_DS_LC_NS_HEAP_TRACE_ + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace() const +{ + std::cerr << std::endl; + trace_node(m_p_root, 0); + std::cerr << std::endl; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace_node(node_const_pointer p_nd, size_type level) +{ + while (p_nd != 0) + { + for (size_type i = 0; i < level; ++i) + std::cerr << ' '; + + std::cerr << p_nd << + " prev = " << p_nd->m_p_prev_or_parent << + " next " << p_nd->m_p_next_sibling << + " left = " << p_nd->m_p_l_child << " "; + + trace_node_metadata(p_nd, type_to_type<node_metadata>()); + std::cerr << p_nd->m_value << std::endl; + trace_node(p_nd->m_p_l_child, level + 1); + p_nd = p_nd->m_p_next_sibling; + } +} + +PB_DS_CLASS_T_DEC +template<typename Metadata_> +void +PB_DS_CLASS_C_DEC:: +trace_node_metadata(node_const_pointer p_nd, type_to_type<Metadata_>) +{ + std::cerr << "(" << p_nd->m_metadata << ") "; +} + +PB_DS_CLASS_T_DEC +void +PB_DS_CLASS_C_DEC:: +trace_node_metadata(node_const_pointer, type_to_type<null_type>) +{ } + +#endif // #ifdef PB_DS_LC_NS_HEAP_TRACE_ |