From aded9d4782802b4ea913d00fdc2ab5d6bf2614b0 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 8 Nov 2023 17:34:33 -0500 Subject: [PATCH] Shortcutting for reverse Member-of hash --- src/singeli/src/search.singeli | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/singeli/src/search.singeli b/src/singeli/src/search.singeli index 89507f37..66fe18f4 100644 --- a/src/singeli/src/search.singeli +++ b/src/singeli/src/search.singeli @@ -375,11 +375,23 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, m:usz, fv:*void, n:usz, links:ity{n swap_sides{}; i=m # i==m return value is kind of dumb @for (ip over m) { # Remove values in ip from hash h := hash_val{ip}; j := h>>sh - if (h == maxh) { has_maxh = 0 } else { + def shortcut = makelabel{} + if (h == maxh) { + if (uniq==0) goto{shortcut} + has_maxh = 0 + } else { k := load{hash,j} if (k <= h) { while (k < h) { ++j; k = load{hash,j} } - if (k==h) hash_remove{j,h} + if (k == h) { + --uniq + if (uniq==0 and not has_maxh) { + setlabel{shortcut} + @for (rp over n) rp = 1 + goto{abort} + } + hash_remove{j,h} + } } } } @@ -432,6 +444,7 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, m:usz, fv:*void, n:usz, links:ity{n def lookup=makelabel{}; def abort=makelabel{}; def dup=makelabel{} cc:usz = 0 # Collision counter + uniq:usz = 0 # Uniques inserted i:usz=0; while (1) { e := tern{m-i>b, i+b, m} while (i < e) { @@ -453,6 +466,7 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, m:usz, fv:*void, n:usz, links:ity{n } while (k != maxh) cc += cast_i{usz, je-j0} } + if (prim=='∊') uniq += promote{usz,h!=maxh} store{hash, j, h} set_tab{j, je, kr, dup} ++i