gcc41 removal: Part 1 of 2: makefiles
[dragonfly.git] / contrib / gcc-4.1 / libstdc++-v3 / include / ext / pb_assoc / detail / gp_ht_map_ / resize_fn_imps.hpp
1 // -*- C++ -*-
2
3 // Copyright (C) 2005 Free Software Foundation, Inc.
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
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
31
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
39
40 /**
41  * @file resize_fn_imps.hpp
42  * Contains implementations of gp_ht_map_'s resize related functions.
43  */
44
45 PB_ASSOC_CLASS_T_DEC
46 inline bool
47 PB_ASSOC_CLASS_C_DEC::
48 do_resize_if_needed()
49 {
50   if (!my_resize_base::is_resize_needed())
51     return (false);
52
53   do
54     do_resize(my_resize_base::get_new_size(m_num_e, m_num_used_e));
55   while (my_resize_base::is_resize_needed());
56
57   return (true);
58 }
59
60 PB_ASSOC_CLASS_T_DEC
61 inline void
62 PB_ASSOC_CLASS_C_DEC::
63 do_resize_if_needed_no_throw()
64 {
65   if (!my_resize_base::is_resize_needed())
66     return;
67
68   try
69     {
70       do
71         do_resize(my_resize_base::get_new_size(m_num_e, m_num_used_e));
72       while (my_resize_base::is_resize_needed());
73     }
74   catch(...)
75     { }
76
77   PB_ASSOC_DBG_ONLY(assert_valid();)
78     }
79
80 PB_ASSOC_CLASS_T_DEC
81 void
82 PB_ASSOC_CLASS_C_DEC::
83 do_resize(size_type new_size)
84 {
85 #ifdef PB_ASSOC_BASIC_REGRESSION
86   throw_prob_adjustor adjust(m_num_e);
87 #endif // #ifdef PB_ASSOC_BASIC_REGRESSION
88
89   PB_ASSOC_DBG_ONLY(assert_valid();)
90
91     const size_type old_size = m_num_e;
92
93   entry_array a_entries_resized = NULL;
94
95   my_ranged_probe_fn_base::notify_resized(new_size);
96
97   // Following line might throw an exception.
98
99   try
100     {
101       a_entries_resized = s_entry_allocator.allocate(new_size);
102     }
103   catch(...)
104     {
105       my_ranged_probe_fn_base::notify_resized(old_size);
106
107       throw;
108     }
109
110   m_num_e = new_size;
111
112   for (size_type i = 0; i < m_num_e; ++i)
113     a_entries_resized[i].m_stat = (entry_status)EMPTY_ENTRY_STATUS;
114
115   try
116     {
117       resize_imp(a_entries_resized, old_size);
118     }
119   catch(...)
120     {
121       erase_all_valid_entries(a_entries_resized, new_size);
122
123       m_num_e = old_size;
124
125       s_entry_allocator.deallocate(a_entries_resized, new_size);
126
127       my_ranged_probe_fn_base::notify_resized(old_size);
128
129       throw;
130     }
131
132   // At this point no exceptions can be thrown.
133
134   PB_ASSOC_DBG_ONLY(assert_entry_array_valid(a_entries_resized, my_hash_traits_base::s_store_hash_indicator);)
135
136     Resize_Policy::notify_resized(new_size);
137
138   erase_all_valid_entries(m_a_entries, old_size);
139
140   s_entry_allocator.deallocate(m_a_entries, old_size);
141
142   m_a_entries = a_entries_resized;
143
144   PB_ASSOC_DBG_ONLY(assert_valid();)
145     }
146
147 PB_ASSOC_CLASS_T_DEC
148 void
149 PB_ASSOC_CLASS_C_DEC::
150 resize_imp(entry_array a_entries_resized, size_type old_size)
151 {
152   for (size_type pos = 0; pos < old_size; ++pos)
153     if (m_a_entries[pos].m_stat == VALID_ENTRY_STATUS)
154       resize_imp_reassign(m_a_entries + pos, a_entries_resized, my_hash_traits_base::s_store_hash_indicator);
155 }
156
157 #include <ext/pb_assoc/detail/gp_ht_map_/resize_no_store_hash_fn_imps.hpp>
158 #include <ext/pb_assoc/detail/gp_ht_map_/resize_store_hash_fn_imps.hpp>