diff options
author | Dan McGee <dpmcgee@gmail.com> | 2009-03-28 17:13:54 -0500 |
---|---|---|
committer | Dan McGee <dpmcgee@gmail.com> | 2009-03-28 17:13:54 -0500 |
commit | c12cefe26b9d500a9ba3422f723865b97bb80ed3 (patch) | |
tree | c55a80ae2b5fa18331fea05f77ac1e7870b9e3be /util.c | |
parent | b0ca4ecf7a8c0fb10ce0d3c035c91638fbc6046c (diff) | |
download | onkyocontrol-c12cefe26b9d500a9ba3422f723865b97bb80ed3.tar.gz onkyocontrol-c12cefe26b9d500a9ba3422f723865b97bb80ed3.zip |
Move sdbm hashing function into util file
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -51,6 +51,22 @@ ssize_t xwrite(int fd, const void *buf, size_t len) } } +/** + * 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 hash_sdbm(const char *str) +{ + unsigned long hash = 0; + int c; + while((c = *str++)) + hash = c + (hash << 6) + (hash << 16) - hash; + + return(hash); +} + /* if using ISO C, strdup() is not actually defined, provide our own */ #ifndef strdup char *strdup(const char *s) |