From 919a7e0c12d771d722d87cbc00d991e406f30a30 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Tue, 17 Mar 2009 07:59:18 +0100 Subject: [PATCH] Changed the hash formula. If I was not that lazy I would look at a standard string hashing technique instead of making my own. --- selector.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 " << endl -- 2.39.5