diff options
author | Dan McGee <dan@archlinux.org> | 2010-12-14 11:56:32 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-12-14 11:56:32 -0600 |
commit | dbf59a6b141213b0afc962c71347eb83f8bcab73 (patch) | |
tree | 924f24750b5c6a9abd32ce349b111714b02748da /lib/libalpm/util.c | |
parent | d1d163c5a3627675e4d063d196ea2b2255507cc8 (diff) | |
download | pacman-dbf59a6b141213b0afc962c71347eb83f8bcab73.tar.xz |
Add hash_sdbm function
This is prepping for the addition of a hash field to each package to greatly
speed up the string comparisons we frequently do on package name in
_alpm_pkg_find.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r-- | lib/libalpm/util.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index e425fa48..8e83bdac 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -845,4 +845,25 @@ int _alpm_splitname(const char *target, pmpkg_t *pkg) return(0); } +/** + * Hash the given string to an unsigned long value. + * This is the standard sdbm hashing algorithm. + * @param str string to hash + * @return the hash value of the given string + */ +unsigned long _alpm_hash_sdbm(const char *str) +{ + unsigned long hash = 0; + int c; + + if(!str) { + return(hash); + } + while((c = *str++)) { + hash = c + (hash << 6) + (hash << 16) - hash; + } + + return(hash); +} + /* vim: set ts=2 sw=2 noet: */ |