123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>std/deques</title>
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- Favicon -->
- <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
- <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
- <!-- CSS -->
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
- <!-- JS -->
- <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
- </head>
- <body>
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">std/deques</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-select-wrapper">
- <label for="theme-select">Theme: </label>
- <select id="theme-select" onchange="setTheme(this.value)">
- <option value="auto">🌗 Match OS</option>
- <option value="dark">🌑 Dark</option>
- <option value="light">🌕 Light</option>
- </select>
- </div>
- <div id="global-links">
- <ul class="simple-boot">
- <li><a href="manual.html">Manual</a></li>
- <li><a href="lib.html">Standard library</a></li>
- <li> <a id="indexLink" href="theindex.html">Index</a></li>
- <li><a href="compiler/theindex.html">Compiler docs</a></li>
- <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
- <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="search" id="searchInput"
- oninput="search()" />
- </div>
-
- <ul class="simple simple-toc" id="toc-list">
- <li><a class="reference" id="see-also_toc" href="#see-also">See also</a></li>
- <li>
- <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#Deque" title="Deque[T] = object">Deque</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#defaultInitialSize" title="defaultInitialSize = 4">defaultInitialSize</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">$
- <li><a class="reference" href="#%24%2CDeque%5BT%5D" title="`$`[T](deq: Deque[T]): string">`$`[T](deq: Deque[T]): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">==
- <li><a class="reference" href="#%3D%3D%2CDeque%5BT%5D%2CDeque%5BT%5D" title="`==`[T](deq1, deq2: Deque[T]): bool">`==`[T](deq1, deq2: Deque[T]): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">[]
- <li><a class="reference" href="#%5B%5D%2CDeque%5BT%5D%2CBackwardsIndex" title="`[]`[T](deq: Deque[T]; i: BackwardsIndex): lent T">`[]`[T](deq: Deque[T]; i: BackwardsIndex): lent T</a></li>
- <li><a class="reference" href="#%5B%5D%2CDeque%5BT%5D%2CNatural" title="`[]`[T](deq: Deque[T]; i: Natural): lent T">`[]`[T](deq: Deque[T]; i: Natural): lent T</a></li>
- <li><a class="reference" href="#%5B%5D%2CDeque%5BT%5D%2CBackwardsIndex_2" title="`[]`[T](deq: var Deque[T]; i: BackwardsIndex): var T">`[]`[T](deq: var Deque[T]; i: BackwardsIndex): var T</a></li>
- <li><a class="reference" href="#%5B%5D%2CDeque%5BT%5D%2CNatural_2" title="`[]`[T](deq: var Deque[T]; i: Natural): var T">`[]`[T](deq: var Deque[T]; i: Natural): var T</a></li>
- </ul>
- <ul class="simple nested-toc-section">[]=
- <li><a class="reference" href="#%5B%5D%3D%2CDeque%5BT%5D%2CBackwardsIndex%2CsinkT" title="`[]=`[T](deq: var Deque[T]; i: BackwardsIndex; x: sink T)">`[]=`[T](deq: var Deque[T]; i: BackwardsIndex; x: sink T)</a></li>
- <li><a class="reference" href="#%5B%5D%3D%2CDeque%5BT%5D%2CNatural%2CsinkT" title="`[]=`[T](deq: var Deque[T]; i: Natural; val: sink T)">`[]=`[T](deq: var Deque[T]; i: Natural; val: sink T)</a></li>
- </ul>
- <ul class="simple nested-toc-section">addFirst
- <li><a class="reference" href="#addFirst%2CDeque%5BT%5D%2CsinkT" title="addFirst[T](deq: var Deque[T]; item: sink T)">addFirst[T](deq: var Deque[T]; item: sink T)</a></li>
- </ul>
- <ul class="simple nested-toc-section">addLast
- <li><a class="reference" href="#addLast%2CDeque%5BT%5D%2CsinkT" title="addLast[T](deq: var Deque[T]; item: sink T)">addLast[T](deq: var Deque[T]; item: sink T)</a></li>
- </ul>
- <ul class="simple nested-toc-section">clear
- <li><a class="reference" href="#clear%2CDeque%5BT%5D" title="clear[T](deq: var Deque[T])">clear[T](deq: var Deque[T])</a></li>
- </ul>
- <ul class="simple nested-toc-section">contains
- <li><a class="reference" href="#contains%2CDeque%5BT%5D%2CT" title="contains[T](deq: Deque[T]; item: T): bool">contains[T](deq: Deque[T]; item: T): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">hash
- <li><a class="reference" href="#hash%2CDeque%5BT%5D" title="hash[T](deq: Deque[T]): Hash">hash[T](deq: Deque[T]): Hash</a></li>
- </ul>
- <ul class="simple nested-toc-section">initDeque
- <li><a class="reference" href="#initDeque%2Cint" title="initDeque[T](initialSize: int = defaultInitialSize): Deque[T]">initDeque[T](initialSize: int = defaultInitialSize): Deque[T]</a></li>
- </ul>
- <ul class="simple nested-toc-section">len
- <li><a class="reference" href="#len%2CDeque%5BT%5D" title="len[T](deq: Deque[T]): int">len[T](deq: Deque[T]): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekFirst
- <li><a class="reference" href="#peekFirst%2CDeque%5BT%5D" title="peekFirst[T](deq: Deque[T]): lent T">peekFirst[T](deq: Deque[T]): lent T</a></li>
- <li><a class="reference" href="#peekFirst%2CDeque%5BT%5D_2" title="peekFirst[T](deq: var Deque[T]): var T">peekFirst[T](deq: var Deque[T]): var T</a></li>
- </ul>
- <ul class="simple nested-toc-section">peekLast
- <li><a class="reference" href="#peekLast%2CDeque%5BT%5D" title="peekLast[T](deq: Deque[T]): lent T">peekLast[T](deq: Deque[T]): lent T</a></li>
- <li><a class="reference" href="#peekLast%2CDeque%5BT%5D_2" title="peekLast[T](deq: var Deque[T]): var T">peekLast[T](deq: var Deque[T]): var T</a></li>
- </ul>
- <ul class="simple nested-toc-section">popFirst
- <li><a class="reference" href="#popFirst%2CDeque%5BT%5D" title="popFirst[T](deq: var Deque[T]): T">popFirst[T](deq: var Deque[T]): T</a></li>
- </ul>
- <ul class="simple nested-toc-section">popLast
- <li><a class="reference" href="#popLast%2CDeque%5BT%5D" title="popLast[T](deq: var Deque[T]): T">popLast[T](deq: var Deque[T]): T</a></li>
- </ul>
- <ul class="simple nested-toc-section">shrink
- <li><a class="reference" href="#shrink%2CDeque%5BT%5D%2Cint%2Cint" title="shrink[T](deq: var Deque[T]; fromFirst = 0; fromLast = 0)">shrink[T](deq: var Deque[T]; fromFirst = 0; fromLast = 0)</a></li>
- </ul>
- <ul class="simple nested-toc-section">toDeque
- <li><a class="reference" href="#toDeque%2CopenArray%5BT%5D" title="toDeque[T](x: openArray[T]): Deque[T]">toDeque[T](x: openArray[T]): Deque[T]</a></li>
- </ul>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">items
- <li><a class="reference" href="#items.i%2CDeque%5BT%5D" title="items[T](deq: Deque[T]): lent T">items[T](deq: Deque[T]): lent T</a></li>
- </ul>
- <ul class="simple nested-toc-section">mitems
- <li><a class="reference" href="#mitems.i%2CDeque%5BT%5D" title="mitems[T](deq: var Deque[T]): var T">mitems[T](deq: var Deque[T]): var T</a></li>
- </ul>
- <ul class="simple nested-toc-section">pairs
- <li><a class="reference" href="#pairs.i%2CDeque%5BT%5D" title="pairs[T](deq: Deque[T]): tuple[key: int, val: T]">pairs[T](deq: Deque[T]): tuple[key: int, val: T]</a></li>
- </ul>
- </ul>
- </details>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L1" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
- <div id="tocRoot"></div>
-
- <p class="module-desc">An implementation of a <span id="deque_1">deque</span> (double-ended queue). The underlying implementation uses a <tt class="docutils literal"><span class="pre"><span class="Identifier">seq</span></span></tt>.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
- None of the procs that get an individual value from the deque should be used on an empty deque.</div>
- <p>If compiled with the <tt class="docutils literal"><span class="pre"><span class="Identifier">boundChecks</span></span></tt> option, those procs will raise an <tt class="docutils literal"><span class="pre"><span class="Identifier">IndexDefect</span></span></tt> on such access. This should not be relied upon, as <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="Identifier">d</span><span class="Punctuation">:</span><span class="Identifier">danger</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Operator">--</span><span class="Identifier">checks</span><span class="Punctuation">:</span><span class="Identifier">off</span></span></tt> will disable those checks and then the procs may return garbage or crash the program.</p>
- <p>As such, a check to see if the deque is empty is needed before any access, unless your program logic guarantees it indirectly.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">deques</span>
- <span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IndexDefect</span><span class="Punctuation">,</span> <span class="Identifier">echo</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">4</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">addLast</span><span class="Punctuation">(</span><span class="DecNumber">50</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 50]"</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">peekFirst</span> <span class="Operator">==</span> <span class="DecNumber">10</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">peekLast</span> <span class="Operator">==</span> <span class="DecNumber">50</span>
- <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">popFirst</span> <span class="Operator">==</span> <span class="DecNumber">10</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">popLast</span> <span class="Operator">==</span> <span class="DecNumber">50</span>
- <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">addFirst</span><span class="Punctuation">(</span><span class="DecNumber">11</span><span class="Punctuation">)</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">addFirst</span><span class="Punctuation">(</span><span class="DecNumber">22</span><span class="Punctuation">)</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">addFirst</span><span class="Punctuation">(</span><span class="DecNumber">33</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[33, 22, 11, 20, 30, 40]"</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">shrink</span><span class="Punctuation">(</span><span class="Identifier">fromFirst</span> <span class="Operator">=</span> <span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="Identifier">fromLast</span> <span class="Operator">=</span> <span class="DecNumber">2</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[22, 11, 20]"</span></pre>
- <h1><a class="toc-backref" id="see-also" href="#see-also">See also</a></h1><ul class="simple"><li><a class="reference external" href="lists.html">lists module</a> for singly and doubly linked lists and rings</li>
- </ul>
- </p>
- <div class="section" id="6">
- <h1><a class="toc-backref" href="#6">Imports</a></h1>
- <dl class="item">
- <a class="reference external" href="since.html">since</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="hashes.html">hashes</a>, <a class="reference external" href="math.html">math</a>
- </dl>
- </div>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="Deque">
- <dt><pre><a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
- <dd>
-
- <p>A double-ended queue backed with a ringed <tt class="docutils literal"><span class="pre"><span class="Identifier">seq</span></span></tt> buffer.</p>
- <p>To initialize an empty deque, use the <a class="reference external" href="#initDeque,int">initDeque proc</a>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L56" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L56" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="10">
- <h1><a class="toc-backref" href="#10">Consts</a></h1>
- <dl class="item">
- <div id="defaultInitialSize">
- <dt><pre><a href="deques.html#defaultInitialSize"><span class="Identifier">defaultInitialSize</span></a> <span class="Other">=</span> <span class="DecNumber">4</span></pre></dt>
- <dd>
-
-
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L72" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L72" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <div id="$-procs-all">
- <div id="$,Deque[T]">
- <dt><pre><span class="Keyword">proc</span> <a href="#%24%2CDeque%5BT%5D"><span class="Identifier">`$`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
- <dd>
-
- Turns a deque into its string representation.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L444" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L444" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="==-procs-all">
- <div id="==,Deque[T],Deque[T]">
- <dt><pre><span class="Keyword">func</span> <a href="#%3D%3D%2CDeque%5BT%5D%2CDeque%5BT%5D"><span class="Identifier">`==`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq1</span><span class="Other">,</span> <span class="Identifier">deq2</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a></pre></dt>
- <dd>
-
- The <tt class="docutils literal"><span class="pre"><span class="Operator">==</span></span></tt> operator for Deque. Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if both deques contains the same values in the same order.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">initDeque</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">addFirst</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">addFirst</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">)</span>
- <span class="Identifier">b</span><span class="Operator">.</span><span class="Identifier">addLast</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">)</span>
- <span class="Identifier">b</span><span class="Operator">.</span><span class="Identifier">addLast</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
- <span class="Identifier">doAssert</span> <span class="Identifier">a</span> <span class="Operator">==</span> <span class="Identifier">b</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L456" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L456" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="[]-procs-all">
- <div id="[],Deque[T],BackwardsIndex">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CDeque%5BT%5D%2CBackwardsIndex"><span class="Identifier">`[]`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#BackwardsIndex"><span class="Identifier">BackwardsIndex</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- <p>Accesses the backwards indexed <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>-th element.</p>
- <p><tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span></span></tt> is the last element.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">50</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">4</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">20</span>
- <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IndexDefect</span><span class="Punctuation">,</span> <span class="Identifier">echo</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">9</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L152" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L152" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="[],Deque[T],Natural">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CDeque%5BT%5D%2CNatural"><span class="Identifier">`[]`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- Accesses the <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>-th element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">10</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">40</span>
- <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">IndexDefect</span><span class="Punctuation">,</span> <span class="Identifier">echo</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">8</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L118" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L118" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="[],Deque[T],BackwardsIndex_2">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CDeque%5BT%5D%2CBackwardsIndex_2"><span class="Identifier">`[]`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#BackwardsIndex"><span class="Identifier">BackwardsIndex</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- <p>Accesses the backwards indexed <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>-th element and returns a mutable reference to it.</p>
- <p><tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span></span></tt> is the last element.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">inc</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">51</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L165" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L165" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="[],Deque[T],Natural_2">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CDeque%5BT%5D%2CNatural_2"><span class="Identifier">`[]`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- Accesses the <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>-th element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt> and returns a mutable reference to it.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">inc</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">11</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L129" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L129" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="[]=-procs-all">
- <div id="[]=,Deque[T],BackwardsIndex,sinkT">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%3D%2CDeque%5BT%5D%2CBackwardsIndex%2CsinkT"><span class="Identifier">`[]=`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#BackwardsIndex"><span class="Identifier">BackwardsIndex</span></a><span class="Other">;</span> <span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <span class="Identifier">T</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- <p>Sets the backwards indexed <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>-th element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt>.</p>
- <p><tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span></span></tt> is the last element.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">a</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="DecNumber">99</span>
- <span class="Identifier">a</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">3</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="DecNumber">77</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 77, 40, 99]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L178" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L178" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="[]=,Deque[T],Natural,sinkT">
- <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%3D%2CDeque%5BT%5D%2CNatural%2CsinkT"><span class="Identifier">`[]=`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">;</span> <span class="Identifier">val</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <span class="Identifier">T</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- Sets the <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>-th element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">val</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="DecNumber">99</span>
- <span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="DecNumber">66</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[99, 20, 30, 66, 50]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L140" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L140" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="addFirst-procs-all">
- <div id="addFirst,Deque[T],sinkT">
- <dt><pre><span class="Keyword">proc</span> <a href="#addFirst%2CDeque%5BT%5D%2CsinkT"><span class="Identifier">addFirst</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">item</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <span class="Identifier">T</span><span class="Other">)</span></pre></dt>
- <dd>
-
- <p>Adds an <tt class="docutils literal"><span class="pre"><span class="Identifier">item</span></span></tt> to the beginning of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#addLast,Deque[T],sinkT">addLast proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">initDeque</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">5</span><span class="Punctuation">:</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">addFirst</span><span class="Punctuation">(</span><span class="DecNumber">10</span> <span class="Operator">*</span> <span class="Identifier">i</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[50, 40, 30, 20, 10]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L262" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L262" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="addLast-procs-all">
- <div id="addLast,Deque[T],sinkT">
- <dt><pre><span class="Keyword">proc</span> <a href="#addLast%2CDeque%5BT%5D%2CsinkT"><span class="Identifier">addLast</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">item</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <span class="Identifier">T</span><span class="Other">)</span></pre></dt>
- <dd>
-
- <p>Adds an <tt class="docutils literal"><span class="pre"><span class="Identifier">item</span></span></tt> to the end of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#addFirst,Deque[T],sinkT">addFirst proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">initDeque</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
- <span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">5</span><span class="Punctuation">:</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">addLast</span><span class="Punctuation">(</span><span class="DecNumber">10</span> <span class="Operator">*</span> <span class="Identifier">i</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 50]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L277" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L277" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="clear-procs-all">
- <div id="clear,Deque[T]">
- <dt><pre><span class="Keyword">proc</span> <a href="#clear%2CDeque%5BT%5D"><span class="Identifier">clear</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- <p>Resets the deque so that it is empty.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#shrink,Deque[T],int,int">shrink proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 50]"</span>
- <span class="Identifier">clear</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L401" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L401" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="contains-procs-all">
- <div id="contains,Deque[T],T">
- <dt><pre><span class="Keyword">proc</span> <a href="#contains%2CDeque%5BT%5D%2CT"><span class="Identifier">contains</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">item</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- <p>Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">item</span></span></tt> is in <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt> or false if not found.</p>
- <p>Usually used via the <tt class="docutils literal"><span class="pre"><span class="Keyword">in</span></span></tt> operator. It is the equivalent of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span><span class="Operator">.</span><span class="Identifier">find</span><span class="Punctuation">(</span><span class="Identifier">item</span><span class="Punctuation">)</span> <span class="Operator">>=</span> <span class="DecNumber">0</span></span></tt>.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">q</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">7</span><span class="Punctuation">,</span> <span class="DecNumber">9</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="DecNumber">7</span> <span class="Keyword">in</span> <span class="Identifier">q</span>
- <span class="Identifier">assert</span> <span class="Identifier">q</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="DecNumber">7</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="DecNumber">8</span> <span class="Keyword">notin</span> <span class="Identifier">q</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L232" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L232" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="hash-procs-all">
- <div id="hash,Deque[T]">
- <dt><pre><span class="Keyword">func</span> <a href="#hash%2CDeque%5BT%5D"><span class="Identifier">hash</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="hashes.html#Hash"><span class="Identifier">Hash</span></a></pre></dt>
- <dd>
-
- Hashing of Deque.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L476" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L476" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="initDeque-procs-all">
- <div id="initDeque,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#initDeque%2Cint"><span class="Identifier">initDeque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">initialSize</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Other">=</span> <span class="Identifier">defaultInitialSize</span><span class="Other">)</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span></pre></dt>
- <dd>
-
- <p>Creates a new empty deque.</p>
- <p>Optionally, the initial capacity can be reserved via <tt class="docutils literal"><span class="pre"><span class="Identifier">initialSize</span></span></tt> as a performance optimization (default: <a class="reference external" href="#defaultInitialSize">defaultInitialSize</a>). The length of a newly created deque will still be 0.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#toDeque,openArray[T]">toDeque proc</a></li>
- </ul>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L85" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L85" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="len-procs-all">
- <div id="len,Deque[T]">
- <dt><pre><span class="Keyword">func</span> <a href="#len%2CDeque%5BT%5D"><span class="Identifier">len</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- Returns the number of elements of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L98" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L98" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekFirst-procs-all">
- <div id="peekFirst,Deque[T]">
- <dt><pre><span class="Keyword">proc</span> <a href="#peekFirst%2CDeque%5BT%5D"><span class="Identifier">peekFirst</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- <p>Returns the first element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>, but does not remove it from the deque.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#peekFirst,Deque[T]_2">peekFirst proc</a> which returns a mutable reference</li>
- <li><a class="reference external" href="#peekLast,Deque[T]">peekLast proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 50]"</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">peekFirst</span> <span class="Operator">==</span> <span class="DecNumber">10</span>
- <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L306" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L306" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="peekFirst,Deque[T]_2">
- <dt><pre><span class="Keyword">proc</span> <a href="#peekFirst%2CDeque%5BT%5D_2"><span class="Identifier">peekFirst</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- <p>Returns a mutable reference to the first element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>, but does not remove it from the deque.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#peekFirst,Deque[T]">peekFirst proc</a></li>
- <li><a class="reference external" href="#peekLast,Deque[T]_2">peekLast proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">peekFirst</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">=</span> <span class="DecNumber">99</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[99, 20, 30, 40, 50]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L336" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L336" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="peekLast-procs-all">
- <div id="peekLast,Deque[T]">
- <dt><pre><span class="Keyword">proc</span> <a href="#peekLast%2CDeque%5BT%5D"><span class="Identifier">peekLast</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- <p>Returns the last element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>, but does not remove it from the deque.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#peekLast,Deque[T]_2">peekLast proc</a> which returns a mutable reference</li>
- <li><a class="reference external" href="#peekFirst,Deque[T]">peekFirst proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 50]"</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">peekLast</span> <span class="Operator">==</span> <span class="DecNumber">50</span>
- <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L321" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L321" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="peekLast,Deque[T]_2">
- <dt><pre><span class="Keyword">proc</span> <a href="#peekLast%2CDeque%5BT%5D_2"><span class="Identifier">peekLast</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
- <dd>
-
- <p>Returns a mutable reference to the last element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>, but does not remove it from the deque.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#peekFirst,Deque[T]_2">peekFirst proc</a></li>
- <li><a class="reference external" href="#peekLast,Deque[T]">peekLast proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">peekLast</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">=</span> <span class="DecNumber">99</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 99]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L351" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L351" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="popFirst-procs-all">
- <div id="popFirst,Deque[T]">
- <dt><pre><span class="Keyword">proc</span> <a href="#popFirst%2CDeque%5BT%5D"><span class="Identifier">popFirst</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span class="Identifier">discardable</span>.}</pre></dt>
- <dd>
-
- <p>Removes and returns the first element of the <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.</p>
- <p>See also:</p>
- <ul class="simple"><li><a class="reference external" href="#popLast,Deque[T]">popLast proc</a></li>
- <li><a class="reference external" href="#shrink,Deque[T],int,int">shrink proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 50]"</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">popFirst</span> <span class="Operator">==</span> <span class="DecNumber">10</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[20, 30, 40, 50]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L369" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L369" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="popLast-procs-all">
- <div id="popLast,Deque[T]">
- <dt><pre><span class="Keyword">proc</span> <a href="#popLast%2CDeque%5BT%5D"><span class="Identifier">popLast</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span class="Identifier">discardable</span>.}</pre></dt>
- <dd>
-
- <p>Removes and returns the last element of the <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#popFirst,Deque[T]">popFirst proc</a></li>
- <li><a class="reference external" href="#shrink,Deque[T],int,int">shrink proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 50]"</span>
- <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">popLast</span> <span class="Operator">==</span> <span class="DecNumber">50</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L385" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L385" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="shrink-procs-all">
- <div id="shrink,Deque[T],int,int">
- <dt><pre><span class="Keyword">proc</span> <a href="#shrink%2CDeque%5BT%5D%2Cint%2Cint"><span class="Identifier">shrink</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">fromFirst</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">;</span> <span class="Identifier">fromLast</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span></pre></dt>
- <dd>
-
- <p>Removes <tt class="docutils literal"><span class="pre"><span class="Identifier">fromFirst</span></span></tt> elements from the front of the deque and <tt class="docutils literal"><span class="pre"><span class="Identifier">fromLast</span></span></tt> elements from the back.</p>
- <p>If the supplied number of elements exceeds the total number of elements in the deque, the deque will remain empty.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#clear,Deque[T]">clear proc</a></li>
- <li><a class="reference external" href="#popFirst,Deque[T]">popFirst proc</a></li>
- <li><a class="reference external" href="#popLast,Deque[T]">popLast proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 50]"</span>
- <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">shrink</span><span class="Punctuation">(</span><span class="Identifier">fromFirst</span> <span class="Operator">=</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="Identifier">fromLast</span> <span class="Operator">=</span> <span class="DecNumber">1</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[30, 40]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L415" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L415" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="toDeque-procs-all">
- <div id="toDeque,openArray[T]">
- <dt><pre><span class="Keyword">proc</span> <a href="#toDeque%2CopenArray%5BT%5D"><span class="Identifier">toDeque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span></pre></dt>
- <dd>
-
- <p>Creates a new deque that contains the elements of <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> (in the same order).</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#initDeque,int">initDeque proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toDeque</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">7</span><span class="Punctuation">,</span> <span class="DecNumber">8</span><span class="Punctuation">,</span> <span class="DecNumber">9</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
- <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[7, 8, 9]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L292" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L292" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- <div class="section" id="15">
- <h1><a class="toc-backref" href="#15">Iterators</a></h1>
- <dl class="item">
- <div id="items-iterators-all">
- <div id="items.i,Deque[T]">
- <dt><pre><span class="Keyword">iterator</span> <a href="#items.i%2CDeque%5BT%5D"><span class="Identifier">items</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <span class="Identifier">T</span></pre></dt>
- <dd>
-
- <p>Yields every element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#mitems.i,Deque[T]">mitems iterator</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">from</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sequtils</span> <span class="Keyword">import</span> <span class="Identifier">toSeq</span>
- <span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Identifier">toSeq</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">items</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L192" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L192" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="mitems-iterators-all">
- <div id="mitems.i,Deque[T]">
- <dt><pre><span class="Keyword">iterator</span> <a href="#mitems.i%2CDeque%5BT%5D"><span class="Identifier">mitems</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span></pre></dt>
- <dd>
-
- <p>Yields every element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>, which can be modified.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#items.i,Deque[T]">items iterator</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">,</span> <span class="DecNumber">40</span><span class="Punctuation">,</span> <span class="DecNumber">50</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[10, 20, 30, 40, 50]"</span>
- <span class="Keyword">for</span> <span class="Identifier">x</span> <span class="Keyword">in</span> <span class="Identifier">mitems</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
- <span class="Identifier">x</span> <span class="Operator">=</span> <span class="DecNumber">5</span> <span class="Operator">*</span> <span class="Identifier">x</span> <span class="Operator">-</span> <span class="DecNumber">1</span>
- <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">"[49, 99, 149, 199, 249]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L206" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L206" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="pairs-iterators-all">
- <div id="pairs.i,Deque[T]">
- <dt><pre><span class="Keyword">iterator</span> <a href="#pairs.i%2CDeque%5BT%5D"><span class="Identifier">pairs</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">deq</span><span class="Other">:</span> <a href="deques.html#Deque"><span class="Identifier">Deque</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <span class="Identifier">val</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">]</span></pre></dt>
- <dd>
-
- Yields every <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">position</span><span class="Punctuation">,</span> <span class="Identifier">value</span><span class="Punctuation">)</span></span></tt>-pair of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">from</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">sequtils</span> <span class="Keyword">import</span> <span class="Identifier">toSeq</span>
- <span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toDeque</span>
- <span class="Identifier">assert</span> <span class="Identifier">toSeq</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">pairs</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">,</span> <span class="DecNumber">10</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">20</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">30</span><span class="Punctuation">)</span><span class="Punctuation">]</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L221" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L221" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- </div>
- </div>
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br>
- <small style="color: var(--hint);">Made with Nim. Generated: 2025-01-09 12:00:22 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|