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:
archnim
2020-08-05 16:41:42 +00:00
committed by GitHub
parent ef6358f0b0
commit d9ed816b10

View File

@@ -84,6 +84,12 @@ proc initDeque*[T](initialSize: int = 4): Deque[T] =
## The length of a newly created deque will still be 0.
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.} =
## Return the number of elements of `deq`.
result = deq.count