From dfb832cf20dd161f5d0b48969bd0239ec67a3ba9 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Tue, 16 Nov 2004 14:59:49 +0000 Subject: [PATCH] * 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. --- ChangeLog | 7 +++++++ src/evtgba/product.cc | 17 ++--------------- src/misc/Makefile.am | 1 + src/misc/hashfunc.hh | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 src/misc/hashfunc.hh diff --git a/ChangeLog b/ChangeLog index 1d5ce802a..75c7b1ca6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-11-16 Alexandre Duret-Lutz + + * 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. + 2004-11-15 Alexandre Duret-Lutz * src/tgbatest/ltl2tgba.cc (main): For non-generalized emptiness diff --git a/src/evtgba/product.cc b/src/evtgba/product.cc index 1f16f06c1..139d090bd 100644 --- a/src/evtgba/product.cc +++ b/src/evtgba/product.cc @@ -20,6 +20,7 @@ // 02111-1307, USA. #include "product.hh" +#include "misc/hashfunc.hh" #include "misc/modgray.hh" #include #include @@ -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; } diff --git a/src/misc/Makefile.am b/src/misc/Makefile.am index 43b87fdd4..901de5f2c 100644 --- a/src/misc/Makefile.am +++ b/src/misc/Makefile.am @@ -31,6 +31,7 @@ misc_HEADERS = \ escape.hh \ freelist.hh \ hash.hh \ + hashfunc.hh \ minato.hh \ modgray.hh \ random.hh \ diff --git a/src/misc/hashfunc.hh b/src/misc/hashfunc.hh new file mode 100644 index 000000000..6c315a775 --- /dev/null +++ b/src/misc/hashfunc.hh @@ -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; + } +}