diff --git a/rpmio/rpmstrpool.c b/rpmio/rpmstrpool.c index 0d832f28e..589f06d92 100644 --- a/rpmio/rpmstrpool.c +++ b/rpmio/rpmstrpool.c @@ -61,6 +61,33 @@ static inline unsigned int rstrlenhash(const char * str, size_t * len) return hash; } +static inline unsigned int rstrnlenhash(const char * str, size_t n, size_t * len) +{ + /* Jenkins One-at-a-time hash */ + unsigned int hash = 0xe4721b68; + const char * s = str; + + while (*s != '\0' && n-- > 0) { + hash += *s; + hash += (hash << 10); + hash ^= (hash >> 6); + s++; + } + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + + if (len) + *len = (s - str); + + return hash; +} + +static inline unsigned int rstrnhash(const char * string, size_t n) +{ + return rstrnlenhash(string, n, NULL); +} + unsigned int rstrhash(const char * string) { return rstrlenhash(string, NULL);