X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=selector.cc;h=1518120476ebae5673f5baf953d50456a34e345c;hb=4ddeef0bd7aa9434029aa6f2167d2d858e932f26;hp=fbcd67a746733702fd7ea141dc1abf4d41eeadda;hpb=c597e11ab02854d2552c8966d376523902ad6d25;p=selector.git diff --git a/selector.cc b/selector.cc index fbcd67a..1518120 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) { @@ -403,7 +403,7 @@ int main(int argc, char **argv) { i++; } - else if(strcmp(argv[i], "-r") == 0) { + else if(strcmp(argv[i], "-d") == 0) { remove_duplicates = 1; i++; } @@ -432,7 +432,7 @@ int main(int argc, char **argv) { << " [-h]" << " [-v]" << " [-m]" - << " [-r]" + << " [-d]" << " [-z]" << " [-i]" << " [-c ]"