From 63b503e27f0ae0a8c8f9a62ceefcefaa9f794e7d Mon Sep 17 00:00:00 2001 From: yrutschle Date: Fri, 8 Apr 2022 19:55:22 +0200 Subject: [PATCH] simplify remove with distance computation --- hash.c | 9 +-------- hashtest/htest | Bin 25032 -> 25032 bytes 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/hash.c b/hash.c index 19adf33..aaed19d 100644 --- a/hash.c +++ b/hash.c @@ -176,13 +176,6 @@ int hash_insert(hash* h, hash_item new) return 0; } -static int next_in_right_place(hash* h, hash_item item, int index) -{ - if (!item) return 0; - int wanted_index = hash_make_key(h, item); - return (wanted_index == index); -} - /* Remove cnx from the hash */ int hash_remove(hash* h, hash_item item) { @@ -196,7 +189,7 @@ int hash_remove(hash* h, hash_item item) 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) || next_in_right_place(h, next, next_index)) { + if ((next == FREE) || (distance(next_index, h, next) == 0)) { h->item_cnt--; if (lower_floor) h->floor--; gap_set(hash, index, FREE); diff --git a/hashtest/htest b/hashtest/htest index d88ee8fb74dfc71b3ae16e5d6e6bc07adae8d3db..224255b7ee9a2aea7a2f835684c6ffb12314a67f 100755 GIT binary patch delta 166 zcmX?cnDNA6#tmPXMAW8sZcv_7A+oHOr=`QEYf{tJ=G-6C4{5=;yXo}I@$S`U=2ZO&z2 zbZvc7ssdDJcnPS?)$sp|6F>zX%||#~I)6mRI>tE0I>tH1A5NRloXf)a`r77iB9?rN R{gVxpMH!tpyD2x>0RZXDLX7|b delta 166 zcmX?cnDNA6#tmPXL_TjXJK&!?;o>c>bK*-@d|8|Gf5oxQ9L$k|S{1H_PhP91@yoX` zfPhEm@&BO$%@5=)50|*ObpG?{{N&U5-m&xk3$e+)B3h18ObiU3oyR;{50tKN&ShY9 zZGBRz22^Kw38>7~@c)ZbKm{JnM>t$Me?-SR#yG}0#yQ3x=9hP1XwGF}e0^o}HxWxd R#@@*W%A$;}o86R~>;P~tMfU&z