diff options
-rw-r--r-- | compiler/semexprs.nim | 2 | ||||
-rw-r--r-- | doc/manual/types.txt | 6 | ||||
-rw-r--r-- | lib/pure/collections/sharedtables.nim | 19 | ||||
-rw-r--r-- | lib/pure/collections/tables.nim | 9 | ||||
-rw-r--r-- | tests/collections/tableadds.nim | 13 |
5 files changed, 35 insertions, 14 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 5c29530b8..48af285bb 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2125,7 +2125,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode = while true: checkInitialized(objType.n, ids, n.info) if objType.sons[0] == nil: break - objType = skipTypes(objType.sons[0], {tyGenericInst}) + objType = skipTypes(objType.sons[0], skipPtrs) proc semBlock(c: PContext, n: PNode): PNode = result = n diff --git a/doc/manual/types.txt b/doc/manual/types.txt index 1e2dc857f..d6495dbc3 100644 --- a/doc/manual/types.txt +++ b/doc/manual/types.txt @@ -390,7 +390,10 @@ i-th *unichar*. The iterator ``runes`` from the `unicode module cstring type ------------ -The ``cstring`` type represents a pointer to a zero-terminated char array + +The ``cstring`` type meaning `compatible string` is the native representation +of a string for the compilation backend. For the C backend the ``cstring`` type +represents a pointer to a zero-terminated char array compatible to the type ``char*`` in Ansi C. Its primary purpose lies in easy interfacing with C. The index operation ``s[i]`` means the i-th *char* of ``s``; however no bounds checking for ``cstring`` is performed making the @@ -421,7 +424,6 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr - Structured types ---------------- A variable of a structured type can hold multiple values at the same diff --git a/lib/pure/collections/sharedtables.nim b/lib/pure/collections/sharedtables.nim index 17600b272..7dc338f4e 100644 --- a/lib/pure/collections/sharedtables.nim +++ b/lib/pure/collections/sharedtables.nim @@ -35,9 +35,12 @@ proc enlarge[A, B](t: var SharedTable[A, B]) = t.dataLen = size swap(t.data, n) for i in 0..<oldSize: - if isFilled(n[i].hcode): - var j = -1 - rawGetKnownHC(t, n[i].key, n[i].hcode) - rawInsert(t, t.data, n[i].key, n[i].val, n[i].hcode, j) + let eh = n[i].hcode + if isFilled(eh): + var j: Hash = eh and maxHash(t) + while isFilled(t.data[j].hcode): + j = nextTry(j, maxHash(t)) + rawInsert(t, t.data, n[i].key, n[i].val, eh, j) deallocShared(n) template withLock(t, x: untyped) = @@ -47,7 +50,7 @@ template withLock(t, x: untyped) = template withValue*[A, B](t: var SharedTable[A, B], key: A, value, body: untyped) = - ## retrieves the value at ``t[key]``. + ## retrieves the value at ``t[key]``. ## `value` can be modified in the scope of the ``withValue`` call. ## ## .. code-block:: nim @@ -55,7 +58,7 @@ template withValue*[A, B](t: var SharedTable[A, B], key: A, ## sharedTable.withValue(key, value) do: ## # block is executed only if ``key`` in ``t`` ## # value is threadsafe in block - ## value.name = "username" + ## value.name = "username" ## value.uid = 1000 ## acquire(t.lock) @@ -71,15 +74,15 @@ template withValue*[A, B](t: var SharedTable[A, B], key: A, template withValue*[A, B](t: var SharedTable[A, B], key: A, value, body1, body2: untyped) = - ## retrieves the value at ``t[key]``. + ## retrieves the value at ``t[key]``. ## `value` can be modified in the scope of the ``withValue`` call. - ## + ## ## .. code-block:: nim ## ## sharedTable.withValue(key, value) do: ## # block is executed only if ``key`` in ``t`` ## # value is threadsafe in block - ## value.name = "username" + ## value.name = "username" ## value.uid = 1000 ## do: ## # block is executed when ``key`` not in ``t`` diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 3f06762ae..9fa8f5263 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -270,9 +270,12 @@ proc enlarge[A, B](t: var Table[A, B]) = newSeq(n, len(t.data) * growthFactor) swap(t.data, n) for i in countup(0, high(n)): - if isFilled(n[i].hcode): - var j = -1 - rawGetKnownHC(t, n[i].key, n[i].hcode) - rawInsert(t, t.data, n[i].key, n[i].val, n[i].hcode, j) + let eh = n[i].hcode + if isFilled(eh): + var j: Hash = eh and maxHash(t) + while isFilled(t.data[j].hcode): + j = nextTry(j, maxHash(t)) + rawInsert(t, t.data, n[i].key, n[i].val, eh, j) proc mgetOrPut*[A, B](t: var Table[A, B], key: A, val: B): var B = ## retrieves value at ``t[key]`` or puts ``val`` if not present, either way diff --git a/tests/collections/tableadds.nim b/tests/collections/tableadds.nim new file mode 100644 index 000000000..71f1fad7d --- /dev/null +++ b/tests/collections/tableadds.nim @@ -0,0 +1,13 @@ +discard """ + output: '''done''' +""" + +import tables + +proc main = + var tab = newTable[string, string]() + for i in 0..1000: + tab.add "key", "value " & $i + +main() +echo "done" |