hash.hh 2.21 KB
Newer Older
1
2
3
// -*- coding: utf-8 -*-
// Copyright (C) 2008, 2011, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
Guillaume Sadegh's avatar
Guillaume Sadegh committed
4
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de
5
6
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
7
8
9
10
11
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
12
// the Free Software Foundation; either version 3 of the License, or
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
13
14
15
16
17
18
19
20
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
// License for more details.
//
// 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/>.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
22

23
24
25
#ifndef SPOT_MISC_HASH_HH
#  define SPOT_MISC_HASH_HH

26
#  include <string>
27
#  include <functional>
28
29
#  include "misc/hashfunc.hh"
#  include "misc/_config.h"
30

31
32
#  include <unordered_map>
#  include <unordered_set>
33
34
35
36

namespace spot
{

37
  /// \ingroup hash_funcs
38
  /// \brief A hash function for pointers.
39
  template <class T>
40
41
  struct ptr_hash :
    public std::unary_function<const T*, size_t>
42
  {
43
44
45
46
47
48
49
    // A default constructor is needed if the ptr_hash object is
    // stored in a const member.  This occur with the clang version
    // installed by OS X 10.9.
    ptr_hash()
    {
    }

50
    size_t operator()(const T* p) const
51
    {
52
53
      return knuth32_hash(reinterpret_cast<const char*>(p)
			  - static_cast<const char*>(0));
54
55
56
    }
  };

57
  /// \ingroup hash_funcs
58
  /// \brief A hash function for strings.
59
  typedef std::hash<std::string> string_hash;
60
61

  /// \ingroup hash_funcs
62
  /// \brief A hash function that returns identity
63
64
65
66
  template<typename T>
  struct identity_hash:
    public std::unary_function<const T&, size_t>
  {
67
68
69
70
71
72
    // A default constructor is needed if the string_hash object is
    // stored in a const member.
    identity_hash()
    {
    }

73
74
75
76
77
    size_t operator()(const T& s) const
    {
      return s;
    }
  };
78
79
80
}

#endif // SPOT_MISC_HASH_HH