erase_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<true>)
00051 {
00052   PB_ASSOC_DBG_ONLY(assert_valid();)
00053 
00054     return (erase_in_pos_imp<T>(r_t, erase_entry_if_last,
00055                 my_ranged_hash_fn_base::operator()(
00056                                    my_traits_base::ext_eraser::extract_key(r_t))));
00057 }
00058 
00059 PB_ASSOC_CLASS_T_DEC
00060 template<class T>
00061 inline typename PB_ASSOC_CLASS_C_DEC::size_type
00062 PB_ASSOC_CLASS_C_DEC::
00063 erase_in_pos_imp(T r_t, bool erase_entry_if_last, const comp_hash& r_pos_hash_pair)
00064 {
00065   PB_ASSOC_DBG_ONLY(assert_valid();)
00066 
00067     entry_pointer p_e = m_a_p_entries[r_pos_hash_pair.first];
00068 
00069   my_resize_base::notify_erase_search_start();
00070 
00071   if (p_e == NULL)
00072     {
00073       my_resize_base::notify_erase_search_end();
00074 
00075       PB_ASSOC_DBG_ONLY(my_map_debug_base::
00076             check_key_does_not_exist(
00077                          my_traits_base::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()(p_e->m_value.first, p_e->m_hash,
00085                      my_traits_base::ext_eraser::extract_key(r_t), r_pos_hash_pair.second))
00086     {
00087       my_resize_base::notify_erase_search_end();
00088 
00089       PB_ASSOC_DBG_ONLY(my_map_debug_base::check_key_exists(
00090                                 my_traits_base::ext_eraser::extract_key(r_t));)
00091 
00092     std::pair<size_type, bool> ers_pair =
00093     my_traits_base::ext_eraser::erase(
00094                       PB_ASSOC_EP2VP(m_a_p_entries[r_pos_hash_pair.first]),
00095                       r_t, erase_entry_if_last);
00096 
00097       if (ers_pair.second)
00098     {
00099       erase_entry_pointer(m_a_p_entries[r_pos_hash_pair.first]);
00100 
00101       do_resize_if_needed_no_throw();
00102     }
00103 
00104       PB_ASSOC_DBG_ONLY(assert_valid();)
00105 
00106     return (ers_pair.first);
00107     }
00108 
00109   while (true)
00110     {
00111       entry_pointer p_next_e = p_e->m_p_next;
00112 
00113       if (p_next_e == NULL)
00114     {
00115       my_resize_base::notify_erase_search_end();
00116 
00117       PB_ASSOC_DBG_ONLY(my_map_debug_base::
00118                 check_key_does_not_exist(
00119                              my_traits_base::ext_eraser::extract_key(r_t));)
00120 
00121         PB_ASSOC_DBG_ONLY(assert_valid();)
00122 
00123         return (0);
00124     }
00125 
00126       if (my_hash_eq_fn_base::operator()(
00127                      p_next_e->m_value.first, p_next_e->m_hash,
00128                      my_traits_base::ext_eraser::extract_key(r_t),
00129                      r_pos_hash_pair.second))
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:56 2010 for GNU C++ STL by  doxygen 1.4.7