Added the ability to initialize a deque with an openArray (#15138)
* Add ability to initialize a deque with a sequence Example: var dq = initDeque[char](@['a', 'b', 'c']) * Update deques.nim * Optimized deque initialization * Sequence replaced by open array in deque initialization
This commit is contained in:
parent
ef6358f0b0
commit
d9ed816b10
1 changed files with 6 additions and 0 deletions
|
|
@ -84,6 +84,12 @@ proc initDeque*[T](initialSize: int = 4): Deque[T] =
|
||||||
## The length of a newly created deque will still be 0.
|
## The length of a newly created deque will still be 0.
|
||||||
result.initImpl(initialSize)
|
result.initImpl(initialSize)
|
||||||
|
|
||||||
|
proc initDeque*[T](arr: openArray[T]): Deque[T] =
|
||||||
|
## Create a new deque initialized with an open array
|
||||||
|
result.initImpl(nextPowerOfTwo(arr.len))
|
||||||
|
for i in 0 ..< arr.len:
|
||||||
|
result.addLast(arr[i])
|
||||||
|
|
||||||
proc len*[T](deq: Deque[T]): int {.inline.} =
|
proc len*[T](deq: Deque[T]): int {.inline.} =
|
||||||
## Return the number of elements of `deq`.
|
## Return the number of elements of `deq`.
|
||||||
result = deq.count
|
result = deq.count
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue