Commit 8298740dd9a56859459b0e191b675c43fb95ea81
1 parent
063189e6
move sdbm implementation in one file.
Showing
8 changed files
with
49 additions
and
62 deletions
| 1 | +2012-02-20 18:08:23 +0100 Georg Hopp | |
| 2 | + | |
| 3 | + * move sdbm implementation in one file. (HEAD, master) | |
| 4 | + | |
| 1 | 5 | 2012-02-20 17:16:44 +0100 Georg Hopp |
| 2 | 6 | |
| 3 | - * changed /**/ single line comments to // (HEAD, master) | |
| 7 | + * changed /**/ single line comments to // (origin/master, origin/HEAD) | |
| 4 | 8 | |
| 5 | 9 | 2012-02-20 14:55:46 +0100 Georg Hopp |
| 6 | 10 | |
| 7 | - * start documenting this whole stuff...well at least add a copyright information in each file (origin/master, origin/HEAD) | |
| 11 | + * start documenting this whole stuff...well at least add a copyright information in each file | |
| 8 | 12 | |
| 9 | 13 | 2012-02-20 10:10:29 +0100 Georg Hopp |
| 10 | 14 | ... | ... |
include/hash.h
0 → 100644
| ... | ... | @@ -40,6 +40,6 @@ bin_PROGRAMS = testserver |
| 40 | 40 | testserver_SOURCES = testserver.c \ |
| 41 | 41 | $(IFACE) $(CLASS) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \ |
| 42 | 42 | $(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \ |
| 43 | - signalHandling.c daemonize.c | |
| 43 | + signalHandling.c daemonize.c hash.c | |
| 44 | 44 | testserver_CFLAGS = -Wall -I ../include/ |
| 45 | 45 | testserver_LDFLAGS = -lrt | ... | ... |
src/hash.c
0 → 100644
| 1 | +#include <ctype.h> | |
| 2 | + | |
| 3 | +#include "hash.h" | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * SDBM hashing algorithm: | |
| 7 | + * | |
| 8 | + * this algorithm was created for sdbm (a public-domain reimplementation of | |
| 9 | + * ndbm) database library. it was found to do well in scrambling bits, | |
| 10 | + * causing better distribution of the keys and fewer splits. it also happens | |
| 11 | + * to be a good general hashing function with good distribution. the actual | |
| 12 | + * function is hash(i) = hash(i - 1) * 65599 + str[i]; what is included below | |
| 13 | + * is the faster version used in gawk. [there is even a faster, duff-device | |
| 14 | + * version] the magic constant 65599 was picked out of thin air while | |
| 15 | + * experimenting with different constants, and turns out to be a prime. this | |
| 16 | + * is one of the algorithms used in berkeley db (see sleepycat) and elsewhere. | |
| 17 | + */ | |
| 18 | +unsigned long | |
| 19 | +sdbm(const unsigned char * str) | |
| 20 | +{ | |
| 21 | + unsigned long hash = 0; | |
| 22 | + int c; | |
| 23 | + | |
| 24 | + while ((c = tolower(*str++))) | |
| 25 | + hash = c + (hash << 6) + (hash << 16) - hash; | |
| 26 | + | |
| 27 | + return hash; | |
| 28 | +} | |
| 29 | + | |
| 30 | +// vim: set ts=4 sw=4: | ... | ... |
| ... | ... | @@ -23,40 +23,13 @@ |
| 23 | 23 | |
| 24 | 24 | #include <stdlib.h> |
| 25 | 25 | #include <string.h> |
| 26 | -#include <ctype.h> | |
| 27 | 26 | |
| 27 | +#include "hash.h" | |
| 28 | 28 | #include "class.h" |
| 29 | 29 | #include "interface/class.h" |
| 30 | 30 | |
| 31 | 31 | #include "http/header.h" |
| 32 | 32 | |
| 33 | -/** | |
| 34 | - * SDBM hashing algorithm: | |
| 35 | - * | |
| 36 | - * this algorithm was created for sdbm (a public-domain reimplementation of | |
| 37 | - * ndbm) database library. it was found to do well in scrambling bits, | |
| 38 | - * causing better distribution of the keys and fewer splits. it also happens | |
| 39 | - * to be a good general hashing function with good distribution. the actual | |
| 40 | - * function is hash(i) = hash(i - 1) * 65599 + str[i]; what is included below | |
| 41 | - * is the faster version used in gawk. [there is even a faster, duff-device | |
| 42 | - * version] the magic constant 65599 was picked out of thin air while | |
| 43 | - * experimenting with different constants, and turns out to be a prime. this | |
| 44 | - * is one of the algorithms used in berkeley db (see sleepycat) and elsewhere. | |
| 45 | - */ | |
| 46 | -static | |
| 47 | -inline | |
| 48 | -unsigned long | |
| 49 | -sdbm(unsigned char * str) | |
| 50 | -{ | |
| 51 | - unsigned long hash = 0; | |
| 52 | - int c; | |
| 53 | - | |
| 54 | - while ((c = tolower(*str++))) | |
| 55 | - hash = c + (hash << 6) + (hash << 16) - hash; | |
| 56 | - | |
| 57 | - return hash; | |
| 58 | -} | |
| 59 | - | |
| 60 | 33 | static |
| 61 | 34 | void |
| 62 | 35 | ctor(void * _this, va_list * params) { | ... | ... |
| ... | ... | @@ -22,29 +22,15 @@ |
| 22 | 22 | |
| 23 | 23 | #include <search.h> |
| 24 | 24 | #include <stdlib.h> |
| 25 | -#include <ctype.h> | |
| 26 | 25 | #include <stdio.h> |
| 27 | 26 | |
| 27 | +#include "hash.h" | |
| 28 | 28 | #include "class.h" |
| 29 | 29 | #include "interface/class.h" |
| 30 | 30 | #include "http/header.h" |
| 31 | 31 | |
| 32 | 32 | static |
| 33 | 33 | inline |
| 34 | -unsigned long | |
| 35 | -sdbm(const unsigned char * str) | |
| 36 | -{ | |
| 37 | - unsigned long hash = 0; | |
| 38 | - int c; | |
| 39 | - | |
| 40 | - while ((c = tolower(*str++))) | |
| 41 | - hash = c + (hash << 6) + (hash << 16) - hash; | |
| 42 | - | |
| 43 | - return hash; | |
| 44 | -} | |
| 45 | - | |
| 46 | -static | |
| 47 | -inline | |
| 48 | 34 | int |
| 49 | 35 | comp(const void * _a, const void * _b) |
| 50 | 36 | { | ... | ... |
| ... | ... | @@ -24,26 +24,12 @@ |
| 24 | 24 | |
| 25 | 25 | #include <search.h> |
| 26 | 26 | #include <stdlib.h> |
| 27 | -#include <ctype.h> | |
| 28 | 27 | |
| 28 | +#include "hash.h" | |
| 29 | 29 | #include "http/header.h" |
| 30 | 30 | |
| 31 | 31 | static |
| 32 | 32 | inline |
| 33 | -unsigned long | |
| 34 | -sdbm(const unsigned char * str) | |
| 35 | -{ | |
| 36 | - unsigned long hash = 0; | |
| 37 | - int c; | |
| 38 | - | |
| 39 | - while ((c = tolower(*str++))) | |
| 40 | - hash = c + (hash << 6) + (hash << 16) - hash; | |
| 41 | - | |
| 42 | - return hash; | |
| 43 | -} | |
| 44 | - | |
| 45 | -static | |
| 46 | -inline | |
| 47 | 33 | int |
| 48 | 34 | comp(const void * _a, const void * _b) |
| 49 | 35 | { | ... | ... |
| ... | ... | @@ -65,7 +65,7 @@ httpWorkerProcess(HttpWorker this, int fd) |
| 65 | 65 | if (NULL != httpHeaderGet( |
| 66 | 66 | &(((HttpMessage)request)->header), |
| 67 | 67 | "If-None-Match")) { |
| 68 | - response = httpResponse304(handle, "image/jpeg"); | |
| 68 | + response = (HttpMessage)httpResponse304(handle, "image/jpeg"); | |
| 69 | 69 | } |
| 70 | 70 | else { |
| 71 | 71 | response = (HttpMessage)httpResponseImage(handle); | ... | ... |
Please
register
or
login
to post a comment