diff --git a/src/singeli/src/hashtab.singeli b/src/singeli/src/hashtab.singeli index 92c200b7..85c8142d 100644 --- a/src/singeli/src/hashtab.singeli +++ b/src/singeli/src/hashtab.singeli @@ -35,7 +35,7 @@ def hash_val{x:u32 & hasarch{'SSE4.2'}} = { # Allocate and initialize resizing hash table # Initial size sz+ext and maximum size msz+ext # One region for each type in Ts initialized with value from v0s -def hash_alloc{logsz, msz, ext, Ts, v0s} = { +def hash_alloc{logsz, msz, ext, Ts, v0s, ordered} = { def ws = each{width,Ts} each{assert, slice{ws,0,-1} >= slice{ws,1}} # Doesn't do alignment # Variables updated on resize @@ -56,15 +56,16 @@ def hash_alloc{logsz, msz, ext, Ts, v0s} = { def hash_resize{cc, m} = { dif := sz*((1< { p -= dif; memset{p, v, dif} }, ptrs, v0s} def {hash, ...vals} = ptrs; def {h0, ...v0r} = v0s - @for (j from dif to sz + ext) { - h := hash->j + @for (h in hash over j from dif to sz + ext) { if (h != h0) { hash <-{j} h0 - k0 := h>>sh; k := k0; while (hash->k!=h0) ++k + k0 := h>>sh + if (ordered) { k = max{k0, k+1} } # k0 can't be less than k + else { k = k0; while (hash->k!=h0) ++k } cc += cast_i{usz, k-k0} hash <-{k} h def move{p,v0} = { diff --git a/src/singeli/src/search.singeli b/src/singeli/src/search.singeli index beca3e04..a46e37fd 100644 --- a/src/singeli/src/search.singeli +++ b/src/singeli/src/search.singeli @@ -360,7 +360,7 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, m:usz, fv:*void, n:usz, links:ity{n maxh := T~~maxvalue{T} def aux = prim!='∊' def {tabs, sz, sh, hash_resize, hash_free} = hash_alloc{ - sl, msz, ext, tup{T, ...aux**u32}, tup{maxh, ...aux**'any'} + sl, msz, ext, tup{T, ...aux**u32}, tup{maxh, ...aux**'any'}, 1 } def {hash,...vals} = tabs diff --git a/src/singeli/src/selfsearch.singeli b/src/singeli/src/selfsearch.singeli index 834de1f3..49dc9948 100644 --- a/src/singeli/src/selfsearch.singeli +++ b/src/singeli/src/selfsearch.singeli @@ -25,7 +25,7 @@ fn selfhashtab{T, name}(rp:*rty{name}, xp:*T, n:usz) = { rp <-{0} res0 def aux = prim!='∊' def {{hash,...vals}, sz, sh, hash_resize, hash_free} = hash_alloc{ - sl, msz, ext, tup{T, ...aux**u32}, tup{x0, ...aux**0} + sl, msz, ext, tup{T, ...aux**u32}, tup{x0, ...aux**0}, 0 } # Resize or abort if more than 1/2^thresh collisions/element