From 277b9408fdef3451d99bca31d2d6b7d0da299446 Mon Sep 17 00:00:00 2001 From: Charles Blake Date: Sun, 24 Nov 2024 08:29:16 -0500 Subject: [PATCH] Fix the only real bug found so far in 1000s of `Uninit` & `ProveInit` warnings where `default(V)` was being used in favor of the `def` parameter that itself only defaults to `default(V)`. --- adix/lptabz.nim | 2 +- adix/oats.nim | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adix/lptabz.nim b/adix/lptabz.nim index 29c1d41..7fcbcc2 100644 --- a/adix/lptabz.nim +++ b/adix/lptabz.nim @@ -1042,7 +1042,7 @@ proc getOrDefault*[K,V,Z;z:static int](t: LPTabz[K,V,Z,z], key: K, def=default(V)): V {.inline.} = mixin rawGet let i = t.rawGet(key) - result = if i >= 0: t.cell(i).val else: default + result = if i >= 0: t.cell(i).val else: def proc del*[K,V,Z;z:static int](t: var LPTabz[K,V,Z,z], key: K) {.inline.} = ## delete one key `key` from `t`; If you want to know if it was present then diff --git a/adix/oats.nim b/adix/oats.nim index dd50ea9..a22a344 100644 --- a/adix/oats.nim +++ b/adix/oats.nim @@ -67,7 +67,7 @@ proc oatSlot*[K,Q](t: Oat[K,Q]; q: Q; h: Hash; d: var Hash): int = proc tooFull*[K,Q](t: Oat[K,Q]; d: int; newSize: var int): bool = #-> user proc w/some provided default BUT there's a circular dep through `len` - let sLen = t.len # Could be a cap-long loop + let sLen=t.len # Could be a cap-long loop if sLen + 1 + 1 > t.cap: # Call setCap pre-put? +1 new, +1 free newSize = t.cap shl 1; return true let p2 = lgCeil(t.cap) # NOT an over-deep search; Would like to test @@ -119,7 +119,7 @@ proc mgetOrPut*[K,Q,V](t: var VPOat[K,Q,V], q: Q, v: V): var V = t.upSert q, i, UP=(t.val i), SERT=(t.key(i, t.keyR q); t.val i, v) proc getOrDefault*[K,Q,V](t: VOat[K,Q,V], q: Q, def=default(V)): V = - if (var d: Hash; let i = oatSlot(t, q, q.hash, d); i >= 0): result = t.val i + if (var d: Hash; let i = oatSlot(t, q, q.hash, d); i >= 0): t.val i else: def iterator items*[K,Q](t: Oat[K,Q]): K = for i in 0 ..< t.cap: (if t.used i: yield t.key i)