3 // Copyright (C) 2005 Free Software Foundation, Inc.
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)
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.
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,
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.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
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.
41 * @file hash_eq_fn.hpp
42 * Contains 2 eqivalence functions, one employing a hash value,
43 * and one ignoring it.
46 #ifndef HASH_EQ_FN_HPP
47 #define HASH_EQ_FN_HPP
57 #ifdef PB_ASSOC_HASH_EQ_FN_DEBUG
58 #define PB_ASSOC_DBG_ASSERT(X) assert(X)
59 #define PB_ASSOC_DBG_VERIFY(X) assert(X)
60 #define PB_ASSOC_DBG_ONLY(X) X
61 #else // #ifdef PB_ASSOC_HASH_EQ_FN_DEBUG
62 #define PB_ASSOC_DBG_ASSERT(X)
63 #define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
64 #define PB_ASSOC_DBG_ONLY(X) ;
65 #endif // #ifdef PB_ASSOC_HASH_EQ_FN_DEBUG
67 template<typename Key, class Eq_Fn, class Allocator, bool Store_Hash>
70 #define PB_ASSOC_CLASS_T_DEC \
71 template<typename Key, class Eq_Fn, class Allocator>
73 #define PB_ASSOC_CLASS_C_DEC \
81 * Specialization 1- The client requests that hash values not be stored.
83 template<typename Key, class Eq_Fn, class Allocator>
84 struct hash_eq_fn<Key, Eq_Fn, Allocator, false> : public Eq_Fn
86 typedef Eq_Fn my_eq_fn_base;
88 typedef typename Allocator::template rebind<Key>::other key_allocator;
90 typedef typename key_allocator::const_reference const_key_reference;
94 hash_eq_fn(const Eq_Fn& r_eq_fn);
97 operator()(const_key_reference r_lhs_key, const_key_reference r_rhs_key) const;
100 swap(const PB_ASSOC_CLASS_C_DEC& r_other);
104 PB_ASSOC_CLASS_C_DEC::
110 PB_ASSOC_CLASS_C_DEC::
111 swap(const PB_ASSOC_CLASS_C_DEC& r_other)
113 std::swap((Eq_Fn& )(*this), (Eq_Fn& )r_other);
117 PB_ASSOC_CLASS_C_DEC::
118 hash_eq_fn(const Eq_Fn& r_eq_fn) :
124 PB_ASSOC_CLASS_C_DEC::
125 operator()(const_key_reference r_lhs_key, const_key_reference r_rhs_key) const
127 return (my_eq_fn_base::operator()(r_lhs_key, r_rhs_key));
130 #undef PB_ASSOC_CLASS_T_DEC
131 #undef PB_ASSOC_CLASS_C_DEC
133 #define PB_ASSOC_CLASS_T_DEC \
134 template<typename Key, class Eq_Fn, class Allocator>
136 #define PB_ASSOC_CLASS_C_DEC \
144 * Specialization 2- The client requests that hash values be stored.
146 template<typename Key, class Eq_Fn, class Allocator>
147 struct hash_eq_fn<Key, Eq_Fn, Allocator, true> :
150 typedef typename Allocator::size_type size_type;
152 typedef Eq_Fn my_eq_fn_base;
154 typedef typename Allocator::template rebind<Key>::other key_allocator;
156 typedef typename key_allocator::const_reference const_key_reference;
160 hash_eq_fn(const Eq_Fn& r_eq_fn);
163 operator()(const_key_reference r_lhs_key, size_type lhs_hash, const_key_reference r_rhs_key, size_type rhs_hash) const;
166 swap(const PB_ASSOC_CLASS_C_DEC& r_other);
170 PB_ASSOC_CLASS_C_DEC::
175 PB_ASSOC_CLASS_C_DEC::
176 hash_eq_fn(const Eq_Fn& r_eq_fn) :
182 PB_ASSOC_CLASS_C_DEC::
183 operator()(const_key_reference r_lhs_key, size_type lhs_hash, const_key_reference r_rhs_key, size_type rhs_hash) const
185 PB_ASSOC_DBG_ASSERT(!my_eq_fn_base::operator()(r_lhs_key, r_rhs_key) ||
186 lhs_hash == rhs_hash);
188 return (lhs_hash == rhs_hash&&
189 my_eq_fn_base::operator()(r_lhs_key, r_rhs_key));
194 PB_ASSOC_CLASS_C_DEC::
195 swap(const PB_ASSOC_CLASS_C_DEC& r_other)
197 std::swap((Eq_Fn& )(*this), (Eq_Fn& )(r_other));
200 #undef PB_ASSOC_CLASS_T_DEC
201 #undef PB_ASSOC_CLASS_C_DEC
203 #undef PB_ASSOC_DBG_ASSERT
204 #undef PB_ASSOC_DBG_VERIFY
205 #undef PB_ASSOC_DBG_ONLY
207 } // namespace detail
209 } // namespace pb_assoc
211 #endif // #ifndef HASH_EQ_FN_HPP