hash.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 #ifndef SATSOLVER_HASH_H
00014 #define SATSOLVER_HASH_H
00015 
00016 #include "pooltypes.h"
00017 
00018 
00019 typedef unsigned int Hashval;
00020 
00021 
00022 typedef unsigned int Hashmask;
00023 
00024 
00025 typedef Id *Hashtable;
00026 
00027 
00028 #define HASHCHAIN_START 7
00029 #define HASHCHAIN_NEXT(h, hh, mask) (((h) + (hh)++) & (mask))
00030 
00031 
00032 
00033 
00034 static inline Hashval
00035 strhash(const char *str)
00036 {
00037   Hashval r = 0;
00038   unsigned int c;
00039   while ((c = *(const unsigned char *)str++) != 0)
00040     r += (r << 3) + c;
00041   return r;
00042 }
00043 
00044 static inline Hashval
00045 strnhash(const char *str, unsigned len)
00046 {
00047   Hashval r = 0;
00048   unsigned int c;
00049   while (len-- && (c = *(const unsigned char *)str++) != 0)
00050     r += (r << 3) + c;
00051   return r;
00052 }
00053 
00054 static inline Hashval
00055 strhash_cont(const char *str, Hashval r)
00056 {
00057   unsigned int c;
00058   while ((c = *(const unsigned char *)str++) != 0)
00059     r += (r << 3) + c;
00060   return r;
00061 }
00062 
00063 
00064 
00065 
00066 
00067 static inline Hashval
00068 relhash(Id name, Id evr, int flags)
00069 {
00070   return name + 7 * evr + 13 * flags;
00071 }
00072 
00073 
00074 
00075 
00076 
00077 
00078  
00079 static inline Hashmask
00080 mkmask(unsigned int num)
00081 {
00082   num *= 2;
00083   while (num & (num - 1))
00084     num &= num - 1;
00085   return num * 2 - 1;
00086 }
00087 
00088 #endif