spot  2.5.2
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 #include <spot/misc/_config.h>
29 
30 #include <unordered_map>
31 #include <unordered_set>
32 
33 namespace spot
34 {
35 
38  template <class T>
39  struct ptr_hash :
40  public std::unary_function<const T*, size_t>
41  {
42  // A default constructor is needed if the ptr_hash object is
43  // stored in a const member. This occur with the clang version
44  // installed by OS X 10.9.
45  ptr_hash()
46  {
47  }
48 
49  size_t operator()(const T* p) const noexcept
50  {
51  return knuth32_hash(reinterpret_cast<const char*>(p)
52  - static_cast<const char*>(nullptr));
53  }
54  };
55 
58  typedef std::hash<std::string> string_hash;
59 
62  template<typename T>
63  struct identity_hash:
64  public std::unary_function<const T&, size_t>
65  {
66  // A default constructor is needed if the identity_hash object is
67  // stored in a const member.
69  {
70  }
71 
72  size_t operator()(const T& s) const noexcept
73  {
74  return s;
75  }
76  };
77 
78 
79  struct pair_hash
80  {
81  template<typename T, typename U>
82  std::size_t operator()(const std::pair<T, U> &p) const noexcept
83  {
84  std::hash<T> th;
85  std::hash<U> uh;
86 
87  return wang32_hash(static_cast<size_t>(th(p.first)) ^
88  static_cast<size_t>(uh(p.second)));
89  }
90  };
91 }
Definition: automata.hh:26
size_t wang32_hash(size_t key)
Thomas Wang&#39;s 32 bit hash function.
Definition: hashfunc.hh:40
A hash function for pointers.
Definition: hash.hh:39
std::hash< std::string > string_hash
A hash function for strings.
Definition: hash.hh:58
Definition: hash.hh:79
size_t knuth32_hash(size_t key)
Knuth&#39;s Multiplicative hash function.
Definition: hashfunc.hh:59
A hash function that returns identity.
Definition: hash.hh:63

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