strtabs
nimony/lib/std/strtabs.nim
The strtabs module implements an efficient hash table that is a mapping from strings to strings. Supports a case-sensitive, case-insensitive and style-insensitive mode.
type StringTableMode = enum modeCaseSensitive = (0, "modeCaseSensitive") modeCaseInsensitive = (1, "modeCaseInsensitive") modeStyleInsensitive = (2, "modeStyleInsensitive")
func dollar`.StringTableMode(e: StringTableMode): stringtype StringTableObj = object counter: int64 data: seq mode: StringTableMode
type StringTableRef = ref StringTableObj not niltype FormatFlag = enum useEnvironment = (0, "useEnvironment") useEmpty = (1, "useEmpty") useKey = (2, "useKey")
func dollar`.FormatFlag(e: FormatFlag): stringproc mode(t: ref StringTableObj not nil): StringTableModeiterator pairs(t: ref StringTableObj not nil): tuple[key: string, value: string]Iterates over every
(key, value)pair in the tablet.iterator keys(t: ref StringTableObj not nil): stringIterates over every key in the table
t.iterator values(t: ref StringTableObj not nil): stringIterates over every value in the table
t.proc len(t: ref StringTableObj not nil): int64Returns the number of keys in
t.proc [](t: ref StringTableObj not nil; key: string): var stringRetrieves the location at
t[key].If
keyis not int, theKeyErrorexception is raised. One can check with hasKey proc whether the key exists.See also:
- getOrDefault proc
- []= proc for inserting a new
(key, value) pair in the table
- hasKey proc for checking if a key
is in the table
proc getOrDefault(t: ref StringTableObj not nil; key: string; default: string): stringRetrieves the location at
t[key].If
keyis not int, the default value is returned (if not specified, it is an empty string ("")).See also:
- [] proc for retrieving a value of a key
- hasKey proc for checking if a key
is in the table
- []= proc for inserting a new
(key, value) pair in the table
proc hasKey(t: ref StringTableObj not nil; key: string): boolproc contains(t: ref StringTableObj not nil; key: string): boolAlias of hasKey proc for use with the
inoperator.proc []=(t: ref StringTableObj not nil; key: string; val: string)proc newStringTable(mode: StringTableMode): ref StringTableObj not nilCreates a new empty string table.
See also:
- `newStringTable(keyValuePairs) proc
<#newStringTable,varargs[tuple[string,string]],StringTableMode>`_
proc clear(s: ref StringTableObj not nil; mode: StringTableMode)Resets a string table to be empty again, perhaps altering the mode.
See also:
- del proc for removing a key from the table
proc clear(s: ref StringTableObj not nil)Resets a string table to be empty again without changing the mode.
proc del(t: ref StringTableObj not nil; key: string)Removes
keyfromt.See also:
- clear proc for resetting a
table to be empty
- []= proc for inserting a new
(key, value) pair in the table
proc $(t: ref StringTableObj not nil): stringThe
$operator for string tables. Used internally when callingechoon a table.proc %(f: string; t: ref StringTableObj not nil; flags: set[FormatFlag]): stringThe
%operator for string tables.