Browse Source

move sdbm implementation in one file.

master
Georg Hopp 14 years ago
parent
commit
8298740dd9
  1. 8
      ChangeLog
  2. 8
      include/hash.h
  3. 2
      src/Makefile.am
  4. 30
      src/hash.c
  5. 29
      src/http/header.c
  6. 16
      src/http/header/add.c
  7. 16
      src/http/header/get.c
  8. 2
      src/http/worker/process.c

8
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 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 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 2012-02-20 10:10:29 +0100 Georg Hopp

8
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:

2
src/Makefile.am

@ -40,6 +40,6 @@ bin_PROGRAMS = testserver
testserver_SOURCES = testserver.c \ testserver_SOURCES = testserver.c \
$(IFACE) $(CLASS) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \ $(IFACE) $(CLASS) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \
$(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \ $(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \
signalHandling.c daemonize.c
signalHandling.c daemonize.c hash.c
testserver_CFLAGS = -Wall -I ../include/ testserver_CFLAGS = -Wall -I ../include/
testserver_LDFLAGS = -lrt testserver_LDFLAGS = -lrt

30
src/hash.c

@ -0,0 +1,30 @@
#include <ctype.h>
#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:

29
src/http/header.c

@ -23,40 +23,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include "hash.h"
#include "class.h" #include "class.h"
#include "interface/class.h" #include "interface/class.h"
#include "http/header.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 static
void void
ctor(void * _this, va_list * params) { ctor(void * _this, va_list * params) {

16
src/http/header/add.c

@ -22,27 +22,13 @@
#include <search.h> #include <search.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include "hash.h"
#include "class.h" #include "class.h"
#include "interface/class.h" #include "interface/class.h"
#include "http/header.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 static
inline inline
int int

16
src/http/header/get.c

@ -24,24 +24,10 @@
#include <search.h> #include <search.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h>
#include "hash.h"
#include "http/header.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 static
inline inline
int int

2
src/http/worker/process.c

@ -65,7 +65,7 @@ httpWorkerProcess(HttpWorker this, int fd)
if (NULL != httpHeaderGet( if (NULL != httpHeaderGet(
&(((HttpMessage)request)->header), &(((HttpMessage)request)->header),
"If-None-Match")) { "If-None-Match")) {
response = httpResponse304(handle, "image/jpeg");
response = (HttpMessage)httpResponse304(handle, "image/jpeg");
} }
else { else {
response = (HttpMessage)httpResponseImage(handle); response = (HttpMessage)httpResponseImage(handle);

Loading…
Cancel
Save