erase_no_store_hash_fn_imps.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00031 
00032 // Permission to use, copy, modify, sell, and distribute this software
00033 // is hereby granted without fee, provided that the above copyright
00034 // notice appears in all copies, and that both that copyright notice and
00035 // this permission notice appear in supporting documentation. None of
00036 // the above authors, nor IBM Haifa Research Laboratories, make any
00037 // representation about the suitability of this software for any
00038 // purpose. It is provided "as is" without express or implied warranty.
00039 
00046 PB_ASSOC_CLASS_T_DEC
00047 template<class T>
00048 inline typename PB_ASSOC_CLASS_C_DEC::size_type
00049 PB_ASSOC_CLASS_C_DEC::
00050 erase(T r_t, bool erase_entry_if_last, pb_assoc::detail::int_to_type<false>)
00051 {
00052   PB_ASSOC_DBG_ONLY(assert_valid();)
00053 
00054     return (erase_in_pos_imp<T>(r_t,
00055                 erase_entry_if_last,
00056                 my_ranged_hash_fn_base::operator()(
00057                                    my_traits_base::ext_eraser::extract_key(r_t))));
00058 }
00059 
00060 PB_ASSOC_CLASS_T_DEC
00061 template<class T>
00062 inline typename PB_ASSOC_CLASS_C_DEC::size_type
00063 PB_ASSOC_CLASS_C_DEC::
00064 erase_in_pos_imp(T r_t, bool erase_entry_if_last, size_type pos)
00065 {
00066   PB_ASSOC_DBG_ONLY(assert_valid();)
00067 
00068     entry_pointer p_e = m_a_p_entries[pos];
00069 
00070   my_resize_base::notify_erase_search_start();
00071 
00072   if (p_e == NULL)
00073     {
00074       my_resize_base::notify_erase_search_end();
00075 
00076       PB_ASSOC_DBG_ONLY(my_map_debug_base::check_key_does_not_exist(
00077                                     ext_eraser::extract_key(r_t));)
00078 
00079     PB_ASSOC_DBG_ONLY(assert_valid();)
00080 
00081     return (0);
00082     }
00083 
00084   if (my_hash_eq_fn_base::operator()(
00085                      p_e->m_value.first,
00086                      my_traits_base::ext_eraser::extract_key(r_t)))
00087     {
00088       my_resize_base::notify_erase_search_end();
00089 
00090       PB_ASSOC_DBG_ONLY(my_map_debug_base::
00091             check_key_exists(my_traits_base::ext_eraser::extract_key(r_t));)
00092 
00093     std::pair<size_type, bool> ers_pair =
00094     my_traits_base::ext_eraser::erase(
00095                       PB_ASSOC_EP2VP(m_a_p_entries[pos]),
00096                       r_t, erase_entry_if_last);
00097 
00098       if (ers_pair.second)
00099     {
00100       erase_entry_pointer(m_a_p_entries[pos]);
00101 
00102       do_resize_if_needed_no_throw();
00103     }
00104 
00105       PB_ASSOC_DBG_ONLY(assert_valid();)
00106 
00107     return (ers_pair.first);
00108     }
00109 
00110   while (true)
00111     {
00112       entry_pointer p_next_e = p_e->m_p_next;
00113 
00114       if (p_next_e == NULL)
00115     {
00116       my_resize_base::notify_erase_search_end();
00117 
00118       PB_ASSOC_DBG_ONLY(my_map_debug_base::
00119                 check_key_does_not_exist(
00120                              my_traits_base::ext_eraser::extract_key(r_t));)
00121 
00122         PB_ASSOC_DBG_ONLY(assert_valid();)
00123 
00124         return (0);
00125     }
00126 
00127       if (my_hash_eq_fn_base::operator()(
00128                      p_next_e->m_value.first,
00129                      my_traits_base::ext_eraser::extract_key(r_t)))
00130     {
00131       my_resize_base::notify_erase_search_end();
00132 
00133       PB_ASSOC_DBG_ONLY(my_map_debug_base::
00134                 check_key_exists(
00135                          my_traits_base::ext_eraser::extract_key(r_t));)
00136 
00137         std::pair<size_type, bool> ers_pair =
00138         my_traits_base::ext_eraser::erase(
00139                           PB_ASSOC_EP2VP(p_e->m_p_next),
00140                           r_t, erase_entry_if_last);
00141 
00142       if (ers_pair.second)
00143         {
00144           erase_entry_pointer(p_e->m_p_next);
00145 
00146           do_resize_if_needed_no_throw();
00147         }
00148 
00149       PB_ASSOC_DBG_ONLY(assert_valid();)
00150 
00151         return (ers_pair.first);
00152     }
00153 
00154       my_resize_base::notify_erase_search_collision();
00155 
00156       p_e = p_next_e;
00157     }
00158 }
00159 

Generated on Tue Feb 2 16:55:55 2010 for GNU C++ STL by  doxygen 1.4.7