spot  2.7.1
hash.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2008, 2011, 2014, 2015, 2018 Laboratoire de Recherche et
3 // Développement de l'Epita (LRDE).
4 // Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de
5 // Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
6 // Université Pierre et Marie Curie.
7 //
8 // This file is part of Spot, a model checking library.
9 //
10 // Spot is free software; you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Spot is distributed in the hope that it will be useful, but WITHOUT
16 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 // License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 #pragma once
24 
25 #include <string>
26 #include <functional>
27 #include <spot/misc/hashfunc.hh>
28 
29 #include <unordered_map>
30 #include <unordered_set>
31 
32 namespace spot
33 {
34 
37  template <class T>
38  struct ptr_hash :
39  public std::unary_function<const T*, size_t>
40  {
41  // A default constructor is needed if the ptr_hash object is
42  // stored in a const member. This occur with the clang version
43  // installed by OS X 10.9.
44  ptr_hash()
45  {
46  }
47 
48  size_t operator()(const T* p) const noexcept
49  {
50  return knuth32_hash(reinterpret_cast<const char*>(p)
51  - static_cast<const char*>(nullptr));
52  }
53  };
54 
57  typedef std::hash<std::string> string_hash;
58 
61  template<typename T>
62  struct identity_hash:
63  public std::unary_function<const T&, size_t>
64  {
65  // A default constructor is needed if the identity_hash object is
66  // stored in a const member.
68  {
69  }
70 
71  size_t operator()(const T& s) const noexcept
72  {
73  return s;
74  }
75  };
76 
77 
78  struct pair_hash
79  {
80  template<typename T, typename U>
81  std::size_t operator()(const std::pair<T, U> &p) const noexcept
82  {
83  std::hash<T> th;
84  std::hash<U> uh;
85 
86  return wang32_hash(static_cast<size_t>(th(p.first)) ^
87  static_cast<size_t>(uh(p.second)));
88  }
89  };
90 }
Definition: automata.hh:26
size_t wang32_hash(size_t key)
Thomas Wang&#39;s 32 bit hash function.
Definition: hashfunc.hh:41
A hash function for pointers.
Definition: hash.hh:38
std::hash< std::string > string_hash
A hash function for strings.
Definition: hash.hh:57
Definition: hash.hh:78
size_t knuth32_hash(size_t key)
Knuth&#39;s Multiplicative hash function.
Definition: hashfunc.hh:60
A hash function that returns identity.
Definition: hash.hh:62

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Fri Feb 27 2015 10:00:07 for spot by doxygen 1.8.13