STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hash_eq_fn.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // Copyright (C) 2005-2013 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 terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
9 // version.
10 
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
26 
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
34 // warranty.
35 
42 #ifndef PB_DS_HASH_EQ_FN_HPP
43 #define PB_DS_HASH_EQ_FN_HPP
44 
45 #include <utility>
46 #include <debug/debug.h>
47 
48 namespace __gnu_pbds
49 {
50  namespace detail
51  {
53  template<typename Key, typename Eq_Fn, typename _Alloc, bool Store_Hash>
54  struct hash_eq_fn;
55 
57  template<typename Key, typename Eq_Fn, typename _Alloc>
58  struct hash_eq_fn<Key, Eq_Fn, _Alloc, false> : public Eq_Fn
59  {
60  typedef Eq_Fn eq_fn_base;
61  typedef typename _Alloc::template rebind<Key>::other key_allocator;
62  typedef typename key_allocator::const_reference key_const_reference;
63 
64  hash_eq_fn() { }
65 
66  hash_eq_fn(const Eq_Fn& r_eq_fn) : Eq_Fn(r_eq_fn) { }
67 
68  bool
70  key_const_reference r_rhs_key) const
71  { return eq_fn_base::operator()(r_lhs_key, r_rhs_key); }
72 
73  void
74  swap(const hash_eq_fn& other)
75  { std::swap((Eq_Fn&)(*this), (Eq_Fn&)other); }
76  };
77 
78 
80  template<typename Key, class Eq_Fn, class _Alloc>
81  struct hash_eq_fn<Key, Eq_Fn, _Alloc, true> : public Eq_Fn
82  {
83  typedef typename _Alloc::size_type size_type;
84  typedef Eq_Fn eq_fn_base;
85  typedef typename _Alloc::template rebind<Key>::other key_allocator;
86  typedef typename key_allocator::const_reference key_const_reference;
87 
88  hash_eq_fn() { }
89 
90  hash_eq_fn(const Eq_Fn& r_eq_fn) : Eq_Fn(r_eq_fn) { }
91 
92  bool
94  key_const_reference r_rhs_key, size_type rhs_hash) const
95  {
96  _GLIBCXX_DEBUG_ASSERT(!eq_fn_base::operator()(r_lhs_key, r_rhs_key)
97  || lhs_hash == rhs_hash);
98 
99  return (lhs_hash == rhs_hash &&
100  eq_fn_base::operator()(r_lhs_key, r_rhs_key));
101  }
102 
103  void
104  swap(const hash_eq_fn& other)
105  { std::swap((Eq_Fn&)(*this), (Eq_Fn&)(other)); }
106  };
107  } // namespace detail
108 } // namespace __gnu_pbds
109 
110 #endif
_Alloc::size_type size_type
Definition: hash_eq_fn.hpp:83
hash_eq_fn(const Eq_Fn &r_eq_fn)
Definition: hash_eq_fn.hpp:90
void swap(const hash_eq_fn &other)
Definition: hash_eq_fn.hpp:104
#define false
Definition: stdbool.h:35
Primary template.
Definition: hash_eq_fn.hpp:54
key_allocator::const_reference key_const_reference
Definition: hash_eq_fn.hpp:86
#define _GLIBCXX_DEBUG_ASSERT(_Condition)
Definition: debug.h:61
#define true
Definition: stdbool.h:34
void swap(const hash_eq_fn &other)
Definition: hash_eq_fn.hpp:74
bool operator()(key_const_reference r_lhs_key, key_const_reference r_rhs_key) const
Definition: hash_eq_fn.hpp:69
_Alloc::template rebind< Key >::other key_allocator
Definition: hash_eq_fn.hpp:85
bool operator()(key_const_reference r_lhs_key, size_type lhs_hash, key_const_reference r_rhs_key, size_type rhs_hash) const
Definition: hash_eq_fn.hpp:93
_Alloc::template rebind< Key >::other key_allocator
Definition: hash_eq_fn.hpp:61
key_allocator::const_reference key_const_reference
Definition: hash_eq_fn.hpp:62
hash_eq_fn(const Eq_Fn &r_eq_fn)
Definition: hash_eq_fn.hpp:66
void swap(exception_ptr &__lhs, exception_ptr &__rhs)
Definition: exception_ptr.h:160