From 53ae8bb91319fe7c676d7e6e3ed7ae71dd4b6c9b Mon Sep 17 00:00:00 2001 From: yrutschle Date: Sat, 9 Apr 2022 13:22:55 +0200 Subject: [PATCH] remove floor entirely --- hash.c | 14 +------------- hashtest/delete.tst.ref | 2 +- hashtest/delete_at_end.tst.ref | 2 +- hashtest/delete_below_floor.tst.ref | 2 +- hashtest/delete_discont.tst.ref | 2 +- hashtest/delete_empty.tst.ref | 2 +- hashtest/delete_full.tst.ref | 2 +- hashtest/delete_middle.tst.ref | 2 +- hashtest/delete_wrap.tst.ref | 2 +- hashtest/delete_wrap_at_end.tst.ref | 2 +- hashtest/delete_wrap_below_floor.tst.ref | 2 +- hashtest/delete_wrap_discont.tst.ref | 2 +- hashtest/htest | Bin 24992 -> 24992 bytes hashtest/insert.tst.ref | 2 +- hashtest/insert_discont.tst.ref | 2 +- hashtest/insert_full.tst.ref | 2 +- hashtest/insert_full_floor.tst.ref | 2 +- hashtest/insert_wrap.tst.ref | 2 +- 18 files changed, 17 insertions(+), 29 deletions(-) diff --git a/hash.c b/hash.c index 2de8bf4..d3b9759 100644 --- a/hash.c +++ b/hash.c @@ -52,7 +52,6 @@ static void* const FREE = NULL; struct hash { int item_cnt; /* Number of items in the hash */ - int floor; /* Where is the highest key. Or the lowest insert point */ gap_array* data; hash_make_key_fn hash_make_key; @@ -74,7 +73,6 @@ hash* hash_init(hash_make_key_fn make_key, hash_cmp_item_fn cmp_item) if (!h) return NULL; h->item_cnt = 0; - h->floor = 0; h->data = gap_init(hash_size); h->hash_make_key = make_key; h->cmp_item = cmp_item; @@ -98,8 +96,6 @@ static int hash_find_index(hash* h, hash_item item) int index = hash_make_key(h, item); int cnt = 0; - if (index < h->floor) index = h->floor; - cnx = gap_get(h->data, index); #ifdef DEBUG fprintf(stderr, "searching %d\n", index); @@ -161,8 +157,6 @@ int hash_insert(hash* h, hash_item new) index = hash_next_index(h, index); curr_item = gap_get(hash, index); - - if (index == 0) h->floor++; } #if DEBUG @@ -182,14 +176,11 @@ int hash_remove(hash* h, hash_item item) int index = hash_find_index(h, item); if (index == -1) return -1; /* Tried to remove something that isn't there */ - int lower_floor = 0; /* If we remove something below the floor, we'll need to lower it */ while (1) { - if (index < h->floor) lower_floor = 1; int next_index = hash_next_index(h, index); hash_item next = gap_get(h->data, next_index); if ((next == FREE) || (distance(next_index, h, next) == 0)) { h->item_cnt--; - if (lower_floor) h->floor--; gap_set(hash, index, FREE); return 0; } @@ -197,9 +188,6 @@ int hash_remove(hash* h, hash_item item) gap_set(hash, index, next); index = hash_next_index(h, index);; -#if DEBUG - fprintf(stderr, "index %d floor %d\n", index, h->floor); -#endif } return 0; } @@ -222,7 +210,7 @@ void hash_dump(hash* h, char* filename) exit(1); } - fprintf(out, "\n", h->floor, h->item_cnt); + fprintf(out, "\n", h->item_cnt); for (int i = 0; i < hash_size; i++) { hash_item item = gap_get(h->data, i); int idx = 0; diff --git a/hashtest/delete.tst.ref b/hashtest/delete.tst.ref index a95a3dc..ca930bb 100644 --- a/hashtest/delete.tst.ref +++ b/hashtest/delete.tst.ref @@ -1,4 +1,4 @@ - + 0:0: 1:0: 2:0: diff --git a/hashtest/delete_at_end.tst.ref b/hashtest/delete_at_end.tst.ref index b883c40..c9ba1e5 100644 --- a/hashtest/delete_at_end.tst.ref +++ b/hashtest/delete_at_end.tst.ref @@ -1,4 +1,4 @@ - + 0:0: 1:0: 2:0: diff --git a/hashtest/delete_below_floor.tst.ref b/hashtest/delete_below_floor.tst.ref index e20cf3a..d256c1f 100644 --- a/hashtest/delete_below_floor.tst.ref +++ b/hashtest/delete_below_floor.tst.ref @@ -1,4 +1,4 @@ - + 0:30:ad 1:0: 2:2:ba diff --git a/hashtest/delete_discont.tst.ref b/hashtest/delete_discont.tst.ref index 07230ec..18b76f8 100644 --- a/hashtest/delete_discont.tst.ref +++ b/hashtest/delete_discont.tst.ref @@ -1,4 +1,4 @@ - + 0:0: 1:0: 2:0: diff --git a/hashtest/delete_empty.tst.ref b/hashtest/delete_empty.tst.ref index e51b8b1..c7539cf 100644 --- a/hashtest/delete_empty.tst.ref +++ b/hashtest/delete_empty.tst.ref @@ -1,4 +1,4 @@ - + 0:0: 1:0: 2:0: diff --git a/hashtest/delete_full.tst.ref b/hashtest/delete_full.tst.ref index 7dd0dea..3cc373a 100644 --- a/hashtest/delete_full.tst.ref +++ b/hashtest/delete_full.tst.ref @@ -1,4 +1,4 @@ - + 0:0:aa 1:1:ab 2:2:ac diff --git a/hashtest/delete_middle.tst.ref b/hashtest/delete_middle.tst.ref index 9484187..1d27ad8 100644 --- a/hashtest/delete_middle.tst.ref +++ b/hashtest/delete_middle.tst.ref @@ -1,4 +1,4 @@ - + 0:0: 1:0: 2:0: diff --git a/hashtest/delete_wrap.tst.ref b/hashtest/delete_wrap.tst.ref index 8cddd01..aabc8bd 100644 --- a/hashtest/delete_wrap.tst.ref +++ b/hashtest/delete_wrap.tst.ref @@ -1,4 +1,4 @@ - + 0:30:ba 1:30:bb 2:0: diff --git a/hashtest/delete_wrap_at_end.tst.ref b/hashtest/delete_wrap_at_end.tst.ref index 73ea879..aa6683a 100644 --- a/hashtest/delete_wrap_at_end.tst.ref +++ b/hashtest/delete_wrap_at_end.tst.ref @@ -1,4 +1,4 @@ - + 0:30:ac 1:1:ad 2:0: diff --git a/hashtest/delete_wrap_below_floor.tst.ref b/hashtest/delete_wrap_below_floor.tst.ref index e94683e..c47ff54 100644 --- a/hashtest/delete_wrap_below_floor.tst.ref +++ b/hashtest/delete_wrap_below_floor.tst.ref @@ -1,4 +1,4 @@ - + 0:30:ad 1:0: 2:0: diff --git a/hashtest/delete_wrap_discont.tst.ref b/hashtest/delete_wrap_discont.tst.ref index 83873da..d734495 100644 --- a/hashtest/delete_wrap_discont.tst.ref +++ b/hashtest/delete_wrap_discont.tst.ref @@ -1,4 +1,4 @@ - + 0:31:ad 1:0: 2:2:ba diff --git a/hashtest/htest b/hashtest/htest index e31a42712469918e80e69ff3bebe67ba1b97660a..aa2447526547353ea416ba87418fc12ae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x42g(CBK#2 z@Gh!ro_B?nwl$ + 0:0: 1:0: 2:0: diff --git a/hashtest/insert_discont.tst.ref b/hashtest/insert_discont.tst.ref index 6b376a2..bef2a57 100644 --- a/hashtest/insert_discont.tst.ref +++ b/hashtest/insert_discont.tst.ref @@ -1,4 +1,4 @@ - + 0:0: 1:0: 2:0: diff --git a/hashtest/insert_full.tst.ref b/hashtest/insert_full.tst.ref index fef3d55..fc6e827 100644 --- a/hashtest/insert_full.tst.ref +++ b/hashtest/insert_full.tst.ref @@ -1,4 +1,4 @@ - + 0:0:aa 1:1:ab 2:2:ac diff --git a/hashtest/insert_full_floor.tst.ref b/hashtest/insert_full_floor.tst.ref index 8c3b321..3823346 100644 --- a/hashtest/insert_full_floor.tst.ref +++ b/hashtest/insert_full_floor.tst.ref @@ -1,4 +1,4 @@ - + 0:30:ac 1:30:ad 2:2:ba diff --git a/hashtest/insert_wrap.tst.ref b/hashtest/insert_wrap.tst.ref index 7138081..6ccb959 100644 --- a/hashtest/insert_wrap.tst.ref +++ b/hashtest/insert_wrap.tst.ref @@ -1,4 +1,4 @@ - + 0:30:ac 1:30:ad 2:0:ba