From f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Apr 2007 03:49:53 +0000 Subject: Ok, no code is left in src, it's all in src/old. We'll gradually move code back into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier. --- src/old/hashfunctionstring.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/old/hashfunctionstring.cpp (limited to 'src/old/hashfunctionstring.cpp') diff --git a/src/old/hashfunctionstring.cpp b/src/old/hashfunctionstring.cpp new file mode 100644 index 0000000..bd14643 --- /dev/null +++ b/src/old/hashfunctionstring.cpp @@ -0,0 +1,51 @@ +#include "hashfunctionstring.h" +#ifndef NULL +#define NULL ((void *) 0) +#endif + +HashFunctionString::HashFunctionString() +{ +} + +HashFunctionString::~HashFunctionString() +{ +} + +unsigned long int HashFunctionString::hash( const void *id ) +{ + if (id == NULL) + { + return 0; + } + + unsigned long int nPos = 0; + for( const char *s = (const char *)id; *s; s++ ) + { + nPos = *s + (nPos << 6) + (nPos << 16) - nPos; + } + return nPos; +} + +bool HashFunctionString::cmpIDs( const void *id1, const void *id2 ) +{ + if (id1 == NULL || id2 == NULL) + { + return false; + } + if (id1 == id2) + { + return true; + } + + const char *str1 = (const char *)id1; + const char *str2 = (const char *)id2; + + int j; + for( j = 0; str1[j] != '\0' && str2[j] != '\0'; j++ ) + { + if( str1[j] != str2[j] ) + return false; + } + return (str1[j]==str2[j]); +} + -- cgit v1.2.3