From 58c7fdbb05978456149eab289490b6779aa23874 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Mon, 16 Mar 2009 18:58:51 +0100 Subject: [PATCH] Cosmetics. Moved the hash-table routines. --- selector.cc | 64 ++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/selector.cc b/selector.cc index fbcd67a..668323e 100644 --- a/selector.cc +++ b/selector.cc @@ -95,6 +95,38 @@ void check_opt(int argc, char **argv, int n_opt, int n, const char *help) { } } +////////////////////////////////////////////////////////////////////// +// A quick and dirty hash table + +int *new_hash_table(int hash_table_size) { + int *result; + result = new int[hash_table_size]; + for(int k = 0; k < hash_table_size; k++) { + result[k] = -1; + } + return result; +} + +int test_and_add(char *new_string, int new_index, + char **strings, int *hash_table, int hash_table_size) { + unsigned int code = 0; + + for(int k = 0; new_string[k]; k++) { + code += int(new_string[k]) << (8 * k%4); + } + + code = code % hash_table_size; + + while(hash_table[code] >= 0) { + if(strcmp(new_string, strings[hash_table[code]]) == 0) return 1; + code = (code + 1) % hash_table_size; + } + + hash_table[code] = new_index; + + return 0; +} + ////////////////////////////////////////////////////////////////////// int previous_visible(int current_line, int nb_lines, char **lines, int nb_patterns, char **patterns) { @@ -306,38 +338,6 @@ void update_screen(int *current_line, int *temporary_line, int motion, refresh(); } -////////////////////////////////////////////////////////////////////// -// A quick and dirty hash table - -int *new_hash_table(int hash_table_size) { - int *result; - result = new int[hash_table_size]; - for(int k = 0; k < hash_table_size; k++) { - result[k] = -1; - } - return result; -} - -int test_and_add(char *new_string, int new_index, - char **strings, int *hash_table, int hash_table_size) { - unsigned int code = 0; - - for(int k = 0; new_string[k]; k++) { - code += int(new_string[k]) << (8 * k%4); - } - - code = code % hash_table_size; - - while(hash_table[code] >= 0) { - if(strcmp(new_string, strings[hash_table[code]]) == 0) return 1; - code = (code + 1) % hash_table_size; - } - - hash_table[code] = new_index; - - return 0; -} - ////////////////////////////////////////////////////////////////////// int main(int argc, char **argv) { -- 2.39.5