* src/misc/hashfunc.hh (wang32_hash): New file and function,
extracted from... * src/evtgba/product.cc (evtgba_product_state::hash): ... here. * src/misc/Makefile.am (misc_HEADERS): Add hashfunc.hh.
This commit is contained in:
parent
49b871f924
commit
dfb832cf20
4 changed files with 50 additions and 15 deletions
|
|
@ -20,6 +20,7 @@
|
|||
// 02111-1307, USA.
|
||||
|
||||
#include "product.hh"
|
||||
#include "misc/hashfunc.hh"
|
||||
#include "misc/modgray.hh"
|
||||
#include <cstdlib>
|
||||
#include <set>
|
||||
|
|
@ -75,23 +76,9 @@ namespace spot
|
|||
size_t
|
||||
hash() const
|
||||
{
|
||||
// We assume that size_t has at least 32bits.
|
||||
size_t res = 0;
|
||||
for (int i = 0; i != n_; ++i)
|
||||
{
|
||||
size_t key = s_[i]->hash();
|
||||
|
||||
// Thomas Wang's 32 bit hash Function
|
||||
// http://www.concentric.net/~Ttwang/tech/inthash.htm
|
||||
key += ~(key << 15);
|
||||
key ^= (key >> 10);
|
||||
key += (key << 3);
|
||||
key ^= (key >> 6);
|
||||
key += ~(key << 11);
|
||||
key ^= (key >> 16);
|
||||
|
||||
res ^= key;
|
||||
}
|
||||
res ^= wang32_hash(s_[i]->hash());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ misc_HEADERS = \
|
|||
escape.hh \
|
||||
freelist.hh \
|
||||
hash.hh \
|
||||
hashfunc.hh \
|
||||
minato.hh \
|
||||
modgray.hh \
|
||||
random.hh \
|
||||
|
|
|
|||
40
src/misc/hashfunc.hh
Normal file
40
src/misc/hashfunc.hh
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// 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
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (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
|
||||
// along with Spot; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
namespace spot
|
||||
{
|
||||
/// \brief Thomas Wang's 32 bit hash function.
|
||||
///
|
||||
/// Hash an integer amongst the integers.
|
||||
/// http://www.concentric.net/~Ttwang/tech/inthash.htm
|
||||
inline size_t
|
||||
wang32_hash(size_t key)
|
||||
{
|
||||
// We assume that size_t has at least 32bits.
|
||||
key += ~(key << 15);
|
||||
key ^= (key >> 10);
|
||||
key += (key << 3);
|
||||
key ^= (key >> 6);
|
||||
key += ~(key << 11);
|
||||
key ^= (key >> 16);
|
||||
return key;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue