mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 21:40:32 +00:00
Add deques.peekFirst/Last(var Deque[T]) -> var T (#13542)
* Add deques.peekFirst/Last(var Deque[T]) -> var T * Add changelog entry for deques.peekFirst/Last var T overloads * Add since annotation to peekFirst/peekLast Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
- The default hash for `Ordinal` has changed to something more bit-scrambling.
|
||||
`import hashes; proc hash(x: myInt): Hash = hashIdentity(x)` recovers the old
|
||||
one in an instantiation context while `-d:nimIntHash1` recovers it globally.
|
||||
- `deques.peekFirst` and `deques.peekLast` now have `var Deque[T] -> var T` overloads.
|
||||
- File handles created from high-level abstractions in the stdlib will no longer
|
||||
be inherited by child processes. In particular, these modules are affected:
|
||||
`system`, `nativesockets`, `net` and `selectors`.
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
## * `lists module <lists.html>`_ for singly and doubly linked lists and rings
|
||||
## * `channels module <channels.html>`_ for inter-thread communication
|
||||
|
||||
include system/inclrtl
|
||||
|
||||
import math
|
||||
|
||||
@@ -363,6 +364,46 @@ proc peekLast*[T](deq: Deque[T]): T {.inline.} =
|
||||
emptyCheck(deq)
|
||||
result = deq.data[(deq.tail - 1) and deq.mask]
|
||||
|
||||
proc peekFirst*[T](deq: var Deque[T]): var T {.inline, since: (1, 3).} =
|
||||
## Returns the first element of `deq`, but does not remove it from the deque.
|
||||
##
|
||||
## See also:
|
||||
## * `addFirst proc <#addFirst,Deque[T],T>`_
|
||||
## * `addLast proc <#addLast,Deque[T],T>`_
|
||||
## * `peekLast proc <#peekLast,Deque[T]>`_
|
||||
## * `popFirst proc <#popFirst,Deque[T]>`_
|
||||
## * `popLast proc <#popLast,Deque[T]>`_
|
||||
runnableExamples:
|
||||
var a = initDeque[int]()
|
||||
for i in 1 .. 5:
|
||||
a.addLast(10*i)
|
||||
assert $a == "[10, 20, 30, 40, 50]"
|
||||
assert a.peekFirst == 10
|
||||
assert len(a) == 5
|
||||
|
||||
emptyCheck(deq)
|
||||
result = deq.data[deq.head]
|
||||
|
||||
proc peekLast*[T](deq: var Deque[T]): var T {.inline, since: (1, 3).} =
|
||||
## Returns the last element of `deq`, but does not remove it from the deque.
|
||||
##
|
||||
## See also:
|
||||
## * `addFirst proc <#addFirst,Deque[T],T>`_
|
||||
## * `addLast proc <#addLast,Deque[T],T>`_
|
||||
## * `peekFirst proc <#peekFirst,Deque[T]>`_
|
||||
## * `popFirst proc <#popFirst,Deque[T]>`_
|
||||
## * `popLast proc <#popLast,Deque[T]>`_
|
||||
runnableExamples:
|
||||
var a = initDeque[int]()
|
||||
for i in 1 .. 5:
|
||||
a.addLast(10*i)
|
||||
assert $a == "[10, 20, 30, 40, 50]"
|
||||
assert a.peekLast == 50
|
||||
assert len(a) == 5
|
||||
|
||||
emptyCheck(deq)
|
||||
result = deq.data[(deq.tail - 1) and deq.mask]
|
||||
|
||||
template destroy(x: untyped) =
|
||||
reset(x)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user