gcc41 removal: Part 1 of 2: makefiles
[dragonfly.git] / contrib / gcc-4.1 / libstdc++-v3 / include / ext / pb_assoc / detail / cc_ht_map_ / erase_store_hash_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 erase_store_hash_fn_imps.hpp
42  * Contains implementations of cc_ht_map_'s erase related functions, when the hash
43  *      value is stored.
44  */
45
46 PB_ASSOC_CLASS_T_DEC
47 template<class T>
48 inline typename PB_ASSOC_CLASS_C_DEC::size_type
49 PB_ASSOC_CLASS_C_DEC::
50 erase(T r_t, bool erase_entry_if_last, pb_assoc::detail::int_to_type<true>)
51 {
52   PB_ASSOC_DBG_ONLY(assert_valid();)
53
54     return (erase_in_pos_imp<T>(r_t, erase_entry_if_last,
55                                 my_ranged_hash_fn_base::operator()(
56                                                                    my_traits_base::ext_eraser::extract_key(r_t))));
57 }
58
59 PB_ASSOC_CLASS_T_DEC
60 template<class T>
61 inline typename PB_ASSOC_CLASS_C_DEC::size_type
62 PB_ASSOC_CLASS_C_DEC::
63 erase_in_pos_imp(T r_t, bool erase_entry_if_last, const comp_hash& r_pos_hash_pair)
64 {
65   PB_ASSOC_DBG_ONLY(assert_valid();)
66
67     entry_pointer p_e = m_a_p_entries[r_pos_hash_pair.first];
68
69   my_resize_base::notify_erase_search_start();
70
71   if (p_e == NULL)
72     {
73       my_resize_base::notify_erase_search_end();
74
75       PB_ASSOC_DBG_ONLY(my_map_debug_base::
76                         check_key_does_not_exist(
77                                                  my_traits_base::ext_eraser::extract_key(r_t));)
78
79         PB_ASSOC_DBG_ONLY(assert_valid();)
80
81         return (0);
82     }
83
84   if (my_hash_eq_fn_base::operator()(p_e->m_value.first, p_e->m_hash,
85                                      my_traits_base::ext_eraser::extract_key(r_t), r_pos_hash_pair.second))
86     {
87       my_resize_base::notify_erase_search_end();
88
89       PB_ASSOC_DBG_ONLY(my_map_debug_base::check_key_exists(
90                                                             my_traits_base::ext_eraser::extract_key(r_t));)
91
92         std::pair<size_type, bool> ers_pair =
93         my_traits_base::ext_eraser::erase(
94                                           PB_ASSOC_EP2VP(m_a_p_entries[r_pos_hash_pair.first]),
95                                           r_t, erase_entry_if_last);
96
97       if (ers_pair.second)
98         {
99           erase_entry_pointer(m_a_p_entries[r_pos_hash_pair.first]);
100
101           do_resize_if_needed_no_throw();
102         }
103
104       PB_ASSOC_DBG_ONLY(assert_valid();)
105
106         return (ers_pair.first);
107     }
108
109   while (true)
110     {
111       entry_pointer p_next_e = p_e->m_p_next;
112
113       if (p_next_e == NULL)
114         {
115           my_resize_base::notify_erase_search_end();
116
117           PB_ASSOC_DBG_ONLY(my_map_debug_base::
118                             check_key_does_not_exist(
119                                                      my_traits_base::ext_eraser::extract_key(r_t));)
120
121             PB_ASSOC_DBG_ONLY(assert_valid();)
122
123             return (0);
124         }
125
126       if (my_hash_eq_fn_base::operator()(
127                                          p_next_e->m_value.first, p_next_e->m_hash,
128                                          my_traits_base::ext_eraser::extract_key(r_t),
129                                          r_pos_hash_pair.second))
130         {
131           my_resize_base::notify_erase_search_end();
132
133           PB_ASSOC_DBG_ONLY(my_map_debug_base::
134                             check_key_exists(
135                                              my_traits_base::ext_eraser::extract_key(r_t));)
136
137             std::pair<size_type, bool> ers_pair =
138             my_traits_base::ext_eraser::erase(
139                                               PB_ASSOC_EP2VP(p_e->m_p_next),
140                                               r_t, erase_entry_if_last);
141
142           if (ers_pair.second)
143             {
144               erase_entry_pointer(p_e->m_p_next);
145
146               do_resize_if_needed_no_throw();
147             }
148
149           PB_ASSOC_DBG_ONLY(assert_valid();)
150
151             return (ers_pair.first);
152         }
153
154       my_resize_base::notify_erase_search_collision();
155
156       p_e = p_next_e;
157     }
158 }
159