Implement {.booldefine.} (#10533)
This commit is contained in:
parent
07553034de
commit
0091f2ad3b
9 changed files with 71 additions and 17 deletions
|
|
@ -28,7 +28,7 @@ runnableExamples:
|
|||
|
||||
|
||||
## When using the style insensitive mode ``modeStyleInsensitive``,
|
||||
## all letters are compared case insensitively within the ASCII range
|
||||
## all letters are compared case insensitively within the ASCII range
|
||||
## and underscores are ignored.
|
||||
|
||||
runnableExamples:
|
||||
|
|
@ -272,6 +272,32 @@ proc `%`*(f: string, t: StringTableRef, flags: set[FormatFlag] = {}): string {.
|
|||
add(result, f[i])
|
||||
inc(i)
|
||||
|
||||
proc del*(t: StringTableRef, key: string) =
|
||||
## Removes `key` from `t`.
|
||||
# Impl adapted from `tableimpl.delImplIdx`
|
||||
var i = rawGet(t, key)
|
||||
let msk = high(t.data)
|
||||
if i >= 0:
|
||||
dec(t.counter)
|
||||
block outer:
|
||||
while true: # KnuthV3 Algo6.4R adapted for i=i+1 instead of i=i-1
|
||||
var j = i # The correctness of this depends on (h+1) in nextTry,
|
||||
var r = j # though may be adaptable to other simple sequences.
|
||||
t.data[i].hasValue = false # mark current EMPTY
|
||||
t.data[i].key = ""
|
||||
t.data[i].val = ""
|
||||
while true:
|
||||
i = (i + 1) and msk # increment mod table size
|
||||
if not t.data[i].hasValue: # end of collision cluster; So all done
|
||||
break outer
|
||||
r = t.myhash(t.data[i].key) and msk # "home" location of key@i
|
||||
if not ((i >= r and r > j) or (r > j and j > i) or (j > i and i >= r)):
|
||||
break
|
||||
when defined(js):
|
||||
t.data[j] = t.data[i]
|
||||
else:
|
||||
shallowCopy(t.data[j], t.data[i]) # data[j] will be marked EMPTY next loop
|
||||
|
||||
proc `$`*(t: StringTableRef): string {.rtlFunc, extern: "nstDollar".} =
|
||||
## The `$` operator for string tables.
|
||||
if t.len == 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue