mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-18 23:11:36 +00:00
Implements BackwardsIndex [] for deque. (#10105)
This commit is contained in:
committed by
Andreas Rumpf
parent
796432ff94
commit
d740a5b79a
@@ -88,11 +88,23 @@ proc `[]`*[T](deq: var Deque[T], i: Natural): var T {.inline.} =
|
||||
xBoundsCheck(deq, i)
|
||||
return deq.data[(deq.head + i) and deq.mask]
|
||||
|
||||
proc `[]=`* [T] (deq: var Deque[T], i: Natural, val : T) {.inline.} =
|
||||
proc `[]=`*[T](deq: var Deque[T], i: Natural, val : T) {.inline.} =
|
||||
## Change the i-th element of `deq`.
|
||||
xBoundsCheck(deq, i)
|
||||
deq.data[(deq.head + i) and deq.mask] = val
|
||||
|
||||
proc `[]`*[T](deq: var Deque[T], i: BackwardsIndex): var T {.inline.} =
|
||||
## Access the backwards indexed i-th element.
|
||||
return deq[deq.len - int(i)]
|
||||
|
||||
proc `[]`*[T](deq: Deque[T], i: BackwardsIndex): T {.inline.} =
|
||||
## Access the backwards indexed i-th element.
|
||||
return deq[deq.len - int(i)]
|
||||
|
||||
proc `[]=`*[T](deq: var Deque[T], i: BackwardsIndex, x: T) {.inline.} =
|
||||
## Change the backwards indexed i-th element.
|
||||
deq[deq.len - int(i)] = x
|
||||
|
||||
iterator items*[T](deq: Deque[T]): T =
|
||||
## Yield every element of `deq`.
|
||||
var i = deq.head
|
||||
|
||||
Reference in New Issue
Block a user