Skip to content

Commit

Permalink
fixes a subtle tables.nim regression
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Sep 5, 2019
1 parent 49f63d3 commit 0882a09
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions lib/pure/collections/tables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ proc initTable*[A, B](initialSize = defaultInitialSize): Table[A, B] =
b = initTable[char, seq[int]]()
initImpl(result, initialSize)

proc `[]=`*[A, B](t: var Table[A, B], key: A, val: B) =
## Inserts a ``(key, value)`` pair into ``t``.
##
## See also:
## * `[] proc<#[],Table[A,B],A>`_ for retrieving a value of a key
## * `hasKeyOrPut proc<#hasKeyOrPut,Table[A,B],A,B>`_
## * `mgetOrPut proc<#mgetOrPut,Table[A,B],A,B>`_
## * `del proc<#del,Table[A,B],A>`_ for removing a key from the table
runnableExamples:
var a = initTable[char, int]()
a['x'] = 7
a['y'] = 33
doAssert a == {'x': 7, 'y': 33}.toTable

putImpl(enlarge)

proc toTable*[A, B](pairs: openArray[(A, B)]): Table[A, B] =
## Creates a new hash table that contains the given ``pairs``.
##
Expand Down Expand Up @@ -362,22 +378,6 @@ proc `[]`*[A, B](t: var Table[A, B], key: A): var B =
## the table
get(t, key)

proc `[]=`*[A, B](t: var Table[A, B], key: A, val: B) =
## Inserts a ``(key, value)`` pair into ``t``.
##
## See also:
## * `[] proc<#[],Table[A,B],A>`_ for retrieving a value of a key
## * `hasKeyOrPut proc<#hasKeyOrPut,Table[A,B],A,B>`_
## * `mgetOrPut proc<#mgetOrPut,Table[A,B],A,B>`_
## * `del proc<#del,Table[A,B],A>`_ for removing a key from the table
runnableExamples:
var a = initTable[char, int]()
a['x'] = 7
a['y'] = 33
doAssert a == {'x': 7, 'y': 33}.toTable

putImpl(enlarge)

proc hasKey*[A, B](t: Table[A, B], key: A): bool =
## Returns true if ``key`` is in the table ``t``.
##
Expand Down Expand Up @@ -1285,6 +1285,22 @@ proc initOrderedTable*[A, B](initialSize = defaultInitialSize): OrderedTable[A,
b = initOrderedTable[char, seq[int]]()
initImpl(result, initialSize)

proc `[]=`*[A, B](t: var OrderedTable[A, B], key: A, val: B) =
## Inserts a ``(key, value)`` pair into ``t``.
##
## See also:
## * `[] proc<#[],OrderedTable[A,B],A>`_ for retrieving a value of a key
## * `hasKeyOrPut proc<#hasKeyOrPut,OrderedTable[A,B],A,B>`_
## * `mgetOrPut proc<#mgetOrPut,OrderedTable[A,B],A,B>`_
## * `del proc<#del,OrderedTable[A,B],A>`_ for removing a key from the table
runnableExamples:
var a = initOrderedTable[char, int]()
a['x'] = 7
a['y'] = 33
doAssert a == {'x': 7, 'y': 33}.toOrderedTable

putImpl(enlarge)

proc toOrderedTable*[A, B](pairs: openArray[(A, B)]): OrderedTable[A, B] =
## Creates a new ordered hash table that contains the given ``pairs``.
##
Expand Down Expand Up @@ -1342,22 +1358,6 @@ proc `[]`*[A, B](t: var OrderedTable[A, B], key: A): var B =
## key is in the table
get(t, key)

proc `[]=`*[A, B](t: var OrderedTable[A, B], key: A, val: B) =
## Inserts a ``(key, value)`` pair into ``t``.
##
## See also:
## * `[] proc<#[],OrderedTable[A,B],A>`_ for retrieving a value of a key
## * `hasKeyOrPut proc<#hasKeyOrPut,OrderedTable[A,B],A,B>`_
## * `mgetOrPut proc<#mgetOrPut,OrderedTable[A,B],A,B>`_
## * `del proc<#del,OrderedTable[A,B],A>`_ for removing a key from the table
runnableExamples:
var a = initOrderedTable[char, int]()
a['x'] = 7
a['y'] = 33
doAssert a == {'x': 7, 'y': 33}.toOrderedTable

putImpl(enlarge)

proc hasKey*[A, B](t: OrderedTable[A, B], key: A): bool =
## Returns true if ``key`` is in the table ``t``.
##
Expand Down

0 comments on commit 0882a09

Please sign in to comment.