add a StringTable.clear that requires no mode specification (#12853)
* add clear overload, test, changelog * add since annotation
This commit is contained in:
parent
a02d043b58
commit
a3d45d0c1b
3 changed files with 9 additions and 1 deletions
|
|
@ -34,6 +34,7 @@
|
||||||
delimiter instead of '{' and '}'.
|
delimiter instead of '{' and '}'.
|
||||||
- introduced new procs in `tables.nim`: `OrderedTable.pop`, `CountTable.del`,
|
- introduced new procs in `tables.nim`: `OrderedTable.pop`, `CountTable.del`,
|
||||||
`CountTable.pop`, `Table.pop`
|
`CountTable.pop`, `Table.pop`
|
||||||
|
- To `strtabs.nim`, added `StringTable.clear` overload that reuses the existing mode.
|
||||||
|
|
||||||
|
|
||||||
- Added `sugar.outplace` for turning in-place algorithms like `sort` and `shuffle` into
|
- Added `sugar.outplace` for turning in-place algorithms like `sort` and `shuffle` into
|
||||||
|
|
|
||||||
|
|
@ -308,7 +308,7 @@ proc getValue(t: StringTableRef, flags: set[FormatFlag], key: string): string =
|
||||||
|
|
||||||
proc clear*(s: StringTableRef, mode: StringTableMode) {.
|
proc clear*(s: StringTableRef, mode: StringTableMode) {.
|
||||||
rtlFunc, extern: "nst$1".} =
|
rtlFunc, extern: "nst$1".} =
|
||||||
## Resets a string table to be empty again.
|
## Resets a string table to be empty again, perhaps altering the mode.
|
||||||
##
|
##
|
||||||
## See also:
|
## See also:
|
||||||
## * `del proc <#del,StringTableRef,string>`_ for removing a key from the table
|
## * `del proc <#del,StringTableRef,string>`_ for removing a key from the table
|
||||||
|
|
@ -324,6 +324,10 @@ proc clear*(s: StringTableRef, mode: StringTableMode) {.
|
||||||
for i in 0..<s.data.len:
|
for i in 0..<s.data.len:
|
||||||
s.data[i].hasValue = false
|
s.data[i].hasValue = false
|
||||||
|
|
||||||
|
proc clear*(s: StringTableRef) {.since: (1, 1).} =
|
||||||
|
## Resets a string table to be empty again without changing the mode.
|
||||||
|
s.clear(s.mode)
|
||||||
|
|
||||||
proc del*(t: StringTableRef, key: string) =
|
proc del*(t: StringTableRef, key: string) =
|
||||||
## Removes `key` from `t`.
|
## Removes `key` from `t`.
|
||||||
##
|
##
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ key_7: value7
|
||||||
key_80: value80
|
key_80: value80
|
||||||
key_8: value8
|
key_8: value8
|
||||||
key_9: value9
|
key_9: value9
|
||||||
|
length of table 0
|
||||||
length of table 81
|
length of table 81
|
||||||
value1 = value2
|
value1 = value2
|
||||||
'''
|
'''
|
||||||
|
|
@ -99,3 +100,5 @@ for key, val in pairs(tab):
|
||||||
writeLine(stdout, "length of table ", $tab.len)
|
writeLine(stdout, "length of table ", $tab.len)
|
||||||
|
|
||||||
writeLine(stdout, `%`("$key1 = $key2", tab, {useEnvironment}))
|
writeLine(stdout, `%`("$key1 = $key2", tab, {useEnvironment}))
|
||||||
|
tab.clear
|
||||||
|
writeLine(stdout, "length of table ", $tab.len)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue