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"
23 typedef unsigned int Hashval;
24 /* mask for hash, used as modulo operator to ensure 'wrapping' of hash
25 values -> hash table */
26 typedef unsigned int Hashmask;
28 /* inside the hash table, Ids are stored. Hash maps: string -> hash -> Id */
29 typedef Id *Hashtable;
32 #define HASHCHAIN_START 7
33 #define HASHCHAIN_NEXT(h, hh, mask) (((h) + (hh)++) & (mask))
35 /* very simple hash function
39 strhash(const char *str)
43 while ((c = *(const unsigned char *)str++) != 0)
49 strnhash(const char *str, unsigned len)
53 while (len-- && (c = *(const unsigned char *)str++) != 0)
59 strhash_cont(const char *str, Hashval r)
62 while ((c = *(const unsigned char *)str++) != 0)
72 relhash(Id name, Id evr, int flags)
74 return name + 7 * evr + 13 * flags;
78 /* compute bitmask for value
79 * returns smallest (2^n-1) > 2 * num
81 * used for Hashtable 'modulo' operation
83 static inline Hashmask
84 mkmask(unsigned int num)
87 while (num & (num - 1))
96 #endif /* LIBSOLV_HASH_H */