summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorDan McGee <dpmcgee@gmail.com>2009-03-28 17:13:54 -0500
committerDan McGee <dpmcgee@gmail.com>2009-03-28 17:13:54 -0500
commitc12cefe26b9d500a9ba3422f723865b97bb80ed3 (patch)
treec55a80ae2b5fa18331fea05f77ac1e7870b9e3be /util.c
parentb0ca4ecf7a8c0fb10ce0d3c035c91638fbc6046c (diff)
downloadonkyocontrol-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.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/util.c b/util.c
index dabfec9..8c7e40f 100644
--- a/util.c
+++ b/util.c
@@ -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)