From 8298740dd9a56859459b0e191b675c43fb95ea81 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Mon, 20 Feb 2012 18:08:23 +0100 Subject: [PATCH] move sdbm implementation in one file. --- ChangeLog | 8 ++++++-- include/hash.h | 8 ++++++++ src/Makefile.am | 2 +- src/hash.c | 30 ++++++++++++++++++++++++++++++ src/http/header.c | 29 +---------------------------- src/http/header/add.c | 16 +--------------- src/http/header/get.c | 16 +--------------- src/http/worker/process.c | 2 +- 8 files changed, 49 insertions(+), 62 deletions(-) create mode 100644 include/hash.h create mode 100644 src/hash.c diff --git a/ChangeLog b/ChangeLog index 9a79ba3..7b9672d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,14 @@ +2012-02-20 18:08:23 +0100 Georg Hopp + + * move sdbm implementation in one file. (HEAD, master) + 2012-02-20 17:16:44 +0100 Georg Hopp - * changed /**/ single line comments to // (HEAD, master) + * changed /**/ single line comments to // (origin/master, origin/HEAD) 2012-02-20 14:55:46 +0100 Georg Hopp - * start documenting this whole stuff...well at least add a copyright information in each file (origin/master, origin/HEAD) + * start documenting this whole stuff...well at least add a copyright information in each file 2012-02-20 10:10:29 +0100 Georg Hopp diff --git a/include/hash.h b/include/hash.h new file mode 100644 index 0000000..6ee4af2 --- /dev/null +++ b/include/hash.h @@ -0,0 +1,8 @@ +#ifndef __HASH_H__ +#define __HASH_H__ + +unsigned long sdbm(const unsigned char *); + +#endif // __HASH_H__ + +// vim: set ts=4 sw=4: diff --git a/src/Makefile.am b/src/Makefile.am index af1873c..846ef43 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,6 +40,6 @@ bin_PROGRAMS = testserver testserver_SOURCES = testserver.c \ $(IFACE) $(CLASS) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \ $(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \ - signalHandling.c daemonize.c + signalHandling.c daemonize.c hash.c testserver_CFLAGS = -Wall -I ../include/ testserver_LDFLAGS = -lrt diff --git a/src/hash.c b/src/hash.c new file mode 100644 index 0000000..0a35a7c --- /dev/null +++ b/src/hash.c @@ -0,0 +1,30 @@ +#include + +#include "hash.h" + +/** + * SDBM hashing algorithm: + * + * this algorithm was created for sdbm (a public-domain reimplementation of + * ndbm) database library. it was found to do well in scrambling bits, + * causing better distribution of the keys and fewer splits. it also happens + * to be a good general hashing function with good distribution. the actual + * function is hash(i) = hash(i - 1) * 65599 + str[i]; what is included below + * is the faster version used in gawk. [there is even a faster, duff-device + * version] the magic constant 65599 was picked out of thin air while + * experimenting with different constants, and turns out to be a prime. this + * is one of the algorithms used in berkeley db (see sleepycat) and elsewhere. + */ +unsigned long +sdbm(const unsigned char * str) +{ + unsigned long hash = 0; + int c; + + while ((c = tolower(*str++))) + hash = c + (hash << 6) + (hash << 16) - hash; + + return hash; +} + +// vim: set ts=4 sw=4: diff --git a/src/http/header.c b/src/http/header.c index b88756e..5ae3f5e 100644 --- a/src/http/header.c +++ b/src/http/header.c @@ -23,40 +23,13 @@ #include #include -#include +#include "hash.h" #include "class.h" #include "interface/class.h" #include "http/header.h" -/** - * SDBM hashing algorithm: - * - * this algorithm was created for sdbm (a public-domain reimplementation of - * ndbm) database library. it was found to do well in scrambling bits, - * causing better distribution of the keys and fewer splits. it also happens - * to be a good general hashing function with good distribution. the actual - * function is hash(i) = hash(i - 1) * 65599 + str[i]; what is included below - * is the faster version used in gawk. [there is even a faster, duff-device - * version] the magic constant 65599 was picked out of thin air while - * experimenting with different constants, and turns out to be a prime. this - * is one of the algorithms used in berkeley db (see sleepycat) and elsewhere. - */ -static -inline -unsigned long -sdbm(unsigned char * str) -{ - unsigned long hash = 0; - int c; - - while ((c = tolower(*str++))) - hash = c + (hash << 6) + (hash << 16) - hash; - - return hash; -} - static void ctor(void * _this, va_list * params) { diff --git a/src/http/header/add.c b/src/http/header/add.c index 4240a5d..d995ba9 100644 --- a/src/http/header/add.c +++ b/src/http/header/add.c @@ -22,27 +22,13 @@ #include #include -#include #include +#include "hash.h" #include "class.h" #include "interface/class.h" #include "http/header.h" -static -inline -unsigned long -sdbm(const unsigned char * str) -{ - unsigned long hash = 0; - int c; - - while ((c = tolower(*str++))) - hash = c + (hash << 6) + (hash << 16) - hash; - - return hash; -} - static inline int diff --git a/src/http/header/get.c b/src/http/header/get.c index 1be7541..3ef57b1 100644 --- a/src/http/header/get.c +++ b/src/http/header/get.c @@ -24,24 +24,10 @@ #include #include -#include +#include "hash.h" #include "http/header.h" -static -inline -unsigned long -sdbm(const unsigned char * str) -{ - unsigned long hash = 0; - int c; - - while ((c = tolower(*str++))) - hash = c + (hash << 6) + (hash << 16) - hash; - - return hash; -} - static inline int diff --git a/src/http/worker/process.c b/src/http/worker/process.c index 1d66cfc..bfaae83 100644 --- a/src/http/worker/process.c +++ b/src/http/worker/process.c @@ -65,7 +65,7 @@ httpWorkerProcess(HttpWorker this, int fd) if (NULL != httpHeaderGet( &(((HttpMessage)request)->header), "If-None-Match")) { - response = httpResponse304(handle, "image/jpeg"); + response = (HttpMessage)httpResponse304(handle, "image/jpeg"); } else { response = (HttpMessage)httpResponseImage(handle);