]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/binary_heap_/constructors_destructor_fn_imps.hpp
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / binary_heap_ / constructors_destructor_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 binary_heap_/constructors_destructor_fn_imps.hpp
4569a895
AT
38 * Contains an implementation class for binary_heap_.
39 */
40
574dfb67
JW
41#ifdef PB_DS_CLASS_C_DEC
42
4569a895
AT
43PB_DS_CLASS_T_DEC
44typename PB_DS_CLASS_C_DEC::entry_allocator
45PB_DS_CLASS_C_DEC::s_entry_allocator;
46
47PB_DS_CLASS_T_DEC
48typename PB_DS_CLASS_C_DEC::value_allocator
49PB_DS_CLASS_C_DEC::s_value_allocator;
50
51PB_DS_CLASS_T_DEC
52typename PB_DS_CLASS_C_DEC::no_throw_copies_t
53PB_DS_CLASS_C_DEC::s_no_throw_copies_ind;
54
55PB_DS_CLASS_T_DEC
56template<typename It>
57void
58PB_DS_CLASS_C_DEC::
59copy_from_range(It first_it, It last_it)
60{
61 while (first_it != last_it)
62 {
63 insert_value(*first_it, s_no_throw_copies_ind);
4569a895
AT
64 ++first_it;
65 }
a345e45d
BK
66 make_heap();
67 PB_DS_ASSERT_VALID((*this))
8fafc2d3 68}
4569a895
AT
69
70PB_DS_CLASS_T_DEC
71PB_DS_CLASS_C_DEC::
a345e45d
BK
72binary_heap()
73: m_size(0), m_actual_size(resize_policy::min_size),
4569a895 74 m_a_entries(s_entry_allocator.allocate(m_actual_size))
a345e45d 75{ PB_DS_ASSERT_VALID((*this)) }
4569a895
AT
76
77PB_DS_CLASS_T_DEC
78PB_DS_CLASS_C_DEC::
a345e45d
BK
79binary_heap(const Cmp_Fn& r_cmp_fn)
80: entry_cmp(r_cmp_fn), m_size(0), m_actual_size(resize_policy::min_size),
4569a895 81 m_a_entries(s_entry_allocator.allocate(m_actual_size))
a345e45d 82{ PB_DS_ASSERT_VALID((*this)) }
4569a895
AT
83
84PB_DS_CLASS_T_DEC
85PB_DS_CLASS_C_DEC::
a345e45d
BK
86binary_heap(const PB_DS_CLASS_C_DEC& other)
87: entry_cmp(other), resize_policy(other), m_size(0),
4569a895
AT
88 m_actual_size(other.m_actual_size),
89 m_a_entries(s_entry_allocator.allocate(m_actual_size))
90{
f5886803 91 PB_DS_ASSERT_VALID(other)
8fafc2d3 92 _GLIBCXX_DEBUG_ASSERT(m_a_entries != other.m_a_entries);
4569a895 93
bc2631e0 94 __try
4569a895 95 {
a345e45d 96 copy_from_range(other.begin(), other.end());
4569a895 97 }
bc2631e0 98 __catch(...)
4569a895
AT
99 {
100 for (size_type i = 0; i < m_size; ++i)
101 erase_at(m_a_entries, i, s_no_throw_copies_ind);
102
103 s_entry_allocator.deallocate(m_a_entries, m_actual_size);
8fafc2d3 104 __throw_exception_again;
4569a895 105 }
f5886803 106 PB_DS_ASSERT_VALID((*this))
8fafc2d3 107}
4569a895
AT
108
109PB_DS_CLASS_T_DEC
110void
111PB_DS_CLASS_C_DEC::
112swap(PB_DS_CLASS_C_DEC& other)
113{
f5886803
FD
114 PB_DS_ASSERT_VALID((*this))
115 PB_DS_ASSERT_VALID(other)
8fafc2d3 116 _GLIBCXX_DEBUG_ASSERT(m_a_entries != other.m_a_entries);
4569a895 117 value_swap(other);
a345e45d 118 std::swap((entry_cmp&)(*this), (entry_cmp&)other);
f5886803
FD
119 PB_DS_ASSERT_VALID((*this))
120 PB_DS_ASSERT_VALID(other)
8fafc2d3 121}
4569a895
AT
122
123PB_DS_CLASS_T_DEC
124void
125PB_DS_CLASS_C_DEC::
126value_swap(PB_DS_CLASS_C_DEC& other)
127{
128 std::swap(m_a_entries, other.m_a_entries);
4569a895 129 std::swap(m_size, other.m_size);
4569a895 130 std::swap(m_actual_size, other.m_actual_size);
8fafc2d3 131 static_cast<resize_policy*>(this)->swap(other);
4569a895
AT
132}
133
134PB_DS_CLASS_T_DEC
135PB_DS_CLASS_C_DEC::
a345e45d 136~binary_heap()
4569a895
AT
137{
138 for (size_type i = 0; i < m_size; ++i)
139 erase_at(m_a_entries, i, s_no_throw_copies_ind);
4569a895
AT
140 s_entry_allocator.deallocate(m_a_entries, m_actual_size);
141}
574dfb67 142#endif