From: Francois Fleuret <francois@fleuret.org>
Date: Tue, 17 Mar 2009 06:59:18 +0000 (+0100)
Subject: Changed the hash formula. If I was not that lazy I would look at a
X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=919a7e0c12d771d722d87cbc00d991e406f30a30;p=selector.git

Changed the hash formula. If I was not that lazy I would look at a
standard string hashing technique instead of making my own.
---

diff --git a/selector.cc b/selector.cc
index c6cf64c..e9b4f64 100644
--- a/selector.cc
+++ b/selector.cc
@@ -104,8 +104,11 @@ int test_and_add(char *new_string, int new_index,
                  char **strings, int *hash_table, int hash_table_size) {
   unsigned int code = 0;
 
+  // This is my recipe. I checked, it seems to work (as long as
+  // hash_table_size is not a multiple of 387433 that should be okay)
+
   for(int k = 0; new_string[k]; k++) {
-    code += int(new_string[k]) << (8 * k%4);
+    code = code * 387433 + (unsigned int) (new_string[k]);
   }
 
   code = code % hash_table_size;
@@ -469,7 +472,7 @@ int main(int argc, char **argv) {
     }
 
     else {
-      cerr << "Selector version " << VERSION
+      cerr << "Selector version " << VERSION << "-R" << REVISION_NUMBER
            << endl
            << "Written by Francois Fleuret <francois@fleuret.org>"
            << endl