CELIX-348: Improved string hash.

Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/13f34df4
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/13f34df4
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/13f34df4

Branch: refs/heads/release/celix-2.0.0
Commit: 13f34df4648ab63e9c5a01afee1a99de06cf467e
Parents: 88a7da2
Author: Pepijn Noltes <[email protected]>
Authored: Wed Feb 10 08:43:50 2016 +0100
Committer: Pepijn Noltes <[email protected]>
Committed: Wed Feb 10 08:43:50 2016 +0100

----------------------------------------------------------------------
 framework/private/src/utils.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/13f34df4/framework/private/src/utils.c
----------------------------------------------------------------------
diff --git a/framework/private/src/utils.c b/framework/private/src/utils.c
index f8e5d1f..a072623 100644
--- a/framework/private/src/utils.c
+++ b/framework/private/src/utils.c
@@ -29,18 +29,14 @@
 #include "utils.h"
 
 unsigned int utils_stringHash(void * string) {
-       char * str = (char *) string;
+    unsigned int hash = 5381;
+    unsigned int i = 0;
+    unsigned int len = strlen(string);
 
-       unsigned int hash = 1315423911;
-       unsigned int i    = 0;
-       unsigned int len = strlen(str);
+    for(i=0; i < len; i++)
+    { hash = (hash << 5) + (*string) + hash; }
 
-       for(i = 0; i < len; str++, i++)
-       {
-         hash ^= ((hash << 5) + (*str) + (hash >> 2));
-       }
-
-       return hash;
+    return hash;
 }
 
 int utils_stringEquals(void * string, void * toCompare) {
@@ -134,4 +130,4 @@ FRAMEWORK_EXPORT int utils_compareServiceIdsAndRanking(long 
servId, long servRan
        }
 
        return result;
-}
\ No newline at end of file
+}

Reply via email to