diff options
author | JamesP <jlp765@gmail.com> | 2015-10-05 15:19:56 +1000 |
---|---|---|
committer | JamesP <jlp765@gmail.com> | 2015-10-06 16:36:32 +1000 |
commit | 73821ad1c4b2f64a2885c60c3bc43e74cae5ee1d (patch) | |
tree | e982e4a6792517e1bc5ce9416aff291b65b601a8 /lib | |
parent | 87a6268d3c93fef26ca5f7a74a3ec78b6aae667a (diff) | |
download | Nim-73821ad1c4b2f64a2885c60c3bc43e74cae5ee1d.tar.gz |
add assert test to end of module
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/strtabs.nim | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim index 0a1cc6167..1ce9067a7 100644 --- a/lib/pure/strtabs.nim +++ b/lib/pure/strtabs.nim @@ -135,18 +135,15 @@ proc enlarge(t: StringTableRef) = if not isNil(t.data[i].key): rawInsert(t, n, t.data[i].key, t.data[i].val) swap(t.data, n) -proc addVal(t: StringTableRef, key, val: string) = +proc `[]=`*(t: StringTableRef, key, val: string) {.rtl, extern: "nstPut".} = + ## puts a (key, value)-pair into `t`. var index = rawGet(t, key) if index >= 0: t.data[index].val = val else: if mustRehash(len(t.data), t.counter): enlarge(t) rawInsert(t, t.data, key, val) - -proc `[]=`*(t: StringTableRef, key, val: string) {.rtl, extern: "nstPut".} = - ## puts a (key, value)-pair into `t`. - t.addVal(key, val) - inc(t.counter) + inc(t.counter) proc raiseFormatException(s: string) = var e: ref ValueError @@ -176,6 +173,9 @@ proc clear*(s: StringTableRef, mode: StringTableMode) = s.mode = mode s.counter = 0 s.data.setLen(startSize) + for i in 0..<s.data.len: + if not isNil(s.data[i].key): + s.data[i].key = nil proc newStringTable*(keyValuePairs: varargs[string], mode: StringTableMode): StringTableRef {. @@ -251,3 +251,6 @@ when isMainModule: x.mget("11") = "23" assert x["11"] == "23" + x.clear(modeCaseInsensitive) + x["11"] = "22" + assert x["11"] == "22" |