2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
10 * generic hash functions
13 #ifndef SATSOLVER_HASH_H
14 #define SATSOLVER_HASH_H
16 #include "pooltypes.h"
19 typedef unsigned int Hashval;
20 /* mask for hash, used as modulo operator to ensure 'wrapping' of hash
21 values -> hash table */
22 typedef unsigned int Hashmask;
24 /* inside the hash table, Ids are stored. Hash maps: string -> hash -> Id */
25 typedef Id *Hashtable;
28 #define HASHCHAIN_START 7
29 #define HASHCHAIN_NEXT(h, hh, mask) (((h) + (hh)++) & (mask))
31 /* very simple hash function
35 strhash(const char *str)
39 while ((c = *(const unsigned char *)str++) != 0)
45 strnhash(const char *str, unsigned len)
49 while (len-- && (c = *(const unsigned char *)str++) != 0)
58 relhash(Id name, Id evr, int flags)
60 return name + 7 * evr + 13 * flags;
64 /* compute bitmask for value
65 * returns smallest (2^n-1) > num
67 * used for Hashtable 'modulo' operation
69 static inline Hashmask
70 mkmask(unsigned int num)
73 while (num & (num - 1))
78 #endif /* SATSOLVER_HASH_H */