diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2019-01-13 13:06:16 +0000 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-01-13 14:06:16 +0100 |
commit | d740a5b79a004632f90da6702cd351ae214e273d (patch) | |
tree | 269f33ddb0bfebeba598ce4f8a3fa3a4d7225a77 /lib/pure | |
parent | 796432ff9439a0d0137f342162d78cf11f2d27a5 (diff) | |
download | Nim-d740a5b79a004632f90da6702cd351ae214e273d.tar.gz |
Implements BackwardsIndex `[]` for deque. (#10105)
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/collections/deques.nim | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/pure/collections/deques.nim b/lib/pure/collections/deques.nim index e8342e208..5243b96a6 100644 --- a/lib/pure/collections/deques.nim +++ b/lib/pure/collections/deques.nim @@ -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 |