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;
25 /* inside the hash table, Ids are stored. Hash maps: string -> hash -> Id */
26 typedef Id *Hashtable;
29 #define HASHCHAIN_START 7
30 #define HASHCHAIN_NEXT(h, hh, mask) (((h) + (hh)++) & (mask))
32 /* very simple hash function
36 strhash(const char *str)
40 while ((c = *(const unsigned char *)str++) != 0)
46 strnhash(const char *str, unsigned len)
50 while (len-- && (c = *(const unsigned char *)str++) != 0)
56 strhash_cont(const char *str, Hashval r)
59 while ((c = *(const unsigned char *)str++) != 0)
69 relhash(Id name, Id evr, int flags)
71 return name + 7 * evr + 13 * flags;
75 /* compute bitmask for value
76 * returns smallest (2^n-1) > 2 * num
78 * used for Hashtable 'modulo' operation
81 mkmask(unsigned int num)
84 while (num & (num - 1))
93 #endif /* LIBSOLV_HASH_H */