Mentions nextPowerOfTwo proc for table initialization.
This commit is contained in:
parent
29d0a774e9
commit
1bd12e208b
1 changed files with 15 additions and 6 deletions
|
|
@ -159,8 +159,11 @@ proc del*[A, B](t: var TTable[A, B], key: A) =
|
||||||
dec(t.counter)
|
dec(t.counter)
|
||||||
|
|
||||||
proc initTable*[A, B](initialSize=64): TTable[A, B] =
|
proc initTable*[A, B](initialSize=64): TTable[A, B] =
|
||||||
## creates a new hash table that is empty. `initialSize` needs to be
|
## creates a new hash table that is empty.
|
||||||
## a power of two.
|
##
|
||||||
|
## `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.
|
||||||
assert isPowerOfTwo(initialSize)
|
assert isPowerOfTwo(initialSize)
|
||||||
result.counter = 0
|
result.counter = 0
|
||||||
newSeq(result.data, initialSize)
|
newSeq(result.data, initialSize)
|
||||||
|
|
@ -290,8 +293,11 @@ proc add*[A, B](t: var TOrderedTable[A, B], key: A, val: B) =
|
||||||
AddImpl()
|
AddImpl()
|
||||||
|
|
||||||
proc initOrderedTable*[A, B](initialSize=64): TOrderedTable[A, B] =
|
proc initOrderedTable*[A, B](initialSize=64): TOrderedTable[A, B] =
|
||||||
## creates a new ordered hash table that is empty. `initialSize` needs to be
|
## creates a new ordered hash table that is empty.
|
||||||
## a power of two.
|
##
|
||||||
|
## `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.
|
||||||
assert isPowerOfTwo(initialSize)
|
assert isPowerOfTwo(initialSize)
|
||||||
result.counter = 0
|
result.counter = 0
|
||||||
result.first = -1
|
result.first = -1
|
||||||
|
|
@ -437,8 +443,11 @@ proc `[]=`*[A](t: var TCountTable[A], key: A, val: int) =
|
||||||
PutImpl()
|
PutImpl()
|
||||||
|
|
||||||
proc initCountTable*[A](initialSize=64): TCountTable[A] =
|
proc initCountTable*[A](initialSize=64): TCountTable[A] =
|
||||||
## creates a new count table that is empty. `initialSize` needs to be
|
## creates a new count table that is empty.
|
||||||
## a power of two.
|
##
|
||||||
|
## `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.
|
||||||
assert isPowerOfTwo(initialSize)
|
assert isPowerOfTwo(initialSize)
|
||||||
result.counter = 0
|
result.counter = 0
|
||||||
newSeq(result.data, initialSize)
|
newSeq(result.data, initialSize)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue