diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2013-10-14 22:25:08 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2013-10-14 22:25:51 +0200 |
commit | 06973479a97d3c99f7a3ce284cb8974bacb6fd3f (patch) | |
tree | 6a81130cb6590ee09f776d5f8d55e931491decc6 /common | |
parent | 61e96bf393f0e3f39125f9e1a5f73cfefdf719df (diff) |
Use djb2 hash in dict module
This slightly modifies the string hashing function to use the djb2 hash.
This hash is supposed to be reasonably fast and have reasonably few
collisions.
Diffstat (limited to 'common')
-rw-r--r-- | common/dict.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/common/dict.c b/common/dict.c index 03e9a7b..d4cfd8e 100644 --- a/common/dict.c +++ b/common/dict.c @@ -2,7 +2,7 @@ dict.c - dictionary functions This file is part of the nss-pam-ldapd library. - Copyright (C) 2007, 2008, 2009, 2010, 2012 Arthur de Jong + Copyright (C) 2007, 2008, 2009, 2010, 2012, 2013 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -72,9 +72,10 @@ struct dictionary { /* Simple hash function that computes the hash value of a string. */ static uint32_t stringhash(const char *str) { - uint32_t hash = 0; - while (*str != '\0') - hash = 3 * hash + *str++; + uint32_t hash = 5381; + uint32_t c; + while ((c = *str++) != '\0') + hash = 33 * hash + c; return hash; } |