spot
0.9.1
|
00001 // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), 00002 // département Systèmes Répartis Coopératifs (SRC), Université Pierre 00003 // et Marie Curie. 00004 // 00005 // This file is part of Spot, a model checking library. 00006 // 00007 // Spot is free software; you can redistribute it and/or modify it 00008 // under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 2 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // Spot is distributed in the hope that it will be useful, but WITHOUT 00013 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00014 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 00015 // License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with Spot; see the file COPYING. If not, write to the Free 00019 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00020 // 02111-1307, USA. 00021 00022 #ifndef SPOT_MISC_HASHFUNC_HH 00023 # define SPOT_MISC_HASHFUNC_HH 00024 # include <cstddef> 00025 00026 namespace spot 00027 { 00031 00036 inline size_t 00037 wang32_hash(size_t key) 00038 { 00039 // We assume that size_t has at least 32bits. 00040 key += ~(key << 15); 00041 key ^= (key >> 10); 00042 key += (key << 3); 00043 key ^= (key >> 6); 00044 key += ~(key << 11); 00045 key ^= (key >> 16); 00046 return key; 00047 } 00048 00055 inline size_t 00056 knuth32_hash(size_t key) 00057 { 00058 // 2654435761 is the golden ratio of 2^32. The right shift of 3 00059 // bits assumes that all objects are aligned on a 8 byte boundary. 00060 return (key >> 3) * 2654435761U; 00061 } 00063 } 00064 00065 #endif // SPOT_MISC_HASHFUNC_HH