3 // Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
37 * @file insert_fn_imps.hpp
38 * Contains an implementation class for left_child_next_sibling_heap_.
42 inline typename
PB_DS_CLASS_C_DEC::node_pointer
44 get_new_node_for_insert(const_reference r_val
)
46 return get_new_node_for_insert(r_val
, s_no_throw_copies_ind
);
50 inline typename
PB_DS_CLASS_C_DEC::node_pointer
52 get_new_node_for_insert(const_reference r_val
, false_type
)
54 node_pointer p_new_nd
= s_node_allocator
.allocate(1);
56 cond_dealtor_t
cond(p_new_nd
);
58 new (const_cast<void* >(
59 static_cast<const void* >(&p_new_nd
->m_value
)))
60 typename
node::value_type(r_val
);
70 inline typename
PB_DS_CLASS_C_DEC::node_pointer
72 get_new_node_for_insert(const_reference r_val
, true_type
)
74 node_pointer p_new_nd
= s_node_allocator
.allocate(1);
76 new (const_cast<void* >(
77 static_cast<const void* >(&p_new_nd
->m_value
)))
78 typename
node::value_type(r_val
);
88 make_child_of(node_pointer p_nd
, node_pointer p_new_parent
)
90 _GLIBCXX_DEBUG_ASSERT(p_nd
!= 0);
91 _GLIBCXX_DEBUG_ASSERT(p_new_parent
!= 0);
93 p_nd
->m_p_next_sibling
= p_new_parent
->m_p_l_child
;
95 if (p_new_parent
->m_p_l_child
!= 0)
96 p_new_parent
->m_p_l_child
->m_p_prev_or_parent
= p_nd
;
98 p_nd
->m_p_prev_or_parent
= p_new_parent
;
100 p_new_parent
->m_p_l_child
= p_nd
;
104 inline typename
PB_DS_CLASS_C_DEC::node_pointer
106 parent(node_pointer p_nd
)
110 node_pointer p_pot
= p_nd
->m_p_prev_or_parent
;
112 if (p_pot
== 0 || p_pot
->m_p_l_child
== p_nd
)
122 swap_with_parent(node_pointer p_nd
, node_pointer p_parent
)
124 if (p_parent
== m_p_root
)
127 _GLIBCXX_DEBUG_ASSERT(p_nd
!= 0);
128 _GLIBCXX_DEBUG_ASSERT(p_parent
!= 0);
129 _GLIBCXX_DEBUG_ASSERT(parent(p_nd
) == p_parent
);
131 const bool nd_direct_child
= p_parent
->m_p_l_child
== p_nd
;
132 const bool parent_root
= p_parent
->m_p_prev_or_parent
== 0;
133 const bool parent_direct_child
=
134 !parent_root
&& p_parent
->m_p_prev_or_parent
->m_p_l_child
== p_parent
;
136 std::swap(p_parent
->m_p_prev_or_parent
, p_nd
->m_p_prev_or_parent
);
137 std::swap(p_parent
->m_p_next_sibling
, p_nd
->m_p_next_sibling
);
138 std::swap(p_parent
->m_p_l_child
, p_nd
->m_p_l_child
);
139 std::swap(p_parent
->m_metadata
, p_nd
->m_metadata
);
141 _GLIBCXX_DEBUG_ASSERT(p_nd
->m_p_l_child
!= 0);
142 _GLIBCXX_DEBUG_ASSERT(p_parent
->m_p_prev_or_parent
!= 0);
144 if (p_nd
->m_p_next_sibling
!= 0)
145 p_nd
->m_p_next_sibling
->m_p_prev_or_parent
= p_nd
;
147 if (p_parent
->m_p_next_sibling
!= 0)
148 p_parent
->m_p_next_sibling
->m_p_prev_or_parent
= p_parent
;
150 if (p_parent
->m_p_l_child
!= 0)
151 p_parent
->m_p_l_child
->m_p_prev_or_parent
= p_parent
;
153 if (parent_direct_child
)
154 p_nd
->m_p_prev_or_parent
->m_p_l_child
= p_nd
;
155 else if (!parent_root
)
156 p_nd
->m_p_prev_or_parent
->m_p_next_sibling
= p_nd
;
158 if (!nd_direct_child
)
160 p_nd
->m_p_l_child
->m_p_prev_or_parent
= p_nd
;
162 p_parent
->m_p_prev_or_parent
->m_p_next_sibling
= p_parent
;
166 _GLIBCXX_DEBUG_ASSERT(p_nd
->m_p_l_child
== p_nd
);
167 _GLIBCXX_DEBUG_ASSERT(p_parent
->m_p_prev_or_parent
== p_parent
);
169 p_nd
->m_p_l_child
= p_parent
;
170 p_parent
->m_p_prev_or_parent
= p_nd
;
173 _GLIBCXX_DEBUG_ASSERT(parent(p_parent
) == p_nd
);