spot 2.3.3

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
hash.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2008, 2011, 2014, 2015 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
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 string_hash object is
67 // stored in a const member.
68 identity_hash()
69 {
70 }
71
72 size_t operator()(const T& s) const
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
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 }
spot
Definition: graph.hh:33
spot::wang32_hash
size_t wang32_hash(size_t key)
Thomas Wang's 32 bit hash function.
Definition: hashfunc.hh:40
spot::ptr_hash
A hash function for pointers.
Definition: hash.hh:39
spot::string_hash
std::hash< std::string > string_hash
A hash function for strings.
Definition: hash.hh:58
spot::pair_hash
Definition: hash.hh:79
spot::knuth32_hash
size_t knuth32_hash(size_t key)
Knuth's Multiplicative hash function.
Definition: hashfunc.hh:59
spot::identity_hash
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.