Merge ../Nim into devel
This commit is contained in:
commit
55840d9505
112 changed files with 313 additions and 311 deletions
|
|
@ -404,7 +404,7 @@ proc setVal[K,V](table: var PConcTable[K,V], key: int, val: int,
|
|||
#echo("tomb old slot then set in new table")
|
||||
nextTable = copySlotAndCheck(table,idx)
|
||||
return setVal(nextTable, key, val, expVal, match)
|
||||
# Finaly ready to add new val to table
|
||||
# Finally ready to add new val to table
|
||||
while true:
|
||||
if match and oldVal != expVal:
|
||||
#echo("set failed, no match oldVal= " & $oldVal & " expVal= " & $expVal)
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ proc excl*[T](c: var CritBitTree[T], key: string) =
|
|||
iterator leaves[T](n: Node[T]): Node[T] =
|
||||
if n != nil:
|
||||
# XXX actually we could compute the necessary stack size in advance:
|
||||
# it's rougly log2(c.count).
|
||||
# it's roughly log2(c.count).
|
||||
var stack = @[n]
|
||||
while stack.len > 0:
|
||||
var it = stack.pop
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ template foldl*(sequence, operation: expr): expr =
|
|||
##
|
||||
## The ``operation`` parameter should be an expression which uses the
|
||||
## variables ``a`` and ``b`` for each step of the fold. Since this is a left
|
||||
## fold, for non associative binary operations like substraction think that
|
||||
## fold, for non associative binary operations like subtraction think that
|
||||
## the sequence of numbers 1, 2 and 3 will be parenthesized as (((1) - 2) -
|
||||
## 3). Example:
|
||||
##
|
||||
|
|
@ -328,12 +328,12 @@ template foldl*(sequence, operation: expr): expr =
|
|||
## let
|
||||
## numbers = @[5, 9, 11]
|
||||
## addition = foldl(numbers, a + b)
|
||||
## substraction = foldl(numbers, a - b)
|
||||
## subtraction = foldl(numbers, a - b)
|
||||
## multiplication = foldl(numbers, a * b)
|
||||
## words = @["nim", "is", "cool"]
|
||||
## concatenation = foldl(words, a & b)
|
||||
## assert addition == 25, "Addition is (((5)+9)+11)"
|
||||
## assert substraction == -15, "Substraction is (((5)-9)-11)"
|
||||
## assert subtraction == -15, "Subtraction is (((5)-9)-11)"
|
||||
## assert multiplication == 495, "Multiplication is (((5)*9)*11)"
|
||||
## assert concatenation == "nimiscool"
|
||||
assert sequence.len > 0, "Can't fold empty sequences"
|
||||
|
|
@ -356,7 +356,7 @@ template foldr*(sequence, operation: expr): expr =
|
|||
##
|
||||
## The ``operation`` parameter should be an expression which uses the
|
||||
## variables ``a`` and ``b`` for each step of the fold. Since this is a right
|
||||
## fold, for non associative binary operations like substraction think that
|
||||
## fold, for non associative binary operations like subtraction think that
|
||||
## the sequence of numbers 1, 2 and 3 will be parenthesized as (1 - (2 -
|
||||
## (3))). Example:
|
||||
##
|
||||
|
|
@ -364,12 +364,12 @@ template foldr*(sequence, operation: expr): expr =
|
|||
## let
|
||||
## numbers = @[5, 9, 11]
|
||||
## addition = foldr(numbers, a + b)
|
||||
## substraction = foldr(numbers, a - b)
|
||||
## subtraction = foldr(numbers, a - b)
|
||||
## multiplication = foldr(numbers, a * b)
|
||||
## words = @["nim", "is", "cool"]
|
||||
## concatenation = foldr(words, a & b)
|
||||
## assert addition == 25, "Addition is (5+(9+(11)))"
|
||||
## assert substraction == 7, "Substraction is (5-(9-(11)))"
|
||||
## assert subtraction == 7, "Subtraction is (5-(9-(11)))"
|
||||
## assert multiplication == 495, "Multiplication is (5*(9*(11)))"
|
||||
## assert concatenation == "nimiscool"
|
||||
assert sequence.len > 0, "Can't fold empty sequences"
|
||||
|
|
@ -507,12 +507,12 @@ when isMainModule:
|
|||
let
|
||||
numbers = @[5, 9, 11]
|
||||
addition = foldl(numbers, a + b)
|
||||
substraction = foldl(numbers, a - b)
|
||||
subtraction = foldl(numbers, a - b)
|
||||
multiplication = foldl(numbers, a * b)
|
||||
words = @["nim", "is", "cool"]
|
||||
concatenation = foldl(words, a & b)
|
||||
assert addition == 25, "Addition is (((5)+9)+11)"
|
||||
assert substraction == -15, "Substraction is (((5)-9)-11)"
|
||||
assert subtraction == -15, "Subtraction is (((5)-9)-11)"
|
||||
assert multiplication == 495, "Multiplication is (((5)*9)*11)"
|
||||
assert concatenation == "nimiscool"
|
||||
|
||||
|
|
@ -520,12 +520,12 @@ when isMainModule:
|
|||
let
|
||||
numbers = @[5, 9, 11]
|
||||
addition = foldr(numbers, a + b)
|
||||
substraction = foldr(numbers, a - b)
|
||||
subtraction = foldr(numbers, a - b)
|
||||
multiplication = foldr(numbers, a * b)
|
||||
words = @["nim", "is", "cool"]
|
||||
concatenation = foldr(words, a & b)
|
||||
assert addition == 25, "Addition is (5+(9+(11)))"
|
||||
assert substraction == 7, "Substraction is (5-(9-(11)))"
|
||||
assert subtraction == 7, "Subtraction is (5-(9-(11)))"
|
||||
assert multiplication == 495, "Multiplication is (5*(9*(11)))"
|
||||
assert concatenation == "nimiscool"
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
## (also often named `dictionary`:idx: in other programming languages) that is
|
||||
## a mapping from keys to values. ``Table`` is the usual hash table,
|
||||
## ``OrderedTable`` is like ``Table`` but remembers insertion order
|
||||
## and ``CountTable`` is a mapping from a key to its number of occurances.
|
||||
## and ``CountTable`` is a mapping from a key to its number of occurrences.
|
||||
## For consistency with every other data type in Nim these have **value**
|
||||
## semantics, this means that ``=`` performs a copy of the hash table.
|
||||
## For **reference** semantics use the ``Ref`` variant: ``TableRef``,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue