]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / left_child_next_sibling_heap_ / insert_fn_imps.hpp
CommitLineData
4569a895
AT
1// -*- C++ -*-
2
a945c346 3// Copyright (C) 2005-2024 Free Software Foundation, Inc.
4569a895
AT
4//
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
748086b7 8// Foundation; either version 3, or (at your option) any later
4569a895
AT
9// version.
10
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.
15
748086b7
JJ
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.
4569a895 19
748086b7
JJ
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/>.
4569a895
AT
24
25// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
26
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
34// warranty.
35
36/**
a345e45d 37 * @file left_child_next_sibling_heap_/insert_fn_imps.hpp
4569a895
AT
38 * Contains an implementation class for left_child_next_sibling_heap_.
39 */
40
574dfb67
JW
41#ifdef PB_DS_CLASS_C_DEC
42
4569a895
AT
43PB_DS_CLASS_T_DEC
44inline typename PB_DS_CLASS_C_DEC::node_pointer
45PB_DS_CLASS_C_DEC::
46get_new_node_for_insert(const_reference r_val)
47{
48 return get_new_node_for_insert(r_val, s_no_throw_copies_ind);
49}
50
51PB_DS_CLASS_T_DEC
52inline typename PB_DS_CLASS_C_DEC::node_pointer
53PB_DS_CLASS_C_DEC::
54get_new_node_for_insert(const_reference r_val, false_type)
55{
56 node_pointer p_new_nd = s_node_allocator.allocate(1);
57
58 cond_dealtor_t cond(p_new_nd);
59
60 new (const_cast<void* >(
61 static_cast<const void* >(&p_new_nd->m_value)))
62 typename node::value_type(r_val);
63
64 cond.set_no_action();
65
66 ++m_size;
67
68 return (p_new_nd);
69}
70
71PB_DS_CLASS_T_DEC
72inline typename PB_DS_CLASS_C_DEC::node_pointer
73PB_DS_CLASS_C_DEC::
74get_new_node_for_insert(const_reference r_val, true_type)
75{
76 node_pointer p_new_nd = s_node_allocator.allocate(1);
77
78 new (const_cast<void* >(
79 static_cast<const void* >(&p_new_nd->m_value)))
80 typename node::value_type(r_val);
81
82 ++m_size;
83
84 return (p_new_nd);
85}
86
87PB_DS_CLASS_T_DEC
88inline void
89PB_DS_CLASS_C_DEC::
90make_child_of(node_pointer p_nd, node_pointer p_new_parent)
91{
8fc81078
PC
92 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
93 _GLIBCXX_DEBUG_ASSERT(p_new_parent != 0);
4569a895
AT
94
95 p_nd->m_p_next_sibling = p_new_parent->m_p_l_child;
96
8fc81078 97 if (p_new_parent->m_p_l_child != 0)
4569a895
AT
98 p_new_parent->m_p_l_child->m_p_prev_or_parent = p_nd;
99
100 p_nd->m_p_prev_or_parent = p_new_parent;
101
102 p_new_parent->m_p_l_child = p_nd;
103}
104
105PB_DS_CLASS_T_DEC
106inline typename PB_DS_CLASS_C_DEC::node_pointer
107PB_DS_CLASS_C_DEC::
108parent(node_pointer p_nd)
109{
110 while (true)
111 {
112 node_pointer p_pot = p_nd->m_p_prev_or_parent;
113
8fc81078 114 if (p_pot == 0 || p_pot->m_p_l_child == p_nd)
4569a895
AT
115 return p_pot;
116
117 p_nd = p_pot;
118 }
119}
120
121PB_DS_CLASS_T_DEC
122inline void
123PB_DS_CLASS_C_DEC::
124swap_with_parent(node_pointer p_nd, node_pointer p_parent)
125{
126 if (p_parent == m_p_root)
127 m_p_root = p_nd;
128
8fc81078
PC
129 _GLIBCXX_DEBUG_ASSERT(p_nd != 0);
130 _GLIBCXX_DEBUG_ASSERT(p_parent != 0);
47bea7b8 131 _GLIBCXX_DEBUG_ASSERT(parent(p_nd) == p_parent);
4569a895
AT
132
133 const bool nd_direct_child = p_parent->m_p_l_child == p_nd;
8fc81078 134 const bool parent_root = p_parent->m_p_prev_or_parent == 0;
4569a895
AT
135 const bool parent_direct_child =
136 !parent_root&& p_parent->m_p_prev_or_parent->m_p_l_child == p_parent;
137
138 std::swap(p_parent->m_p_prev_or_parent, p_nd->m_p_prev_or_parent);
139 std::swap(p_parent->m_p_next_sibling, p_nd->m_p_next_sibling);
140 std::swap(p_parent->m_p_l_child, p_nd->m_p_l_child);
141 std::swap(p_parent->m_metadata, p_nd->m_metadata);
142
8fc81078
PC
143 _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_l_child != 0);
144 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_prev_or_parent != 0);
4569a895 145
8fc81078 146 if (p_nd->m_p_next_sibling != 0)
4569a895
AT
147 p_nd->m_p_next_sibling->m_p_prev_or_parent = p_nd;
148
8fc81078 149 if (p_parent->m_p_next_sibling != 0)
4569a895
AT
150 p_parent->m_p_next_sibling->m_p_prev_or_parent = p_parent;
151
8fc81078 152 if (p_parent->m_p_l_child != 0)
4569a895
AT
153 p_parent->m_p_l_child->m_p_prev_or_parent = p_parent;
154
155 if (parent_direct_child)
156 p_nd->m_p_prev_or_parent->m_p_l_child = p_nd;
157 else if (!parent_root)
158 p_nd->m_p_prev_or_parent->m_p_next_sibling = p_nd;
159
160 if (!nd_direct_child)
161 {
162 p_nd->m_p_l_child->m_p_prev_or_parent = p_nd;
163
164 p_parent->m_p_prev_or_parent->m_p_next_sibling = p_parent;
165 }
166 else
167 {
47bea7b8
BK
168 _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_l_child == p_nd);
169 _GLIBCXX_DEBUG_ASSERT(p_parent->m_p_prev_or_parent == p_parent);
4569a895
AT
170
171 p_nd->m_p_l_child = p_parent;
172 p_parent->m_p_prev_or_parent = p_nd;
173 }
174
47bea7b8 175 _GLIBCXX_DEBUG_ASSERT(parent(p_parent) == p_nd);
4569a895
AT
176}
177
574dfb67 178#endif