]> arthur.barton.de Git - ngircd-alex.git/commitdiff
- Implementation einer Hash-Funktion begonnen.
authorAlexander Barton <alex@barton.de>
Thu, 14 Mar 2002 15:31:22 +0000 (15:31 +0000)
committerAlexander Barton <alex@barton.de>
Thu, 14 Mar 2002 15:31:22 +0000 (15:31 +0000)
MacOSX/ngircd.pbproj/project.pbxproj
src/ngircd/Makefile.am
src/ngircd/hash.c [new file with mode: 0644]
src/ngircd/hash.h [new file with mode: 0644]

index 2fea6f203f762418d406b65fa889901a9b7f22fb..829e8277b9aa5c8adb857826a35fffd3bf4312d3 100644 (file)
                                F5F18138023EC63701A85B04,
                                F5F18139023EC63701A85B04,
                                F5F1813A023EC63701A85B04,
                                F5F18138023EC63701A85B04,
                                F5F18139023EC63701A85B04,
                                F5F1813A023EC63701A85B04,
+                               F55047BC0240F6E501A85B04,
                        );
                        isa = PBXHeadersBuildPhase;
                        name = Headers;
                        );
                        isa = PBXHeadersBuildPhase;
                        name = Headers;
                                F57C88880232853501A85B04,
                                F57C888C0232884501A85B04,
                                F57C889002328D7201A85B04,
                                F57C88880232853501A85B04,
                                F57C888C0232884501A85B04,
                                F57C889002328D7201A85B04,
+                               F55047BD0240F6E501A85B04,
                        );
                        isa = PBXSourcesBuildPhase;
                        name = Sources;
                        );
                        isa = PBXSourcesBuildPhase;
                        name = Sources;
                                F52162C101C7B904012300F4,
                                F51F791201DFC95301D13771,
                                F576ABFE01D61D7401A85B03,
                                F52162C101C7B904012300F4,
                                F51F791201DFC95301D13771,
                                F576ABFE01D61D7401A85B03,
+                               F55047BA0240F6E501A85B04,
+                               F55047BB0240F6E501A85B04,
                        );
                        isa = PBXGroup;
                        path = ngircd;
                        );
                        isa = PBXGroup;
                        path = ngircd;
                        path = ../doc/Makefile.am;
                        refType = 2;
                };
                        path = ../doc/Makefile.am;
                        refType = 2;
                };
+               F55047BA0240F6E501A85B04 = {
+                       isa = PBXFileReference;
+                       path = hash.c;
+                       refType = 4;
+               };
+               F55047BB0240F6E501A85B04 = {
+                       isa = PBXFileReference;
+                       path = hash.h;
+                       refType = 4;
+               };
+               F55047BC0240F6E501A85B04 = {
+                       fileRef = F55047BB0240F6E501A85B04;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               F55047BD0240F6E501A85B04 = {
+                       fileRef = F55047BA0240F6E501A85B04;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
                F56D8B9E01E0BFA00155ADA7 = {
                        children = (
                                F56D8B9F01E0BFA00155ADA7,
                F56D8B9E01E0BFA00155ADA7 = {
                        children = (
                                F56D8B9F01E0BFA00155ADA7,
index 23627272802d97325071e8531753f18ab4c82cb3..2e2b8dc61569f04f2a764a4b668386eb2cd0dcfd 100644 (file)
@@ -9,18 +9,18 @@
 # Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
 # der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
 #
 # Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
 # der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
 #
-# $Id: Makefile.am,v 1.16 2002/03/12 14:37:51 alex Exp $
+# $Id: Makefile.am,v 1.17 2002/03/14 15:31:22 alex Exp $
 #
 
 AM_CFLAGS = -I$(srcdir)/../portab
 
 sbin_PROGRAMS = ngircd
 
 #
 
 AM_CFLAGS = -I$(srcdir)/../portab
 
 sbin_PROGRAMS = ngircd
 
-ngircd_SOURCES = ngircd.c channel.c client.c conf.c conn.c irc.c \
+ngircd_SOURCES = ngircd.c channel.c client.c conf.c conn.c hash.c irc.c \
        irc-channel.c irc-login.c irc-mode.c irc-oper.c irc-server.c \
        irc-write.c log.c parse.c tool.c
 
        irc-channel.c irc-login.c irc-mode.c irc-oper.c irc-server.c \
        irc-write.c log.c parse.c tool.c
 
-noinst_HEADERS = ngircd.h channel.h client.h conf.h conn.h irc.h \
+noinst_HEADERS = ngircd.h channel.h client.h conf.h conn.h hash.h irc.h \
        irc-channel.h irc-login.h irc-mode.h irc-oper.h irc-server.h \
        irc-write.h log.h parse.h tool.h \
        messages.h defines.h
        irc-channel.h irc-login.h irc-mode.h irc-oper.h irc-server.h \
        irc-write.h log.h parse.h tool.h \
        messages.h defines.h
diff --git a/src/ngircd/hash.c b/src/ngircd/hash.c
new file mode 100644 (file)
index 0000000..511dba1
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * ngIRCd -- The Next Generation IRC Daemon
+ * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ *
+ * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
+ * der GNU General Public License (GPL), wie von der Free Software Foundation
+ * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
+ * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
+ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
+ * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
+ *
+ * $Id: hash.c,v 1.1 2002/03/14 15:31:22 alex Exp $
+ *
+ * hash.c: Hash-Werte berechnen
+ */
+
+
+#include "portab.h"
+
+#include "imp.h"
+#include <assert.h>
+
+#include "exp.h"
+#include "hash.h"
+
+
+/*
+ * Die hier verwendete Hash-Funktion stammt aus lookup2.c von Bob Jenkins
+ * (URL: <http://burtleburtle.net/bob/c/lookup2.c>). Aus dem Header:
+ * --------------------------------------------------------------------
+ * lookup2.c, by Bob Jenkins, December 1996, Public Domain.
+ * hash(), hash2(), hash3, and mix() are externally useful functions.
+ * Routines to test the hash are included if SELF_TEST is defined.
+ * You can use this free for any purpose.  It has no warranty.
+ * --------------------------------------------------------------------
+ * nicht alle seiner Funktionen werden hier genutzt.
+ */
+
+
+typedef unsigned long int ub4;
+typedef unsigned char ub1;
+
+
+#define hashsize(n) ((ub4)1<<(n))
+#define hashmask(n) (hashsize(n)-1)
+
+#define mix(a,b,c) \
+{ \
+       a -= b; a -= c; a ^= (c>>13); \
+       b -= c; b -= a; b ^= (a<<8);  \
+       c -= a; c -= b; c ^= (b>>13); \
+       a -= b; a -= c; a ^= (c>>12); \
+       b -= c; b -= a; b ^= (a<<16); \
+       c -= a; c -= b; c ^= (b>>5);  \
+       a -= b; a -= c; a ^= (c>>3);  \
+       b -= c; b -= a; b ^= (a<<10); \
+       c -= a; c -= b; c ^= (b>>15); \
+}
+
+
+ub4 hash( register ub1 *k, register ub4 length, register ub4 initval)
+{
+       /* k: the key
+        * length: length of the key
+        * initval: the previous hash, or an arbitrary value
+        */
+
+       register ub4 a,b,c,len;
+
+       /* Set up the internal state */
+       len = length;
+       a = b = 0x9e3779b9;     /* the golden ratio; an arbitrary value */
+       c = initval;            /* the previous hash value */
+
+       /* handle most of the key */
+       while (len >= 12)
+       {
+               a += (k[0] +((ub4)k[1]<<8) +((ub4)k[2]<<16) +((ub4)k[3]<<24));
+               b += (k[4] +((ub4)k[5]<<8) +((ub4)k[6]<<16) +((ub4)k[7]<<24));
+               c += (k[8] +((ub4)k[9]<<8) +((ub4)k[10]<<16)+((ub4)k[11]<<24));
+               mix(a,b,c);
+               k += 12; len -= 12;
+       }
+
+       /* handle the last 11 bytes */
+       c += length;
+       switch(len)             /* all the case statements fall through */
+       {
+               case 11: c+=((ub4)k[10]<<24);
+               case 10: c+=((ub4)k[9]<<16);
+               case 9 : c+=((ub4)k[8]<<8);
+               /* the first byte of c is reserved for the length */
+               case 8 : b+=((ub4)k[7]<<24);
+               case 7 : b+=((ub4)k[6]<<16);
+               case 6 : b+=((ub4)k[5]<<8);
+               case 5 : b+=k[4];
+               case 4 : a+=((ub4)k[3]<<24);
+               case 3 : a+=((ub4)k[2]<<16);
+               case 2 : a+=((ub4)k[1]<<8);
+               case 1 : a+=k[0];
+               /* case 0: nothing left to add */
+       }
+       mix(a,b,c);
+
+       /* report the result */
+       return c;
+} /* hash */
+
+
+/* -eof- */
diff --git a/src/ngircd/hash.h b/src/ngircd/hash.h
new file mode 100644 (file)
index 0000000..80caed8
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * ngIRCd -- The Next Generation IRC Daemon
+ * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ *
+ * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
+ * der GNU General Public License (GPL), wie von der Free Software Foundation
+ * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
+ * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
+ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
+ * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
+ *
+ * $Id: hash.h,v 1.1 2002/03/14 15:31:22 alex Exp $
+ *
+ * hash.h: Hash-Werte berechnen (Header)
+ */
+
+
+#ifndef __hash_h__
+#define __hash_h__
+
+
+#endif
+
+
+/* -eof- */