Don't need to initialize indices for hashed Index-of

This commit is contained in:
Marshall Lochbaum 2023-11-04 17:52:22 -04:00
parent 1286ee32ec
commit af81da50e4
2 changed files with 6 additions and 2 deletions

View File

@ -50,6 +50,7 @@ def hash_alloc{logsz, msz, ext, Ts, v0s} = {
def pe{{..._, p}} = p+sze # Next unallocated space given pointers so far
def pl{{...R, T}} = { def ps=pl{R}; tup{...ps, *T~~pe{ps}+szo} }
ptrs := pl{Ts}
def memset{_, ('any'), _} = {} # Indicates initialization not needed
each{memset{., ., sze}, ptrs, v0s}
def hash_resize{cc, m} = {
@ -66,7 +67,10 @@ def hash_alloc{logsz, msz, ext, Ts, v0s} = {
k0 := h>>sh; k := k0; while (hash->k!=h0) ++k
cc += cast_i{usz, k-k0}
hash <-{k} h
each{{p,v0} => { v := p->j; p <-{j} v0; p <-{k} v }, vals, v0r}
def move{p,v0} = {
v := p->j; if (not same{v0,'any'}) p <-{j} v0; p <-{k} v
}
each{move, vals, v0r}
}
}
}

View File

@ -360,7 +360,7 @@ fn hashtab{T, name}(rp:*rty{name}, ip:*T, m:usz, fp:*T, n:usz, links:ity{name})
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**0}
sl, msz, ext, tup{T, ...aux**u32}, tup{maxh, ...aux**(if (prim=='⊐') 'any' else 0)}
}
def {hash,...vals} = tabs