projects
/
selector.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c06d16d
)
Added a detection of full hash table.
author
Francois Fleuret
<francois@fleuret.org>
Mon, 13 Sep 2010 08:20:48 +0000
(10:20 +0200)
committer
Francois Fleuret
<francois@fleuret.org>
Mon, 13 Sep 2010 08:20:48 +0000
(10:20 +0200)
selector.c
patch
|
blob
|
history
diff --git
a/selector.c
b/selector.c
index
edff2be
..
b849e65
100644
(file)
--- a/
selector.c
+++ b/
selector.c
@@
-252,7
+252,7
@@
int add_and_get_previous_index(struct hash_table_t *hash_table,
const char *new_string, int new_index,
char **strings) {
const char *new_string, int new_index,
char **strings) {
- unsigned int code = 0;
+ unsigned int code = 0
, start
;
int k;
/* This is my recipe. I checked, it seems to work (as long as
int k;
/* This is my recipe. I checked, it seems to work (as long as
@@
-264,6
+264,7
@@
int add_and_get_previous_index(struct hash_table_t *hash_table,
}
code = code % hash_table->size;
}
code = code % hash_table->size;
+ start = code;
while(hash_table->entries[code] >= 0) {
/* There is a string with that code */
while(hash_table->entries[code] >= 0) {
/* There is a string with that code */
@@
-278,6
+279,12
@@
int add_and_get_previous_index(struct hash_table_t *hash_table,
/* This collision was not the same string, let's move to the next
in the table */
code = (code + 1) % hash_table->size;
/* This collision was not the same string, let's move to the next
in the table */
code = (code + 1) % hash_table->size;
+ /* We came back to our original code, which means that the table
+ is full */
+ if(code == start) {
+ printf("Full hash table (that should not happen)\n");
+ exit(EXIT_FAILURE);
+ }
}
/* This string was not already in there, store the index in the
}
/* This string was not already in there, store the index in the