hash.hh 2.34 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
33
34
35
36
#  include <unordered_map>
#  include <unordered_set>
   namespace Sgi = std;
#  define hash_map unordered_map
#  define hash_multimap unordered_multimap
#  define hash_set unordered_set
37
38
39
40

namespace spot
{

41
  /// \ingroup hash_funcs
42
  /// \brief A hash function for pointers.
43
  template <class T>
44
45
  struct ptr_hash :
    public std::unary_function<const T*, size_t>
46
  {
47
48
49
50
51
52
53
    // 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()
    {
    }

54
    size_t operator()(const T* p) const
55
    {
56
57
      return knuth32_hash(reinterpret_cast<const char*>(p)
			  - static_cast<const char*>(0));
58
59
60
    }
  };

61
  /// \ingroup hash_funcs
62
  /// \brief A hash function for strings.
63
  typedef Sgi::hash<std::string> string_hash;
64
65

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

77
78
79
80
81
    size_t operator()(const T& s) const
    {
      return s;
    }
  };
82
83
84
}

#endif // SPOT_MISC_HASH_HH