some comments

This commit is contained in:
dzaima 2023-11-13 16:14:04 +02:00
parent c94d51dcaf
commit b4e53abbe4
2 changed files with 8 additions and 3 deletions

View File

@ -36,6 +36,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
# Allocates the maximum at the start, resizes downwards within the existing allocation
def hash_alloc{logsz, msz, ext, Ts, v0s, has_radix, ordered} = {
def ws = each{width,Ts}
def wt = tupsel{0,ws}
@ -56,15 +57,18 @@ def hash_alloc{logsz, msz, ext, Ts, v0s, has_radix, ordered} = {
each{memset{., ., sze}, ptrs, v0s}
def hash_resize{cc, m} = {
dif := sz*((1<<m)-1)
dif := sz*((1<<m)-1) # Number of elements of space to add
sh -= m; sz <<= m
set_thresh{}
cc = 0
k:tupsel{0,Ts} = 0; --k
cc = 0 # Collision counter
k:tupsel{0,Ts} = 0; --k # Index where to move an element to
each{{p,v} => { p -= dif; memset{p, v, dif} }, ptrs, v0s}
def {hash, ...vals} = ptrs; def {h0, ...v0r} = v0s
s := sz+ext
i := dif
# Iterate over existing elements in blocks of e<=32
# Branchlessly skips over h0
while (i < s) {
e := min{s-i, usz~~32}
b:u32 = 0

View File

@ -338,6 +338,7 @@ oper &- ({v:T,m} => v & -promote{T,m}) infix left 35
def rty{name} = if (to_prim{name}=='∊') i8 else i32
def ity{name} = (to_prim{name}=='⊒')**(*u32)
fn hashtab{T, name}(rp:*rty{name}, iv:*void, mi:usz, fv:*void, ni:usz, links:ity{name}) = {
# iv,mi/ip,m - searched-in; fv,ni/fp,n - searched-for; may get swapped around & back
def prim = to_prim{name}
def U = if (prim=='∊') usz else u32
m := cast_i{U,mi}; n := cast_i{U,ni}