#!/bin/sh [ $1 = pre ] && touch src/Basic/Types/standard_hashes.hh exit 0 cleanup pointer hashing Rewrite the hash(pointer) function to work properly (and compile without warning) on systems where void* and int are not the same size. *** TeXmacs-1.0.0.22-src/src/Basic/Types/hashmap.hh --- TeXmacs-1.0.0.22-src/src/Basic/Types/hashmap.hh *************** extern inline int N (hashmap<T,U> h) { r *** 93,108 **** /* should be in data.gen.h */ extern hashmap<string,int> CONSTRUCTOR_CODE; - #ifndef STANDARD_HASHES - #define STANDARD_HASHES - inline int hash (int i) { return i; } - inline int hash (pointer ptr) { return (int) ptr; } - #endif - // FIXME: used to let hashmap::join compile // should be replaced by a more generic copy() solution inline int copy(const int& x) { return x; } #include "hashmap.cc" #include "hashmap_extra.cc" --- 93,103 ---- /* should be in data.gen.h */ extern hashmap<string,int> CONSTRUCTOR_CODE; // FIXME: used to let hashmap::join compile // should be replaced by a more generic copy() solution inline int copy(const int& x) { return x; } + #include "standard_hashes.hh" #include "hashmap.cc" #include "hashmap_extra.cc" *** TeXmacs-1.0.0.22-src/src/Basic/Types/hashset.hh --- TeXmacs-1.0.0.22-src/src/Basic/Types/hashset.hh *************** template<class T> bool operator == (hash *** 57,68 **** template<class T> bool operator <= (hashset<T> h1, hashset<T> h2); template<class T> bool operator < (hashset<T> h1, hashset<T> h2); ! #ifndef STANDARD_HASHES ! #define STANDARD_HASHES ! inline int hash (int i) { return i; } ! inline int hash (pointer ptr) { return (int) ptr; } ! #endif ! #include "hashset.cc" #endif // defined HASHSET_H --- 57,63 ---- template<class T> bool operator <= (hashset<T> h1, hashset<T> h2); template<class T> bool operator < (hashset<T> h1, hashset<T> h2); ! #include "standard_hashes.hh" #include "hashset.cc" #endif // defined HASHSET_H *** TeXmacs-1.0.0.22-src/src/Basic/Types/standard_hashes.hh --- TeXmacs-1.0.0.22-src/src/Basic/Types/standard_hashes.hh *************** *** 0 **** --- 1,32 ---- + + /****************************************************************************** + * MODULE : standard_hashes.hh + * DESCRIPTION: basic hash functions + * COPYRIGHT : (C) 2002 David Allouche + ******************************************************************************* + * This software falls under the GNU general public license and comes WITHOUT + * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details. + * If you don't have this file, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + ******************************************************************************/ + + #ifndef STANDARD_HASHES_H + #define STANDARD_HASHES_H + + inline int hash (int i) { return i; } + + inline int + hash (pointer ptr) { + // This algorithm degenerates gracefully when sizeof(pointer)==sizeof(int) + const int n= sizeof(pointer) / sizeof(int) + + + (0 != sizeof(pointer) izeof(int) ? 1 : 0); + union { int i[n]; pointer p; } u; + if (0 != sizeof(pointer) izeof(int)) u.i[n-1]= 0; + u.p= ptr; + int h= hash(u.i[0]); + for (int j=1; j<n; j++) + h= hash(u.i[j] ^ ((h<<7) + (h>>25))); + return h; + } + + #endif // defined STANDARD_HASHES_H