Merge pull request #2139 from c-blake/devel
Add mgetOrPut to support just one probe chase for the common
This commit is contained in:
commit
358d4b958c
3 changed files with 69 additions and 23 deletions
|
|
@ -65,7 +65,15 @@ block tableTest2:
|
|||
|
||||
for key, val in items(data): t[key] = val.toFloat
|
||||
for key, val in items(data): assert t[key] == val.toFloat
|
||||
|
||||
|
||||
assert(not t.hasKeyOrPut("456", 4.0)) # test absent key
|
||||
assert t.hasKeyOrPut("012", 3.0) # test present key
|
||||
var x = t.mgetOrPut("111", 1.5) # test absent key
|
||||
x = x * 2
|
||||
assert x == 3.0
|
||||
x = t.mgetOrPut("test", 1.5) # test present key
|
||||
x = x * 2
|
||||
assert x == 2 * 1.2345
|
||||
|
||||
block orderedTableTest1:
|
||||
var t = initOrderedTable[string, int](2)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ block tableTest1:
|
|||
for y in 0..1:
|
||||
assert t[(x,y)] == $x & $y
|
||||
assert($t ==
|
||||
"{(x: 0, y: 0): 00, (x: 0, y: 1): 01, (x: 1, y: 0): 10, (x: 1, y: 1): 11}")
|
||||
"{(x: 0, y: 1): 01, (x: 0, y: 0): 00, (x: 1, y: 0): 10, (x: 1, y: 1): 11}")
|
||||
|
||||
block tableTest2:
|
||||
var t = newTable[string, float]()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue