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 LIBSOLV_HASH_H
14 #define LIBSOLV_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)
55 strhash_cont(const char *str, Hashval r)
58 while ((c = *(const unsigned char *)str++) != 0)
68 relhash(Id name, Id evr, int flags)
70 return name + 7 * evr + 13 * flags;
74 /* compute bitmask for value
75 * returns smallest (2^n-1) > 2 * num
77 * used for Hashtable 'modulo' operation
79 static inline Hashmask
80 mkmask(unsigned int num)
83 while (num & (num - 1))
88 #endif /* LIBSOLV_HASH_H */