initialSize parameter does not work in OrderedTableRef #4940

miiza opened this Issue Oct 23, 2016 · 0 comments


None yet

1 participant

miiza commented Oct 23, 2016

initialSize parameter in newOrderedTable procedure is not transmited to initOrderedTable procedure:

proc newOrderedTable*[A, B](initialSize=64): OrderedTableRef[A, B] =
  ## creates a new ordered hash table that is empty.
  ## `initialSize` needs to be a power of two. If you need to accept runtime
  ## values for this you could use the ``nextPowerOfTwo`` proc from the
  ## `math <math.html>`_ module or the ``rightSize`` proc from this module.
result[] = initOrderedTable[A, B]()

In other procedures it is ok, e. g.:

proc newTable*[A, B](initialSize=64): TableRef[A, B] =
result[] = initTable[A, B](initialSize)

You can see it in the following code: b will be initialized to default 64 instead of requested 1.

import tables
import marshal

var a :  OrderedTable[int, int]
var b: OrderedTableRef[int, int]

a = initOrderedTable[int, int](1)
b = newOrderedTable[int, int](1)

a[777] = 888
b[777] = 888

echo $$a
echo $$b[]

I am new both to Nim and git so I am sorry I can't fix it myself.

@Araq Araq pushed a commit that closed this issue Oct 27, 2016
@jangko jangko fixes #4940 a42e9b1
@Araq Araq closed this in a42e9b1 Oct 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment