Skip to content

Commit

Permalink
Fix the only real bug found so far in 1000s of Uninit & ProveInit
Browse files Browse the repository at this point in the history
warnings where `default(V)` was being used in favor of the `def`
parameter that itself only defaults to `default(V)`.
  • Loading branch information
c-blake committed Nov 24, 2024
1 parent f37ac8e commit 277b940
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion adix/lptabz.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions adix/oats.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 277b940

Please sign in to comment.