}
}
+//////////////////////////////////////////////////////////////////////
+// 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) {
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) {