deques.html 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/deques</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <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=="/>
  14. <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=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/deques</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li><a class="reference" id="see-also_toc" href="#see-also">See also</a></li>
  50. <li>
  51. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  52. </li>
  53. <li>
  54. <details open>
  55. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  56. <ul class="simple simple-toc-section">
  57. <li><a class="reference" href="#Deque" title="Deque[T] = object">Deque</a></li>
  58. </ul>
  59. </details>
  60. </li>
  61. <li>
  62. <details open>
  63. <summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
  64. <ul class="simple simple-toc-section">
  65. <li><a class="reference" href="#defaultInitialSize" title="defaultInitialSize = 4">defaultInitialSize</a></li>
  66. </ul>
  67. </details>
  68. </li>
  69. <li>
  70. <details open>
  71. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  72. <ul class="simple simple-toc-section">
  73. <ul class="simple nested-toc-section">$
  74. <li><a class="reference" href="#%24%2CDeque%5BT%5D" title="`$`[T](deq: Deque[T]): string">`$`[T](deq: Deque[T]): string</a></li>
  75. </ul>
  76. <ul class="simple nested-toc-section">==
  77. <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>
  78. </ul>
  79. <ul class="simple nested-toc-section">[]
  80. <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>
  81. <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>
  82. <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>
  83. <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>
  84. </ul>
  85. <ul class="simple nested-toc-section">[]=
  86. <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>
  87. <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>
  88. </ul>
  89. <ul class="simple nested-toc-section">addFirst
  90. <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>
  91. </ul>
  92. <ul class="simple nested-toc-section">addLast
  93. <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>
  94. </ul>
  95. <ul class="simple nested-toc-section">clear
  96. <li><a class="reference" href="#clear%2CDeque%5BT%5D" title="clear[T](deq: var Deque[T])">clear[T](deq: var Deque[T])</a></li>
  97. </ul>
  98. <ul class="simple nested-toc-section">contains
  99. <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>
  100. </ul>
  101. <ul class="simple nested-toc-section">hash
  102. <li><a class="reference" href="#hash%2CDeque%5BT%5D" title="hash[T](deq: Deque[T]): Hash">hash[T](deq: Deque[T]): Hash</a></li>
  103. </ul>
  104. <ul class="simple nested-toc-section">initDeque
  105. <li><a class="reference" href="#initDeque%2Cint" title="initDeque[T](initialSize: int = defaultInitialSize): Deque[T]">initDeque[T](initialSize: int = defaultInitialSize): Deque[T]</a></li>
  106. </ul>
  107. <ul class="simple nested-toc-section">len
  108. <li><a class="reference" href="#len%2CDeque%5BT%5D" title="len[T](deq: Deque[T]): int">len[T](deq: Deque[T]): int</a></li>
  109. </ul>
  110. <ul class="simple nested-toc-section">peekFirst
  111. <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>
  112. <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>
  113. </ul>
  114. <ul class="simple nested-toc-section">peekLast
  115. <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>
  116. <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>
  117. </ul>
  118. <ul class="simple nested-toc-section">popFirst
  119. <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>
  120. </ul>
  121. <ul class="simple nested-toc-section">popLast
  122. <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>
  123. </ul>
  124. <ul class="simple nested-toc-section">shrink
  125. <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>
  126. </ul>
  127. <ul class="simple nested-toc-section">toDeque
  128. <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>
  129. </ul>
  130. </ul>
  131. </details>
  132. </li>
  133. <li>
  134. <details open>
  135. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  136. <ul class="simple simple-toc-section">
  137. <ul class="simple nested-toc-section">items
  138. <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>
  139. </ul>
  140. <ul class="simple nested-toc-section">mitems
  141. <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>
  142. </ul>
  143. <ul class="simple nested-toc-section">pairs
  144. <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>
  145. </ul>
  146. </ul>
  147. </details>
  148. </li>
  149. </ul>
  150. </div>
  151. <div class="nine columns" id="content">
  152. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  153. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  154. <div id="tocRoot"></div>
  155. <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>
  156. None of the procs that get an individual value from the deque should be used on an empty deque.</div>
  157. <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>
  158. <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>
  159. <p><strong class="examples_text">Example:</strong></p>
  160. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">deques</span>
  161. <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>
  162. <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>
  163. <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>
  164. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 50]&quot;</span>
  165. <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>
  166. <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>
  167. <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>
  168. <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>
  169. <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>
  170. <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>
  171. <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>
  172. <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>
  173. <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>
  174. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[33, 22, 11, 20, 30, 40]&quot;</span>
  175. <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>
  176. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[22, 11, 20]&quot;</span></pre>
  177. <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>
  178. </ul>
  179. </p>
  180. <div class="section" id="6">
  181. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  182. <dl class="item">
  183. <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>
  184. </dl>
  185. </div>
  186. <div class="section" id="7">
  187. <h1><a class="toc-backref" href="#7">Types</a></h1>
  188. <dl class="item">
  189. <div id="Deque">
  190. <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>
  191. <dd>
  192. <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>
  193. <p>To initialize an empty deque, use the <a class="reference external" href="#initDeque,int">initDeque proc</a>.</p>
  194. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L56" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  195. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L56" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  196. </dd>
  197. </div>
  198. </dl>
  199. </div>
  200. <div class="section" id="10">
  201. <h1><a class="toc-backref" href="#10">Consts</a></h1>
  202. <dl class="item">
  203. <div id="defaultInitialSize">
  204. <dt><pre><a href="deques.html#defaultInitialSize"><span class="Identifier">defaultInitialSize</span></a> <span class="Other">=</span> <span class="DecNumber">4</span></pre></dt>
  205. <dd>
  206. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L72" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  207. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L72" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  208. </dd>
  209. </div>
  210. </dl>
  211. </div>
  212. <div class="section" id="12">
  213. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  214. <dl class="item">
  215. <div id="$-procs-all">
  216. <div id="$,Deque[T]">
  217. <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>
  218. <dd>
  219. Turns a deque into its string representation.
  220. <p><strong class="examples_text">Example:</strong></p>
  221. <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>
  222. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30]&quot;</span></pre>
  223. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L444" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  224. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L444" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  225. </dd>
  226. </div>
  227. </div>
  228. <div id="==-procs-all">
  229. <div id="==,Deque[T],Deque[T]">
  230. <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>
  231. <dd>
  232. 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.
  233. <p><strong class="examples_text">Example:</strong></p>
  234. <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>
  235. <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>
  236. <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>
  237. <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>
  238. <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>
  239. <span class="Identifier">doAssert</span> <span class="Identifier">a</span> <span class="Operator">==</span> <span class="Identifier">b</span></pre>
  240. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L456" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  241. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L456" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  242. </dd>
  243. </div>
  244. </div>
  245. <div id="[]-procs-all">
  246. <div id="[],Deque[T],BackwardsIndex">
  247. <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>
  248. <dd>
  249. <p>Accesses the backwards indexed <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>-th element.</p>
  250. <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>
  251. <p><strong class="examples_text">Example:</strong></p>
  252. <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>
  253. <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>
  254. <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>
  255. <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>
  256. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L152" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  257. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L152" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  258. </dd>
  259. </div>
  260. <div id="[],Deque[T],Natural">
  261. <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>
  262. <dd>
  263. 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>.
  264. <p><strong class="examples_text">Example:</strong></p>
  265. <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>
  266. <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>
  267. <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>
  268. <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>
  269. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L118" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  270. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L118" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  271. </dd>
  272. </div>
  273. <div id="[],Deque[T],BackwardsIndex_2">
  274. <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>
  275. <dd>
  276. <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>
  277. <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>
  278. <p><strong class="examples_text">Example:</strong></p>
  279. <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>
  280. <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>
  281. <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>
  282. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L165" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  283. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L165" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  284. </dd>
  285. </div>
  286. <div id="[],Deque[T],Natural_2">
  287. <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>
  288. <dd>
  289. 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.
  290. <p><strong class="examples_text">Example:</strong></p>
  291. <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>
  292. <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>
  293. <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>
  294. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L129" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  295. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L129" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  296. </dd>
  297. </div>
  298. </div>
  299. <div id="[]=-procs-all">
  300. <div id="[]=,Deque[T],BackwardsIndex,sinkT">
  301. <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>
  302. <dd>
  303. <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>
  304. <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>
  305. <p><strong class="examples_text">Example:</strong></p>
  306. <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>
  307. <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>
  308. <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>
  309. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 77, 40, 99]&quot;</span></pre>
  310. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L178" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  311. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L178" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  312. </dd>
  313. </div>
  314. <div id="[]=,Deque[T],Natural,sinkT">
  315. <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>
  316. <dd>
  317. 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>.
  318. <p><strong class="examples_text">Example:</strong></p>
  319. <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>
  320. <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>
  321. <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>
  322. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[99, 20, 30, 66, 50]&quot;</span></pre>
  323. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L140" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  324. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L140" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  325. </dd>
  326. </div>
  327. </div>
  328. <div id="addFirst-procs-all">
  329. <div id="addFirst,Deque[T],sinkT">
  330. <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>
  331. <dd>
  332. <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>
  333. <p><strong>See also:</strong></p>
  334. <ul class="simple"><li><a class="reference external" href="#addLast,Deque[T],sinkT">addLast proc</a></li>
  335. </ul>
  336. <p><strong class="examples_text">Example:</strong></p>
  337. <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>
  338. <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>
  339. <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>
  340. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[50, 40, 30, 20, 10]&quot;</span></pre>
  341. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L262" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  342. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L262" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  343. </dd>
  344. </div>
  345. </div>
  346. <div id="addLast-procs-all">
  347. <div id="addLast,Deque[T],sinkT">
  348. <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>
  349. <dd>
  350. <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>
  351. <p><strong>See also:</strong></p>
  352. <ul class="simple"><li><a class="reference external" href="#addFirst,Deque[T],sinkT">addFirst proc</a></li>
  353. </ul>
  354. <p><strong class="examples_text">Example:</strong></p>
  355. <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>
  356. <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>
  357. <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>
  358. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 50]&quot;</span></pre>
  359. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L277" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  360. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L277" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  361. </dd>
  362. </div>
  363. </div>
  364. <div id="clear-procs-all">
  365. <div id="clear,Deque[T]">
  366. <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>
  367. <dd>
  368. <p>Resets the deque so that it is empty.</p>
  369. <p><strong>See also:</strong></p>
  370. <ul class="simple"><li><a class="reference external" href="#shrink,Deque[T],int,int">shrink proc</a></li>
  371. </ul>
  372. <p><strong class="examples_text">Example:</strong></p>
  373. <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>
  374. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 50]&quot;</span>
  375. <span class="Identifier">clear</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span>
  376. <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>
  377. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L401" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  378. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L401" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  379. </dd>
  380. </div>
  381. </div>
  382. <div id="contains-procs-all">
  383. <div id="contains,Deque[T],T">
  384. <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>
  385. <dd>
  386. <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>
  387. <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">&gt;=</span> <span class="DecNumber">0</span></span></tt>.</p>
  388. <p><strong class="examples_text">Example:</strong></p>
  389. <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>
  390. <span class="Identifier">assert</span> <span class="DecNumber">7</span> <span class="Keyword">in</span> <span class="Identifier">q</span>
  391. <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>
  392. <span class="Identifier">assert</span> <span class="DecNumber">8</span> <span class="Keyword">notin</span> <span class="Identifier">q</span></pre>
  393. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L232" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  394. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L232" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  395. </dd>
  396. </div>
  397. </div>
  398. <div id="hash-procs-all">
  399. <div id="hash,Deque[T]">
  400. <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>
  401. <dd>
  402. Hashing of Deque.
  403. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L476" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  404. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L476" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  405. </dd>
  406. </div>
  407. </div>
  408. <div id="initDeque-procs-all">
  409. <div id="initDeque,int">
  410. <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>
  411. <dd>
  412. <p>Creates a new empty deque.</p>
  413. <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>
  414. <p><strong>See also:</strong></p>
  415. <ul class="simple"><li><a class="reference external" href="#toDeque,openArray[T]">toDeque proc</a></li>
  416. </ul>
  417. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L85" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  418. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L85" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  419. </dd>
  420. </div>
  421. </div>
  422. <div id="len-procs-all">
  423. <div id="len,Deque[T]">
  424. <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>
  425. <dd>
  426. Returns the number of elements of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.
  427. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L98" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  428. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L98" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  429. </dd>
  430. </div>
  431. </div>
  432. <div id="peekFirst-procs-all">
  433. <div id="peekFirst,Deque[T]">
  434. <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>
  435. <dd>
  436. <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>
  437. <p><strong>See also:</strong></p>
  438. <ul class="simple"><li><a class="reference external" href="#peekFirst,Deque[T]_2">peekFirst proc</a> which returns a mutable reference</li>
  439. <li><a class="reference external" href="#peekLast,Deque[T]">peekLast proc</a></li>
  440. </ul>
  441. <p><strong class="examples_text">Example:</strong></p>
  442. <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>
  443. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 50]&quot;</span>
  444. <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>
  445. <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>
  446. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L306" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  447. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L306" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  448. </dd>
  449. </div>
  450. <div id="peekFirst,Deque[T]_2">
  451. <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>
  452. <dd>
  453. <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>
  454. <p><strong>See also:</strong></p>
  455. <ul class="simple"><li><a class="reference external" href="#peekFirst,Deque[T]">peekFirst proc</a></li>
  456. <li><a class="reference external" href="#peekLast,Deque[T]_2">peekLast proc</a></li>
  457. </ul>
  458. <p><strong class="examples_text">Example:</strong></p>
  459. <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>
  460. <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>
  461. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[99, 20, 30, 40, 50]&quot;</span></pre>
  462. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L336" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  463. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L336" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  464. </dd>
  465. </div>
  466. </div>
  467. <div id="peekLast-procs-all">
  468. <div id="peekLast,Deque[T]">
  469. <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>
  470. <dd>
  471. <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>
  472. <p><strong>See also:</strong></p>
  473. <ul class="simple"><li><a class="reference external" href="#peekLast,Deque[T]_2">peekLast proc</a> which returns a mutable reference</li>
  474. <li><a class="reference external" href="#peekFirst,Deque[T]">peekFirst proc</a></li>
  475. </ul>
  476. <p><strong class="examples_text">Example:</strong></p>
  477. <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>
  478. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 50]&quot;</span>
  479. <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>
  480. <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>
  481. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L321" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  482. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L321" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  483. </dd>
  484. </div>
  485. <div id="peekLast,Deque[T]_2">
  486. <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>
  487. <dd>
  488. <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>
  489. <p><strong>See also:</strong></p>
  490. <ul class="simple"><li><a class="reference external" href="#peekFirst,Deque[T]_2">peekFirst proc</a></li>
  491. <li><a class="reference external" href="#peekLast,Deque[T]">peekLast proc</a></li>
  492. </ul>
  493. <p><strong class="examples_text">Example:</strong></p>
  494. <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>
  495. <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>
  496. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 99]&quot;</span></pre>
  497. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L351" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  498. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L351" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  499. </dd>
  500. </div>
  501. </div>
  502. <div id="popFirst-procs-all">
  503. <div id="popFirst,Deque[T]">
  504. <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>
  505. <dd>
  506. <p>Removes and returns the first element of the <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.</p>
  507. <p>See also:</p>
  508. <ul class="simple"><li><a class="reference external" href="#popLast,Deque[T]">popLast proc</a></li>
  509. <li><a class="reference external" href="#shrink,Deque[T],int,int">shrink proc</a></li>
  510. </ul>
  511. <p><strong class="examples_text">Example:</strong></p>
  512. <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>
  513. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 50]&quot;</span>
  514. <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>
  515. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[20, 30, 40, 50]&quot;</span></pre>
  516. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L369" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  517. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L369" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  518. </dd>
  519. </div>
  520. </div>
  521. <div id="popLast-procs-all">
  522. <div id="popLast,Deque[T]">
  523. <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>
  524. <dd>
  525. <p>Removes and returns the last element of the <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.</p>
  526. <p><strong>See also:</strong></p>
  527. <ul class="simple"><li><a class="reference external" href="#popFirst,Deque[T]">popFirst proc</a></li>
  528. <li><a class="reference external" href="#shrink,Deque[T],int,int">shrink proc</a></li>
  529. </ul>
  530. <p><strong class="examples_text">Example:</strong></p>
  531. <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>
  532. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 50]&quot;</span>
  533. <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>
  534. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40]&quot;</span></pre>
  535. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L385" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  536. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L385" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  537. </dd>
  538. </div>
  539. </div>
  540. <div id="shrink-procs-all">
  541. <div id="shrink,Deque[T],int,int">
  542. <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>
  543. <dd>
  544. <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>
  545. <p>If the supplied number of elements exceeds the total number of elements in the deque, the deque will remain empty.</p>
  546. <p><strong>See also:</strong></p>
  547. <ul class="simple"><li><a class="reference external" href="#clear,Deque[T]">clear proc</a></li>
  548. <li><a class="reference external" href="#popFirst,Deque[T]">popFirst proc</a></li>
  549. <li><a class="reference external" href="#popLast,Deque[T]">popLast proc</a></li>
  550. </ul>
  551. <p><strong class="examples_text">Example:</strong></p>
  552. <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>
  553. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 50]&quot;</span>
  554. <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>
  555. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[30, 40]&quot;</span></pre>
  556. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L415" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  557. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L415" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  558. </dd>
  559. </div>
  560. </div>
  561. <div id="toDeque-procs-all">
  562. <div id="toDeque,openArray[T]">
  563. <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>
  564. <dd>
  565. <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>
  566. <p><strong>See also:</strong></p>
  567. <ul class="simple"><li><a class="reference external" href="#initDeque,int">initDeque proc</a></li>
  568. </ul>
  569. <p><strong class="examples_text">Example:</strong></p>
  570. <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>
  571. <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>
  572. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[7, 8, 9]&quot;</span></pre>
  573. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L292" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  574. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L292" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  575. </dd>
  576. </div>
  577. </div>
  578. </dl>
  579. </div>
  580. <div class="section" id="15">
  581. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  582. <dl class="item">
  583. <div id="items-iterators-all">
  584. <div id="items.i,Deque[T]">
  585. <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>
  586. <dd>
  587. <p>Yields every element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>.</p>
  588. <p><strong>See also:</strong></p>
  589. <ul class="simple"><li><a class="reference external" href="#mitems.i,Deque[T]">mitems iterator</a></li>
  590. </ul>
  591. <p><strong class="examples_text">Example:</strong></p>
  592. <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>
  593. <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>
  594. <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>
  595. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L192" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  596. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L192" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  597. </dd>
  598. </div>
  599. </div>
  600. <div id="mitems-iterators-all">
  601. <div id="mitems.i,Deque[T]">
  602. <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>
  603. <dd>
  604. <p>Yields every element of <tt class="docutils literal"><span class="pre"><span class="Identifier">deq</span></span></tt>, which can be modified.</p>
  605. <p><strong>See also:</strong></p>
  606. <ul class="simple"><li><a class="reference external" href="#items.i,Deque[T]">items iterator</a></li>
  607. </ul>
  608. <p><strong class="examples_text">Example:</strong></p>
  609. <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>
  610. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[10, 20, 30, 40, 50]&quot;</span>
  611. <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>
  612. <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>
  613. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="StringLit">&quot;[49, 99, 149, 199, 249]&quot;</span></pre>
  614. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L206" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  615. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L206" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  616. </dd>
  617. </div>
  618. </div>
  619. <div id="pairs-iterators-all">
  620. <div id="pairs.i,Deque[T]">
  621. <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>
  622. <dd>
  623. 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>.
  624. <p><strong class="examples_text">Example:</strong></p>
  625. <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>
  626. <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>
  627. <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>
  628. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/deques.nim#L221" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  629. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/deques.nim#L221" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  630. </dd>
  631. </div>
  632. </div>
  633. </dl>
  634. </div>
  635. </div>
  636. </div>
  637. <div class="twelve-columns footer">
  638. <span class="nim-sprite"></span>
  639. <br>
  640. <small style="color: var(--hint);">Made with Nim. Generated: 2025-01-09 12:00:22 UTC</small>
  641. </div>
  642. </div>
  643. </div>
  644. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  645. </body>
  646. </html>