sets.html 160 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  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/sets</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/sets</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>
  50. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  51. </li>
  52. <li>
  53. <details open>
  54. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  55. <ul class="simple simple-toc-section">
  56. <li><a class="reference" href="#HashSet" title="HashSet[A] {..} = object">HashSet</a></li>
  57. <li><a class="reference" href="#OrderedSet" title="OrderedSet[A] {..} = object">OrderedSet</a></li>
  58. <li><a class="reference" href="#SomeSet" title="SomeSet[A] = HashSet[A] | OrderedSet[A]">SomeSet</a></li>
  59. </ul>
  60. </details>
  61. </li>
  62. <li>
  63. <details open>
  64. <summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
  65. <ul class="simple simple-toc-section">
  66. <li><a class="reference" href="#defaultInitialSize" title="defaultInitialSize = 64">defaultInitialSize</a></li>
  67. </ul>
  68. </details>
  69. </li>
  70. <li>
  71. <details open>
  72. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  73. <ul class="simple simple-toc-section">
  74. <ul class="simple nested-toc-section">$
  75. <li><a class="reference" href="#%24%2CHashSet%5BA%5D" title="`$`[A](s: HashSet[A]): string">`$`[A](s: HashSet[A]): string</a></li>
  76. <li><a class="reference" href="#%24%2COrderedSet%5BA%5D" title="`$`[A](s: OrderedSet[A]): string">`$`[A](s: OrderedSet[A]): string</a></li>
  77. </ul>
  78. <ul class="simple nested-toc-section">*
  79. <li><a class="reference" href="#%2A%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="`*`[A](s1, s2: HashSet[A]): HashSet[A]">`*`[A](s1, s2: HashSet[A]): HashSet[A]</a></li>
  80. </ul>
  81. <ul class="simple nested-toc-section">+
  82. <li><a class="reference" href="#%2B%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="`+`[A](s1, s2: HashSet[A]): HashSet[A]">`+`[A](s1, s2: HashSet[A]): HashSet[A]</a></li>
  83. </ul>
  84. <ul class="simple nested-toc-section">-
  85. <li><a class="reference" href="#-%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="`-`[A](s1, s2: HashSet[A]): HashSet[A]">`-`[A](s1, s2: HashSet[A]): HashSet[A]</a></li>
  86. </ul>
  87. <ul class="simple nested-toc-section">-+-
  88. <li><a class="reference" href="#-%2B-%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="`-+-`[A](s1, s2: HashSet[A]): HashSet[A]">`-+-`[A](s1, s2: HashSet[A]): HashSet[A]</a></li>
  89. </ul>
  90. <ul class="simple nested-toc-section"><
  91. <li><a class="reference" href="#%3C%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="`&lt;`[A](s, t: HashSet[A]): bool">`&lt;`[A](s, t: HashSet[A]): bool</a></li>
  92. </ul>
  93. <ul class="simple nested-toc-section"><=
  94. <li><a class="reference" href="#%3C%3D%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="`&lt;=`[A](s, t: HashSet[A]): bool">`&lt;=`[A](s, t: HashSet[A]): bool</a></li>
  95. </ul>
  96. <ul class="simple nested-toc-section">==
  97. <li><a class="reference" href="#%3D%3D%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="`==`[A](s, t: HashSet[A]): bool">`==`[A](s, t: HashSet[A]): bool</a></li>
  98. <li><a class="reference" href="#%3D%3D%2COrderedSet%5BA%5D%2COrderedSet%5BA%5D" title="`==`[A](s, t: OrderedSet[A]): bool">`==`[A](s, t: OrderedSet[A]): bool</a></li>
  99. </ul>
  100. <ul class="simple nested-toc-section">[]
  101. <li><a class="reference" href="#%5B%5D%2CHashSet%5BA%5D%2CA" title="`[]`[A](s: var HashSet[A]; key: A): var A">`[]`[A](s: var HashSet[A]; key: A): var A</a></li>
  102. </ul>
  103. <ul class="simple nested-toc-section">card
  104. <li><a class="reference" href="#card%2CHashSet%5BA%5D" title="card[A](s: HashSet[A]): int">card[A](s: HashSet[A]): int</a></li>
  105. <li><a class="reference" href="#card%2COrderedSet%5BA%5D" title="card[A](s: OrderedSet[A]): int">card[A](s: OrderedSet[A]): int</a></li>
  106. </ul>
  107. <ul class="simple nested-toc-section">clear
  108. <li><a class="reference" href="#clear%2CHashSet%5BA%5D" title="clear[A](s: var HashSet[A])">clear[A](s: var HashSet[A])</a></li>
  109. <li><a class="reference" href="#clear%2COrderedSet%5BA%5D" title="clear[A](s: var OrderedSet[A])">clear[A](s: var OrderedSet[A])</a></li>
  110. </ul>
  111. <ul class="simple nested-toc-section">contains
  112. <li><a class="reference" href="#contains%2CHashSet%5BA%5D%2CA" title="contains[A](s: HashSet[A]; key: A): bool">contains[A](s: HashSet[A]; key: A): bool</a></li>
  113. <li><a class="reference" href="#contains%2COrderedSet%5BA%5D%2CA" title="contains[A](s: OrderedSet[A]; key: A): bool">contains[A](s: OrderedSet[A]; key: A): bool</a></li>
  114. </ul>
  115. <ul class="simple nested-toc-section">containsOrIncl
  116. <li><a class="reference" href="#containsOrIncl%2CHashSet%5BA%5D%2CA" title="containsOrIncl[A](s: var HashSet[A]; key: A): bool">containsOrIncl[A](s: var HashSet[A]; key: A): bool</a></li>
  117. <li><a class="reference" href="#containsOrIncl%2COrderedSet%5BA%5D%2CA" title="containsOrIncl[A](s: var OrderedSet[A]; key: A): bool">containsOrIncl[A](s: var OrderedSet[A]; key: A): bool</a></li>
  118. </ul>
  119. <ul class="simple nested-toc-section">difference
  120. <li><a class="reference" href="#difference%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="difference[A](s1, s2: HashSet[A]): HashSet[A]">difference[A](s1, s2: HashSet[A]): HashSet[A]</a></li>
  121. </ul>
  122. <ul class="simple nested-toc-section">disjoint
  123. <li><a class="reference" href="#disjoint%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="disjoint[A](s1, s2: HashSet[A]): bool">disjoint[A](s1, s2: HashSet[A]): bool</a></li>
  124. </ul>
  125. <ul class="simple nested-toc-section">excl
  126. <li><a class="reference" href="#excl%2CHashSet%5BA%5D%2CA" title="excl[A](s: var HashSet[A]; key: A)">excl[A](s: var HashSet[A]; key: A)</a></li>
  127. <li><a class="reference" href="#excl%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="excl[A](s: var HashSet[A]; other: HashSet[A])">excl[A](s: var HashSet[A]; other: HashSet[A])</a></li>
  128. <li><a class="reference" href="#excl%2COrderedSet%5BA%5D%2CA" title="excl[A](s: var OrderedSet[A]; key: A)">excl[A](s: var OrderedSet[A]; key: A)</a></li>
  129. </ul>
  130. <ul class="simple nested-toc-section">hash
  131. <li><a class="reference" href="#hash%2CHashSet%5BA%5D" title="hash[A](s: HashSet[A]): Hash">hash[A](s: HashSet[A]): Hash</a></li>
  132. <li><a class="reference" href="#hash%2COrderedSet%5BA%5D" title="hash[A](s: OrderedSet[A]): Hash">hash[A](s: OrderedSet[A]): Hash</a></li>
  133. </ul>
  134. <ul class="simple nested-toc-section">incl
  135. <li><a class="reference" href="#incl%2CHashSet%5BA%5D%2CA" title="incl[A](s: var HashSet[A]; key: A)">incl[A](s: var HashSet[A]; key: A)</a></li>
  136. <li><a class="reference" href="#incl%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="incl[A](s: var HashSet[A]; other: HashSet[A])">incl[A](s: var HashSet[A]; other: HashSet[A])</a></li>
  137. <li><a class="reference" href="#incl%2CHashSet%5BA%5D%2COrderedSet%5BA%5D" title="incl[A](s: var HashSet[A]; other: OrderedSet[A])">incl[A](s: var HashSet[A]; other: OrderedSet[A])</a></li>
  138. <li><a class="reference" href="#incl%2COrderedSet%5BA%5D%2CA" title="incl[A](s: var OrderedSet[A]; key: A)">incl[A](s: var OrderedSet[A]; key: A)</a></li>
  139. </ul>
  140. <ul class="simple nested-toc-section">init
  141. <li><a class="reference" href="#init%2CHashSet%5BA%5D" title="init[A](s: var HashSet[A]; initialSize = defaultInitialSize)">init[A](s: var HashSet[A]; initialSize = defaultInitialSize)</a></li>
  142. <li><a class="reference" href="#init%2COrderedSet%5BA%5D" title="init[A](s: var OrderedSet[A]; initialSize = defaultInitialSize)">init[A](s: var OrderedSet[A]; initialSize = defaultInitialSize)</a></li>
  143. </ul>
  144. <ul class="simple nested-toc-section">initHashSet
  145. <li><a class="reference" href="#initHashSet" title="initHashSet[A](initialSize = defaultInitialSize): HashSet[A]">initHashSet[A](initialSize = defaultInitialSize): HashSet[A]</a></li>
  146. </ul>
  147. <ul class="simple nested-toc-section">initOrderedSet
  148. <li><a class="reference" href="#initOrderedSet" title="initOrderedSet[A](initialSize = defaultInitialSize): OrderedSet[A]">initOrderedSet[A](initialSize = defaultInitialSize): OrderedSet[A]</a></li>
  149. </ul>
  150. <ul class="simple nested-toc-section">initSet
  151. <li><a class="reference" href="#initSet" title="initSet[A](initialSize = defaultInitialSize): HashSet[A]">initSet[A](initialSize = defaultInitialSize): HashSet[A]</a></li>
  152. </ul>
  153. <ul class="simple nested-toc-section">intersection
  154. <li><a class="reference" href="#intersection%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="intersection[A](s1, s2: HashSet[A]): HashSet[A]">intersection[A](s1, s2: HashSet[A]): HashSet[A]</a></li>
  155. </ul>
  156. <ul class="simple nested-toc-section">isValid
  157. <li><a class="reference" href="#isValid%2CHashSet%5BA%5D" title="isValid[A](s: HashSet[A]): bool">isValid[A](s: HashSet[A]): bool</a></li>
  158. </ul>
  159. <ul class="simple nested-toc-section">len
  160. <li><a class="reference" href="#len%2CHashSet%5BA%5D" title="len[A](s: HashSet[A]): int">len[A](s: HashSet[A]): int</a></li>
  161. <li><a class="reference" href="#len%2COrderedSet%5BA%5D" title="len[A](s: OrderedSet[A]): int">len[A](s: OrderedSet[A]): int</a></li>
  162. </ul>
  163. <ul class="simple nested-toc-section">map
  164. <li><a class="reference" href="#map%2CHashSet%5BA%5D%2Cproc%28A%29" title="map[A, B](data: HashSet[A]; op: proc (x: A): B {.closure.}): HashSet[B]">map[A, B](data: HashSet[A]; op: proc (x: A): B {.closure.}): HashSet[B]</a></li>
  165. </ul>
  166. <ul class="simple nested-toc-section">missingOrExcl
  167. <li><a class="reference" href="#missingOrExcl%2CHashSet%5BA%5D%2CA" title="missingOrExcl[A](s: var HashSet[A]; key: A): bool">missingOrExcl[A](s: var HashSet[A]; key: A): bool</a></li>
  168. <li><a class="reference" href="#missingOrExcl%2COrderedSet%5BA%5D%2CA" title="missingOrExcl[A](s: var OrderedSet[A]; key: A): bool">missingOrExcl[A](s: var OrderedSet[A]; key: A): bool</a></li>
  169. </ul>
  170. <ul class="simple nested-toc-section">pop
  171. <li><a class="reference" href="#pop%2CHashSet%5BA%5D" title="pop[A](s: var HashSet[A]): A">pop[A](s: var HashSet[A]): A</a></li>
  172. </ul>
  173. <ul class="simple nested-toc-section">symmetricDifference
  174. <li><a class="reference" href="#symmetricDifference%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="symmetricDifference[A](s1, s2: HashSet[A]): HashSet[A]">symmetricDifference[A](s1, s2: HashSet[A]): HashSet[A]</a></li>
  175. </ul>
  176. <ul class="simple nested-toc-section">toHashSet
  177. <li><a class="reference" href="#toHashSet%2CopenArray%5BA%5D" title="toHashSet[A](keys: openArray[A]): HashSet[A]">toHashSet[A](keys: openArray[A]): HashSet[A]</a></li>
  178. </ul>
  179. <ul class="simple nested-toc-section">toOrderedSet
  180. <li><a class="reference" href="#toOrderedSet%2CopenArray%5BA%5D" title="toOrderedSet[A](keys: openArray[A]): OrderedSet[A]">toOrderedSet[A](keys: openArray[A]): OrderedSet[A]</a></li>
  181. </ul>
  182. <ul class="simple nested-toc-section">toSet
  183. <li><a class="reference" href="#toSet%2CopenArray%5BA%5D" title="toSet[A](keys: openArray[A]): HashSet[A]">toSet[A](keys: openArray[A]): HashSet[A]</a></li>
  184. </ul>
  185. <ul class="simple nested-toc-section">union
  186. <li><a class="reference" href="#union%2CHashSet%5BA%5D%2CHashSet%5BA%5D" title="union[A](s1, s2: HashSet[A]): HashSet[A]">union[A](s1, s2: HashSet[A]): HashSet[A]</a></li>
  187. </ul>
  188. </ul>
  189. </details>
  190. </li>
  191. <li>
  192. <details open>
  193. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  194. <ul class="simple simple-toc-section">
  195. <ul class="simple nested-toc-section">items
  196. <li><a class="reference" href="#items.i%2CHashSet%5BA%5D" title="items[A](s: HashSet[A]): A">items[A](s: HashSet[A]): A</a></li>
  197. <li><a class="reference" href="#items.i%2COrderedSet%5BA%5D" title="items[A](s: OrderedSet[A]): A">items[A](s: OrderedSet[A]): A</a></li>
  198. </ul>
  199. <ul class="simple nested-toc-section">pairs
  200. <li><a class="reference" href="#pairs.i%2COrderedSet%5BA%5D" title="pairs[A](s: OrderedSet[A]): tuple[a: int, b: A]">pairs[A](s: OrderedSet[A]): tuple[a: int, b: A]</a></li>
  201. </ul>
  202. </ul>
  203. </details>
  204. </li>
  205. </ul>
  206. </div>
  207. <div class="nine columns" id="content">
  208. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  209. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  210. <div id="tocRoot"></div>
  211. <p class="module-desc"><p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">sets</span></span></tt> module implements an efficient <span id="hash-set_1">hash set</span> and ordered hash set.</p>
  212. <p>Hash sets are different from the <a class="reference external" href="manual.html#types-set-type">built in set type</a>. Sets allow you to store any value that can be <a class="reference external" href="hashes.html">hashed</a> and they don't contain duplicate entries.</p>
  213. <p>Common usages of sets:</p>
  214. <ul class="simple"><li>removing duplicates from a container by converting it with <a class="reference external" href="#toHashSet,openArray[A]">toHashSet proc</a> (see also <a class="reference external" href="sequtils.html#deduplicate,openArray[T],bool">sequtils.deduplicate func</a>)</li>
  215. <li>membership testing</li>
  216. <li>mathematical operations on two sets, such as <a class="reference external" href="#union,HashSet[A],HashSet[A]">union</a>, <a class="reference external" href="#intersection,HashSet[A],HashSet[A]">intersection</a>, <a class="reference external" href="#difference,HashSet[A],HashSet[A]">difference</a>, and <a class="reference external" href="#symmetricDifference,HashSet[A],HashSet[A]">symmetric difference</a></li>
  217. </ul>
  218. <p><strong>Examples:</strong></p>
  219. <p><pre class="listing"><span class="Identifier">echo</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">9</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Comment"># {9, 1, 5}</span>
  220. <span class="Identifier">echo</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">9</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Comment"># {9, 5, 1}</span>
  221. <span class="Keyword">let</span>
  222. <span class="Identifier">s1</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">9</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  223. <span class="Identifier">s2</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  224. <span class="Identifier">echo</span> <span class="Identifier">s1</span> <span class="Operator">+</span> <span class="Identifier">s2</span> <span class="Comment"># {9, 1, 3, 5, 7}</span>
  225. <span class="Identifier">echo</span> <span class="Identifier">s1</span> <span class="Operator">-</span> <span class="Identifier">s2</span> <span class="Comment"># {1, 9}</span>
  226. <span class="Identifier">echo</span> <span class="Identifier">s1</span> <span class="Operator">*</span> <span class="Identifier">s2</span> <span class="Comment"># {5}</span>
  227. <span class="Identifier">echo</span> <span class="Identifier">s1</span> <span class="Operator">-+-</span> <span class="Identifier">s2</span> <span class="Comment"># {9, 1, 3, 7}</span></pre></p>
  228. <p>Note: The data types declared here have <em>value semantics</em>: This means that <tt class="docutils literal"><span class="pre"><span class="Operator">=</span></span></tt> performs a copy of the set.</p>
  229. <p><strong>See also:</strong></p>
  230. <ul class="simple"><li><a class="reference external" href="intsets.html">intsets module</a> for efficient int sets</li>
  231. <li><a class="reference external" href="tables.html">tables module</a> for hash tables</li>
  232. </ul>
  233. </p>
  234. <div class="section" id="6">
  235. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  236. <dl class="item">
  237. <a class="reference external" href="hashes.html">hashes</a>, <a class="reference external" href="math.html">math</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="outparams.html">outparams</a>
  238. </dl>
  239. </div>
  240. <div class="section" id="7">
  241. <h1><a class="toc-backref" href="#7">Types</a></h1>
  242. <dl class="item">
  243. <div id="HashSet">
  244. <dt><pre><a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> {..} <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
  245. <dd>
  246. <p>
  247. A generic hash set.</p>
  248. <p>Use <a class="reference external" href="#init,HashSet[A]">init proc</a> or <a class="reference external" href="#initHashSet">initHashSet proc</a> before calling other procs on it.</p>
  249. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L66" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  250. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L66" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  251. </dd>
  252. </div>
  253. <div id="OrderedSet">
  254. <dt><pre><a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> {..} <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
  255. <dd>
  256. <p>
  257. A generic hash set that remembers insertion order.</p>
  258. <p>Use <a class="reference external" href="#init,OrderedSet[A]">init proc</a> or <a class="reference external" href="#initOrderedSet">initOrderedSet proc</a> before calling other procs on it.</p>
  259. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L78" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  260. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L78" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  261. </dd>
  262. </div>
  263. <div id="SomeSet">
  264. <dt><pre><a href="sets.html#SomeSet"><span class="Identifier">SomeSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> <span class="Other">=</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> <span class="Operator">|</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  265. <dd>
  266. Type union representing <tt class="docutils literal"><span class="pre"><span class="Identifier">HashSet</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Identifier">OrderedSet</span></span></tt>.
  267. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L85" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  268. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L85" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  269. </dd>
  270. </div>
  271. </dl>
  272. </div>
  273. <div class="section" id="10">
  274. <h1><a class="toc-backref" href="#10">Consts</a></h1>
  275. <dl class="item">
  276. <div id="defaultInitialSize">
  277. <dt><pre><a href="sets.html#defaultInitialSize"><span class="Identifier">defaultInitialSize</span></a> <span class="Other">=</span> <span class="DecNumber">64</span></pre></dt>
  278. <dd>
  279. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L89" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  280. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L89" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  281. </dd>
  282. </div>
  283. </dl>
  284. </div>
  285. <div class="section" id="12">
  286. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  287. <dl class="item">
  288. <div id="$-procs-all">
  289. <div id="$,HashSet[A]">
  290. <dt><pre><span class="Keyword">proc</span> <a href="#%24%2CHashSet%5BA%5D"><span class="Identifier">`$`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  291. <dd>
  292. <p>Converts the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> to a string, mostly for logging and printing purposes.</p>
  293. <p>Don't use this proc for serialization, the representation may change at any moment and values are not escaped.</p>
  294. <p><strong>Examples:</strong></p>
  295. <p><pre class="listing"><span class="Identifier">echo</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  296. <span class="Comment"># --&gt; {2, 4, 5}</span>
  297. <span class="Identifier">echo</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;no&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;esc'aping&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;is </span><span class="EscapeSequence">\&quot;</span><span class="StringLit"> provided&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  298. <span class="Comment"># --&gt; {no, esc'aping, is &quot; provided}</span></pre></p>
  299. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L587" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  300. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L587" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  301. </dd>
  302. </div>
  303. <div id="$,OrderedSet[A]">
  304. <dt><pre><span class="Keyword">proc</span> <a href="#%24%2COrderedSet%5BA%5D"><span class="Identifier">`$`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  305. <dd>
  306. <p>Converts the ordered hash set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> to a string, mostly for logging and printing purposes.</p>
  307. <p>Don't use this proc for serialization, the representation may change at any moment and values are not escaped.</p>
  308. <p><strong>Examples:</strong></p>
  309. <p><pre class="listing"><span class="Identifier">echo</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  310. <span class="Comment"># --&gt; {2, 4, 5}</span>
  311. <span class="Identifier">echo</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;no&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;esc'aping&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;is </span><span class="EscapeSequence">\&quot;</span><span class="StringLit"> provided&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  312. <span class="Comment"># --&gt; {no, esc'aping, is &quot; provided}</span></pre></p>
  313. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L876" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  314. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L876" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  315. </dd>
  316. </div>
  317. </div>
  318. <div id="*-procs-all">
  319. <div id="*,HashSet[A],HashSet[A]">
  320. <dt><pre><span class="Keyword">proc</span> <a href="#%2A%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">`*`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s1</span><span class="Other">,</span> <span class="Identifier">s2</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> {.<span class="Identifier">inline</span>.}</pre></dt>
  321. <dd>
  322. Alias for <a class="reference external" href="#intersection,HashSet[A],HashSet[A]">intersection(s1, s2)</a>.
  323. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L495" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  324. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L495" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  325. </dd>
  326. </div>
  327. </div>
  328. <div id="+-procs-all">
  329. <div id="+,HashSet[A],HashSet[A]">
  330. <dt><pre><span class="Keyword">proc</span> <a href="#%2B%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">`+`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s1</span><span class="Other">,</span> <span class="Identifier">s2</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> {.<span class="Identifier">inline</span>.}</pre></dt>
  331. <dd>
  332. Alias for <a class="reference external" href="#union,HashSet[A],HashSet[A]">union(s1, s2)</a>.
  333. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L491" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  334. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L491" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  335. </dd>
  336. </div>
  337. </div>
  338. <div id="--procs-all">
  339. <div id="-,HashSet[A],HashSet[A]">
  340. <dt><pre><span class="Keyword">proc</span> <a href="#-%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">`-`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s1</span><span class="Other">,</span> <span class="Identifier">s2</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> {.<span class="Identifier">inline</span>.}</pre></dt>
  341. <dd>
  342. Alias for <a class="reference external" href="#difference,HashSet[A],HashSet[A]">difference(s1, s2)</a>.
  343. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L499" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  344. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L499" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  345. </dd>
  346. </div>
  347. </div>
  348. <div id="-+--procs-all">
  349. <div id="-+-,HashSet[A],HashSet[A]">
  350. <dt><pre><span class="Keyword">proc</span> <a href="#-%2B-%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">`-+-`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s1</span><span class="Other">,</span> <span class="Identifier">s2</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> {.<span class="Identifier">inline</span>.}</pre></dt>
  351. <dd>
  352. Alias for <a class="reference external" href="#symmetricDifference,HashSet[A],HashSet[A]">symmetricDifference(s1, s2)</a>.
  353. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L503" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  354. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L503" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  355. </dd>
  356. </div>
  357. </div>
  358. <div id="&lt;-procs-all">
  359. <div id="<,HashSet[A],HashSet[A]">
  360. <dt><pre><span class="Keyword">proc</span> <a href="#%3C%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">`&lt;`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">,</span> <span class="Identifier">t</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  361. <dd>
  362. <p>Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> is a strict or proper subset of <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
  363. <p>A strict or proper subset <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> has all of its members in <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> but <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> has more elements than <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  364. <p><strong class="examples_text">Example:</strong></p>
  365. <pre class="listing"><span class="Keyword">let</span>
  366. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  367. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;b&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;c&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  368. <span class="Identifier">c</span> <span class="Operator">=</span> <span class="Identifier">intersection</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">)</span>
  369. <span class="Identifier">assert</span> <span class="Identifier">c</span> <span class="Operator">&lt;</span> <span class="Identifier">a</span> <span class="Keyword">and</span> <span class="Identifier">c</span> <span class="Operator">&lt;</span> <span class="Identifier">b</span>
  370. <span class="Identifier">assert</span><span class="Punctuation">(</span><span class="Keyword">not</span> <span class="Punctuation">(</span><span class="Identifier">a</span> <span class="Operator">&lt;</span> <span class="Identifier">a</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>
  371. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L521" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  372. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L521" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  373. </dd>
  374. </div>
  375. </div>
  376. <div id="&lt;=-procs-all">
  377. <div id="<=,HashSet[A],HashSet[A]">
  378. <dt><pre><span class="Keyword">proc</span> <a href="#%3C%3D%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">`&lt;=`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">,</span> <span class="Identifier">t</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  379. <dd>
  380. <p>Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> is a subset of <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
  381. <p>A subset <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> has all of its members in <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> doesn't necessarily have more members than <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. That is, <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> can be equal to <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
  382. <p><strong class="examples_text">Example:</strong></p>
  383. <pre class="listing"><span class="Keyword">let</span>
  384. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  385. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;b&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;c&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  386. <span class="Identifier">c</span> <span class="Operator">=</span> <span class="Identifier">intersection</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">)</span>
  387. <span class="Identifier">assert</span> <span class="Identifier">c</span> <span class="Operator">&lt;=</span> <span class="Identifier">a</span> <span class="Keyword">and</span> <span class="Identifier">c</span> <span class="Operator">&lt;=</span> <span class="Identifier">b</span>
  388. <span class="Identifier">assert</span> <span class="Identifier">a</span> <span class="Operator">&lt;=</span> <span class="Identifier">a</span></pre>
  389. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L536" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  390. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L536" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  391. </dd>
  392. </div>
  393. </div>
  394. <div id="==-procs-all">
  395. <div id="==,HashSet[A],HashSet[A]">
  396. <dt><pre><span class="Keyword">proc</span> <a href="#%3D%3D%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">`==`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">,</span> <span class="Identifier">t</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  397. <dd>
  398. Returns true if both <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> have the same members and set size.
  399. <p><strong class="examples_text">Example:</strong></p>
  400. <pre class="listing"><span class="Keyword">var</span>
  401. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  402. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  403. <span class="Identifier">assert</span> <span class="Identifier">a</span> <span class="Operator">==</span> <span class="Identifier">b</span></pre>
  404. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L557" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  405. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L557" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  406. </dd>
  407. </div>
  408. <div id="==,OrderedSet[A],OrderedSet[A]">
  409. <dt><pre><span class="Keyword">proc</span> <a href="#%3D%3D%2COrderedSet%5BA%5D%2COrderedSet%5BA%5D"><span class="Identifier">`==`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">,</span> <span class="Identifier">t</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  410. <dd>
  411. Equality for ordered sets.
  412. <p><strong class="examples_text">Example:</strong></p>
  413. <pre class="listing"><span class="Keyword">let</span>
  414. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  415. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  416. <span class="Identifier">assert</span><span class="Punctuation">(</span><span class="Keyword">not</span> <span class="Punctuation">(</span><span class="Identifier">a</span> <span class="Operator">==</span> <span class="Identifier">b</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>
  417. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L846" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  418. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L846" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  419. </dd>
  420. </div>
  421. </div>
  422. <div id="[]-procs-all">
  423. <div id="[],HashSet[A],A">
  424. <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CHashSet%5BA%5D%2CA"><span class="Identifier">`[]`</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">A</span></pre></dt>
  425. <dd>
  426. <p>Returns the element that is actually stored in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> which has the same value as <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> or raises the <tt class="docutils literal"><span class="pre"><span class="Identifier">KeyError</span></span></tt> exception.</p>
  427. <p>This is useful when one overloaded <tt class="docutils literal"><span class="pre"><span class="Identifier">hash</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Operator">==</span></span></tt> but still needs reference semantics for sharing.</p>
  428. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L136" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  429. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L136" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  430. </dd>
  431. </div>
  432. </div>
  433. <div id="card-procs-all">
  434. <div id="card,HashSet[A]">
  435. <dt><pre><span class="Keyword">proc</span> <a href="#card%2CHashSet%5BA%5D"><span class="Identifier">card</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a></pre></dt>
  436. <dd>
  437. <p>Alias for <a class="reference external" href="#len,HashSet[A]">len()</a>.</p>
  438. <p>Card stands for the <a class="reference external" href="https://en.wikipedia.org/wiki/Cardinality">cardinality</a> of a set.</p>
  439. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L186" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  440. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L186" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  441. </dd>
  442. </div>
  443. <div id="card,OrderedSet[A]">
  444. <dt><pre><span class="Keyword">proc</span> <a href="#card%2COrderedSet%5BA%5D"><span class="Identifier">card</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  445. <dd>
  446. <p>Alias for <a class="reference external" href="#len,OrderedSet[A]">len()</a>.</p>
  447. <p>Card stands for the <a class="reference external" href="https://en.wikipedia.org/wiki/Cardinality">cardinality</a> of a set.</p>
  448. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L839" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  449. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L839" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  450. </dd>
  451. </div>
  452. </div>
  453. <div id="clear-procs-all">
  454. <div id="clear,HashSet[A]">
  455. <dt><pre><span class="Keyword">proc</span> <a href="#clear%2CHashSet%5BA%5D"><span class="Identifier">clear</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span></pre></dt>
  456. <dd>
  457. <p>Clears the HashSet back to an empty state, without shrinking any of the existing storage.</p>
  458. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">O</span><span class="Punctuation">(</span><span class="Identifier">n</span><span class="Punctuation">)</span></span></tt> operation, where <tt class="docutils literal"><span class="pre"><span class="Identifier">n</span></span></tt> is the size of the hash bucket.</p>
  459. <p>See also:</p>
  460. <ul class="simple"><li><a class="reference external" href="#pop,HashSet[A]">pop proc</a></li>
  461. </ul>
  462. <p><strong class="examples_text">Example:</strong></p>
  463. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  464. <span class="Identifier">clear</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">)</span>
  465. <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span></pre>
  466. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L369" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  467. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L369" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  468. </dd>
  469. </div>
  470. <div id="clear,OrderedSet[A]">
  471. <dt><pre><span class="Keyword">proc</span> <a href="#clear%2COrderedSet%5BA%5D"><span class="Identifier">clear</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span></pre></dt>
  472. <dd>
  473. <p>Clears the OrderedSet back to an empty state, without shrinking any of the existing storage.</p>
  474. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">O</span><span class="Punctuation">(</span><span class="Identifier">n</span><span class="Punctuation">)</span></span></tt> operation where <tt class="docutils literal"><span class="pre"><span class="Identifier">n</span></span></tt> is the size of the hash bucket.</p>
  475. <p><strong class="examples_text">Example:</strong></p>
  476. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  477. <span class="Identifier">clear</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">)</span>
  478. <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span></pre>
  479. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L805" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  480. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L805" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  481. </dd>
  482. </div>
  483. </div>
  484. <div id="contains-procs-all">
  485. <div id="contains,HashSet[A],A">
  486. <dt><pre><span class="Keyword">proc</span> <a href="#contains%2CHashSet%5BA%5D%2CA"><span class="Identifier">contains</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a></pre></dt>
  487. <dd>
  488. <p>Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  489. <p>This allows the usage of <tt class="docutils literal"><span class="pre"><span class="Keyword">in</span></span></tt> operator.</p>
  490. <p>See also:</p>
  491. <ul class="simple"><li><a class="reference external" href="#incl,HashSet[A],A">incl proc</a></li>
  492. <li><a class="reference external" href="#containsOrIncl,HashSet[A],A">containsOrIncl proc</a></li>
  493. </ul>
  494. <p><strong class="examples_text">Example:</strong></p>
  495. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">values</span> <span class="Operator">=</span> <span class="Identifier">initHashSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  496. <span class="Identifier">assert</span><span class="Punctuation">(</span><span class="Keyword">not</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  497. <span class="Identifier">assert</span> <span class="DecNumber">2</span> <span class="Keyword">notin</span> <span class="Identifier">values</span>
  498. <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  499. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  500. <span class="Identifier">assert</span> <span class="DecNumber">2</span> <span class="Keyword">in</span> <span class="Identifier">values</span></pre>
  501. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L151" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  502. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L151" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  503. </dd>
  504. </div>
  505. <div id="contains,OrderedSet[A],A">
  506. <dt><pre><span class="Keyword">proc</span> <a href="#contains%2COrderedSet%5BA%5D%2CA"><span class="Identifier">contains</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a></pre></dt>
  507. <dd>
  508. <p>Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  509. <p>This allows the usage of <tt class="docutils literal"><span class="pre"><span class="Keyword">in</span></span></tt> operator.</p>
  510. <p>See also:</p>
  511. <ul class="simple"><li><a class="reference external" href="#incl,OrderedSet[A],A">incl proc</a></li>
  512. <li><a class="reference external" href="#containsOrIncl,OrderedSet[A],A">containsOrIncl proc</a></li>
  513. </ul>
  514. <p><strong class="examples_text">Example:</strong></p>
  515. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">values</span> <span class="Operator">=</span> <span class="Identifier">initOrderedSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  516. <span class="Identifier">assert</span><span class="Punctuation">(</span><span class="Keyword">not</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  517. <span class="Identifier">assert</span> <span class="DecNumber">2</span> <span class="Keyword">notin</span> <span class="Identifier">values</span>
  518. <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  519. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">contains</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  520. <span class="Identifier">assert</span> <span class="DecNumber">2</span> <span class="Keyword">in</span> <span class="Identifier">values</span></pre>
  521. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L696" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  522. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L696" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  523. </dd>
  524. </div>
  525. </div>
  526. <div id="containsOrIncl-procs-all">
  527. <div id="containsOrIncl,HashSet[A],A">
  528. <dt><pre><span class="Keyword">proc</span> <a href="#containsOrIncl%2CHashSet%5BA%5D%2CA"><span class="Identifier">containsOrIncl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a></pre></dt>
  529. <dd>
  530. <p>Includes <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> in the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and tells if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was already in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  531. <p>The difference with regards to the <a class="reference external" href="#incl,HashSet[A],A">incl proc</a> is that this proc returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> already contained <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt>. The proc will return <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was added as a new value to <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> during this call.</p>
  532. <p>See also:</p>
  533. <ul class="simple"><li><a class="reference external" href="#incl,HashSet[A],A">incl proc</a> for including an element</li>
  534. <li><a class="reference external" href="#incl,HashSet[A],HashSet[A]">incl proc</a> for including other set</li>
  535. <li><a class="reference external" href="#missingOrExcl,HashSet[A],A">missingOrExcl proc</a></li>
  536. </ul>
  537. <p><strong class="examples_text">Example:</strong></p>
  538. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">values</span> <span class="Operator">=</span> <span class="Identifier">initHashSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  539. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">containsOrIncl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  540. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">containsOrIncl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  541. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">containsOrIncl</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span></pre>
  542. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L274" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  543. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L274" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  544. </dd>
  545. </div>
  546. <div id="containsOrIncl,OrderedSet[A],A">
  547. <dt><pre><span class="Keyword">proc</span> <a href="#containsOrIncl%2COrderedSet%5BA%5D%2CA"><span class="Identifier">containsOrIncl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a></pre></dt>
  548. <dd>
  549. <p>Includes <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> in the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and tells if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was already in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  550. <p>The difference with regards to the <a class="reference external" href="#incl,OrderedSet[A],A">incl proc</a> is that this proc returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> already contained <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt>. The proc will return false if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was added as a new value to <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> during this call.</p>
  551. <p>See also:</p>
  552. <ul class="simple"><li><a class="reference external" href="#incl,OrderedSet[A],A">incl proc</a> for including an element</li>
  553. <li><a class="reference external" href="#missingOrExcl,OrderedSet[A],A">missingOrExcl proc</a></li>
  554. </ul>
  555. <p><strong class="examples_text">Example:</strong></p>
  556. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">values</span> <span class="Operator">=</span> <span class="Identifier">initOrderedSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  557. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">containsOrIncl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  558. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">containsOrIncl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  559. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">containsOrIncl</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span></pre>
  560. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L750" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  561. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L750" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  562. </dd>
  563. </div>
  564. </div>
  565. <div id="difference-procs-all">
  566. <div id="difference,HashSet[A],HashSet[A]">
  567. <dt><pre><span class="Keyword">proc</span> <a href="#difference%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">difference</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s1</span><span class="Other">,</span> <span class="Identifier">s2</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  568. <dd>
  569. <p>Returns the difference of the sets <tt class="docutils literal"><span class="pre"><span class="Identifier">s1</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">s2</span></span></tt>.</p>
  570. <p>The same as <a class="reference external" href="#-,HashSet[A],HashSet[A]">s1 - s2</a>.</p>
  571. <p>The difference of two sets is represented mathematically as <em>A ∖ B</em> and is the set of all objects that are members of <tt class="docutils literal"><span class="pre"><span class="Identifier">s1</span></span></tt> and not members of <tt class="docutils literal"><span class="pre"><span class="Identifier">s2</span></span></tt>.</p>
  572. <p>See also:</p>
  573. <ul class="simple"><li><a class="reference external" href="#union,HashSet[A],HashSet[A]">union proc</a></li>
  574. <li><a class="reference external" href="#intersection,HashSet[A],HashSet[A]">intersection proc</a></li>
  575. <li><a class="reference external" href="#symmetricDifference,HashSet[A],HashSet[A]">symmetricDifference proc</a></li>
  576. </ul>
  577. <p><strong class="examples_text">Example:</strong></p>
  578. <pre class="listing"><span class="Keyword">let</span>
  579. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  580. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;b&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;c&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  581. <span class="Identifier">c</span> <span class="Operator">=</span> <span class="Identifier">difference</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">)</span>
  582. <span class="Identifier">assert</span> <span class="Identifier">c</span> <span class="Operator">==</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
  583. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L443" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  584. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L443" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  585. </dd>
  586. </div>
  587. </div>
  588. <div id="disjoint-procs-all">
  589. <div id="disjoint,HashSet[A],HashSet[A]">
  590. <dt><pre><span class="Keyword">proc</span> <a href="#disjoint%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">disjoint</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s1</span><span class="Other">,</span> <span class="Identifier">s2</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  591. <dd>
  592. Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if the sets <tt class="docutils literal"><span class="pre"><span class="Identifier">s1</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">s2</span></span></tt> have no items in common.
  593. <p><strong class="examples_text">Example:</strong></p>
  594. <pre class="listing"><span class="Keyword">let</span>
  595. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  596. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;b&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;c&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  597. <span class="Identifier">assert</span> <span class="Identifier">disjoint</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  598. <span class="Identifier">assert</span> <span class="Identifier">disjoint</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span> <span class="Operator">-</span> <span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span></pre>
  599. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L508" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  600. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L508" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  601. </dd>
  602. </div>
  603. </div>
  604. <div id="excl-procs-all">
  605. <div id="excl,HashSet[A],A">
  606. <dt><pre><span class="Keyword">proc</span> <a href="#excl%2CHashSet%5BA%5D%2CA"><span class="Identifier">excl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span></pre></dt>
  607. <dd>
  608. <p>Excludes <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> from the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  609. <p>This doesn't do anything if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is not found in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  610. <p>See also:</p>
  611. <ul class="simple"><li><a class="reference external" href="#incl,HashSet[A],A">incl proc</a> for including an element</li>
  612. <li><a class="reference external" href="#excl,HashSet[A],HashSet[A]">excl proc</a> for excluding other set</li>
  613. <li><a class="reference external" href="#missingOrExcl,HashSet[A],A">missingOrExcl proc</a></li>
  614. </ul>
  615. <p><strong class="examples_text">Example:</strong></p>
  616. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">6</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  617. <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">excl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  618. <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">excl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  619. <span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">3</span></pre>
  620. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L294" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  621. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L294" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  622. </dd>
  623. </div>
  624. <div id="excl,HashSet[A],HashSet[A]">
  625. <dt><pre><span class="Keyword">proc</span> <a href="#excl%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">excl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">other</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span></pre></dt>
  626. <dd>
  627. <p>Excludes all elements of <tt class="docutils literal"><span class="pre"><span class="Identifier">other</span></span></tt> set from <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  628. <p>This is the in-place version of <a class="reference external" href="#-,HashSet[A],HashSet[A]">s - other</a>.</p>
  629. <p>See also:</p>
  630. <ul class="simple"><li><a class="reference external" href="#incl,HashSet[A],HashSet[A]">incl proc</a> for including other set</li>
  631. <li><a class="reference external" href="#excl,HashSet[A],A">excl proc</a> for excluding an element</li>
  632. <li><a class="reference external" href="#missingOrExcl,HashSet[A],A">missingOrExcl proc</a></li>
  633. </ul>
  634. <p><strong class="examples_text">Example:</strong></p>
  635. <pre class="listing"><span class="Keyword">var</span>
  636. <span class="Identifier">numbers</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  637. <span class="Identifier">even</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="DecNumber">6</span><span class="Punctuation">,</span> <span class="DecNumber">8</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  638. <span class="Identifier">numbers</span><span class="Operator">.</span><span class="Identifier">excl</span><span class="Punctuation">(</span><span class="Identifier">even</span><span class="Punctuation">)</span>
  639. <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">numbers</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
  640. <span class="Comment">## numbers == {1, 3, 5}</span></pre>
  641. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L311" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  642. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L311" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  643. </dd>
  644. </div>
  645. <div id="excl,OrderedSet[A],A">
  646. <dt><pre><span class="Keyword">proc</span> <a href="#excl%2COrderedSet%5BA%5D%2CA"><span class="Identifier">excl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span></pre></dt>
  647. <dd>
  648. <p>Excludes <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> from the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Efficiency: <tt class="docutils literal"><span class="pre"><span class="Identifier">O</span><span class="Punctuation">(</span><span class="Identifier">n</span><span class="Punctuation">)</span></span></tt>.</p>
  649. <p>This doesn't do anything if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is not found in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  650. <p>See also:</p>
  651. <ul class="simple"><li><a class="reference external" href="#incl,OrderedSet[A],A">incl proc</a> for including an element</li>
  652. <li><a class="reference external" href="#missingOrExcl,OrderedSet[A],A">missingOrExcl proc</a></li>
  653. </ul>
  654. <p><strong class="examples_text">Example:</strong></p>
  655. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">6</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  656. <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">excl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  657. <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">excl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  658. <span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">3</span></pre>
  659. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L769" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  660. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L769" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  661. </dd>
  662. </div>
  663. </div>
  664. <div id="hash-procs-all">
  665. <div id="hash,HashSet[A]">
  666. <dt><pre><span class="Keyword">proc</span> <a href="#hash%2CHashSet%5BA%5D"><span class="Identifier">hash</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  667. <dd>
  668. Hashing of HashSet.
  669. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L581" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  670. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L581" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  671. </dd>
  672. </div>
  673. <div id="hash,OrderedSet[A]">
  674. <dt><pre><span class="Keyword">proc</span> <a href="#hash%2COrderedSet%5BA%5D"><span class="Identifier">hash</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  675. <dd>
  676. Hashing of OrderedSet.
  677. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L870" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  678. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L870" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  679. </dd>
  680. </div>
  681. </div>
  682. <div id="incl-procs-all">
  683. <div id="incl,HashSet[A],A">
  684. <dt><pre><span class="Keyword">proc</span> <a href="#incl%2CHashSet%5BA%5D%2CA"><span class="Identifier">incl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span></pre></dt>
  685. <dd>
  686. <p>Includes an element <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  687. <p>This doesn't do anything if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is already in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  688. <p>See also:</p>
  689. <ul class="simple"><li><a class="reference external" href="#excl,HashSet[A],A">excl proc</a> for excluding an element</li>
  690. <li><a class="reference external" href="#incl,HashSet[A],HashSet[A]">incl proc</a> for including other set</li>
  691. <li><a class="reference external" href="#containsOrIncl,HashSet[A],A">containsOrIncl proc</a></li>
  692. </ul>
  693. <p><strong class="examples_text">Example:</strong></p>
  694. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">values</span> <span class="Operator">=</span> <span class="Identifier">initHashSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  695. <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  696. <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  697. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre>
  698. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L193" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  699. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L193" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  700. </dd>
  701. </div>
  702. <div id="incl,HashSet[A],HashSet[A]">
  703. <dt><pre><span class="Keyword">proc</span> <a href="#incl%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">incl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">other</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span></pre></dt>
  704. <dd>
  705. <p>Includes all elements from <tt class="docutils literal"><span class="pre"><span class="Identifier">other</span></span></tt> set into <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> (must be declared as <tt class="docutils literal"><span class="pre"><span class="Keyword">var</span></span></tt>).</p>
  706. <p>This is the in-place version of <a class="reference external" href="#+,HashSet[A],HashSet[A]">s + other</a>.</p>
  707. <p>See also:</p>
  708. <ul class="simple"><li><a class="reference external" href="#excl,HashSet[A],HashSet[A]">excl proc</a> for excluding other set</li>
  709. <li><a class="reference external" href="#incl,HashSet[A],A">incl proc</a> for including an element</li>
  710. <li><a class="reference external" href="#containsOrIncl,HashSet[A],A">containsOrIncl proc</a></li>
  711. </ul>
  712. <p><strong class="examples_text">Example:</strong></p>
  713. <pre class="listing"><span class="Keyword">var</span>
  714. <span class="Identifier">values</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  715. <span class="Identifier">others</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  716. <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="Identifier">others</span><span class="Punctuation">)</span>
  717. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">5</span></pre>
  718. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L210" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  719. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L210" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  720. </dd>
  721. </div>
  722. <div id="incl,HashSet[A],OrderedSet[A]">
  723. <dt><pre><span class="Keyword">proc</span> <a href="#incl%2CHashSet%5BA%5D%2COrderedSet%5BA%5D"><span class="Identifier">incl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">other</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span></pre></dt>
  724. <dd>
  725. <p>Includes all elements from the OrderedSet <tt class="docutils literal"><span class="pre"><span class="Identifier">other</span></span></tt> into HashSet <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> (must be declared as <tt class="docutils literal"><span class="pre"><span class="Keyword">var</span></span></tt>).</p>
  726. <p>See also:</p>
  727. <ul class="simple"><li><a class="reference external" href="#incl,OrderedSet[A],A">incl proc</a> for including an element</li>
  728. <li><a class="reference external" href="#containsOrIncl,OrderedSet[A],A">containsOrIncl proc</a></li>
  729. </ul>
  730. <p><strong class="examples_text">Example:</strong></p>
  731. <pre class="listing"><span class="Keyword">var</span>
  732. <span class="Identifier">values</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  733. <span class="Identifier">others</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  734. <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="Identifier">others</span><span class="Punctuation">)</span>
  735. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">5</span></pre>
  736. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L734" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  737. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L734" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  738. </dd>
  739. </div>
  740. <div id="incl,OrderedSet[A],A">
  741. <dt><pre><span class="Keyword">proc</span> <a href="#incl%2COrderedSet%5BA%5D%2CA"><span class="Identifier">incl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span></pre></dt>
  742. <dd>
  743. <p>Includes an element <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  744. <p>This doesn't do anything if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is already in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  745. <p>See also:</p>
  746. <ul class="simple"><li><a class="reference external" href="#excl,OrderedSet[A],A">excl proc</a> for excluding an element</li>
  747. <li><a class="reference external" href="#incl,HashSet[A],OrderedSet[A]">incl proc</a> for including other set</li>
  748. <li><a class="reference external" href="#containsOrIncl,OrderedSet[A],A">containsOrIncl proc</a></li>
  749. </ul>
  750. <p><strong class="examples_text">Example:</strong></p>
  751. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">values</span> <span class="Operator">=</span> <span class="Identifier">initOrderedSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  752. <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  753. <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">)</span>
  754. <span class="Identifier">assert</span> <span class="Identifier">values</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre>
  755. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L717" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  756. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L717" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  757. </dd>
  758. </div>
  759. </div>
  760. <div id="init-procs-all">
  761. <div id="init,HashSet[A]">
  762. <dt><pre><span class="Keyword">proc</span> <a href="#init%2CHashSet%5BA%5D"><span class="Identifier">init</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">initialSize</span> <span class="Other">=</span> <span class="Identifier">defaultInitialSize</span><span class="Other">)</span></pre></dt>
  763. <dd>
  764. <p>Initializes a hash set.</p>
  765. <p>Starting from Nim v0.20, sets are initialized by default and it is not necessary to call this function explicitly.</p>
  766. <p>You can call this proc on a previously initialized hash set, which will discard all its values. This might be more convenient than iterating over existing values and calling <a class="reference external" href="#excl,HashSet[A],A">excl()</a> on them.</p>
  767. <p>See also:</p>
  768. <ul class="simple"><li><a class="reference external" href="#initHashSet">initHashSet proc</a></li>
  769. <li><a class="reference external" href="#toHashSet,openArray[A]">toHashSet proc</a></li>
  770. </ul>
  771. <p><strong class="examples_text">Example:</strong></p>
  772. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">HashSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span>
  773. <span class="Identifier">init</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span></pre>
  774. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L98" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  775. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L98" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  776. </dd>
  777. </div>
  778. <div id="init,OrderedSet[A]">
  779. <dt><pre><span class="Keyword">proc</span> <a href="#init%2COrderedSet%5BA%5D"><span class="Identifier">init</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">initialSize</span> <span class="Other">=</span> <span class="Identifier">defaultInitialSize</span><span class="Other">)</span></pre></dt>
  780. <dd>
  781. <p>Initializes an ordered hash set.</p>
  782. <p>Starting from Nim v0.20, sets are initialized by default and it is not necessary to call this function explicitly.</p>
  783. <p>You can call this proc on a previously initialized hash set, which will discard all its values. This might be more convenient than iterating over existing values and calling <a class="reference external" href="#excl,HashSet[A],A">excl()</a> on them.</p>
  784. <p>See also:</p>
  785. <ul class="simple"><li><a class="reference external" href="#initOrderedSet">initOrderedSet proc</a></li>
  786. <li><a class="reference external" href="#toOrderedSet,openArray[A]">toOrderedSet proc</a></li>
  787. </ul>
  788. <p><strong class="examples_text">Example:</strong></p>
  789. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">OrderedSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span>
  790. <span class="Identifier">init</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span></pre>
  791. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L638" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  792. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L638" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  793. </dd>
  794. </div>
  795. </div>
  796. <div id="initHashSet-procs-all">
  797. <div id="initHashSet">
  798. <dt><pre><span class="Keyword">proc</span> <a href="#initHashSet"><span class="Identifier">initHashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">initialSize</span> <span class="Other">=</span> <span class="Identifier">defaultInitialSize</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  799. <dd>
  800. <p>Wrapper around <a class="reference external" href="#init,HashSet[A]">init proc</a> for initialization of hash sets.</p>
  801. <p>Returns an empty hash set you can assign directly in <tt class="docutils literal"><span class="pre"><span class="Keyword">var</span></span></tt> blocks in a single line.</p>
  802. <p>Starting from Nim v0.20, sets are initialized by default and it is not necessary to call this function explicitly.</p>
  803. <p>See also:</p>
  804. <ul class="simple"><li><a class="reference external" href="#toHashSet,openArray[A]">toHashSet proc</a></li>
  805. </ul>
  806. <p><strong class="examples_text">Example:</strong></p>
  807. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">initHashSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  808. <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span>
  809. <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">1</span></pre>
  810. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L117" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  811. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L117" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  812. </dd>
  813. </div>
  814. </div>
  815. <div id="initOrderedSet-procs-all">
  816. <div id="initOrderedSet">
  817. <dt><pre><span class="Keyword">proc</span> <a href="#initOrderedSet"><span class="Identifier">initOrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">initialSize</span> <span class="Other">=</span> <span class="Identifier">defaultInitialSize</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  818. <dd>
  819. <p>Wrapper around <a class="reference external" href="#init,OrderedSet[A]">init proc</a> for initialization of ordered hash sets.</p>
  820. <p>Returns an empty ordered hash set you can assign directly in <tt class="docutils literal"><span class="pre"><span class="Keyword">var</span></span></tt> blocks in a single line.</p>
  821. <p>Starting from Nim v0.20, sets are initialized by default and it is not necessary to call this function explicitly.</p>
  822. <p>See also:</p>
  823. <ul class="simple"><li><a class="reference external" href="#toOrderedSet,openArray[A]">toOrderedSet proc</a></li>
  824. </ul>
  825. <p><strong class="examples_text">Example:</strong></p>
  826. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">initOrderedSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  827. <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span>
  828. <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">1</span></pre>
  829. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L657" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  830. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L657" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  831. </dd>
  832. </div>
  833. </div>
  834. <div id="initSet-procs-all">
  835. <div id="initSet">
  836. <dt><pre><span class="Keyword">proc</span> <a href="#initSet"><span class="Identifier">initSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">initialSize</span> <span class="Other">=</span> <span class="Identifier">defaultInitialSize</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> {.
  837. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">&quot;Deprecated since v0.20, use \'initHashSet\'&quot;</span></span>.}</pre></dt>
  838. <dd>
  839. <div class="deprecation-message">
  840. <b>Deprecated:</b> Deprecated since v0.20, use &apos;initHashSet&apos;
  841. </div>
  842. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L603" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  843. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L603" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  844. </dd>
  845. </div>
  846. </div>
  847. <div id="intersection-procs-all">
  848. <div id="intersection,HashSet[A],HashSet[A]">
  849. <dt><pre><span class="Keyword">proc</span> <a href="#intersection%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">intersection</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s1</span><span class="Other">,</span> <span class="Identifier">s2</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  850. <dd>
  851. <p>Returns the intersection of the sets <tt class="docutils literal"><span class="pre"><span class="Identifier">s1</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">s2</span></span></tt>.</p>
  852. <p>The same as <a class="reference external" href="#*,HashSet[A],HashSet[A]">s1 * s2</a>.</p>
  853. <p>The intersection of two sets is represented mathematically as <em>A ∩ B</em> and is the set of all objects that are members of <tt class="docutils literal"><span class="pre"><span class="Identifier">s1</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">s2</span></span></tt> at the same time.</p>
  854. <p>See also:</p>
  855. <ul class="simple"><li><a class="reference external" href="#union,HashSet[A],HashSet[A]">union proc</a></li>
  856. <li><a class="reference external" href="#difference,HashSet[A],HashSet[A]">difference proc</a></li>
  857. <li><a class="reference external" href="#symmetricDifference,HashSet[A],HashSet[A]">symmetricDifference proc</a></li>
  858. </ul>
  859. <p><strong class="examples_text">Example:</strong></p>
  860. <pre class="listing"><span class="Keyword">let</span>
  861. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  862. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;b&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;c&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  863. <span class="Identifier">c</span> <span class="Operator">=</span> <span class="Identifier">intersection</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">)</span>
  864. <span class="Identifier">assert</span> <span class="Identifier">c</span> <span class="Operator">==</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
  865. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L412" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  866. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L412" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  867. </dd>
  868. </div>
  869. </div>
  870. <div id="isValid-procs-all">
  871. <div id="isValid,HashSet[A]">
  872. <dt><pre><span class="Keyword">proc</span> <a href="#isValid%2CHashSet%5BA%5D"><span class="Identifier">isValid</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">&quot;Deprecated since v0.20; sets are initialized by default&quot;</span></span>.}</pre></dt>
  873. <dd>
  874. <div class="deprecation-message">
  875. <b>Deprecated:</b> Deprecated since v0.20; sets are initialized by default
  876. </div>
  877. Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if the set has been initialized (with <a class="reference external" href="#initHashSet">initHashSet proc</a> or <a class="reference external" href="#init,HashSet[A]">init proc</a>).
  878. <p><strong class="examples_text">Example:</strong></p>
  879. <pre class="listing"><span class="Keyword">proc</span> <span class="Identifier">savePreferences</span><span class="Punctuation">(</span><span class="Identifier">options</span><span class="Punctuation">:</span> <span class="Identifier">HashSet</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Operator">=</span>
  880. <span class="Identifier">assert</span> <span class="Identifier">options</span><span class="Operator">.</span><span class="Identifier">isValid</span><span class="Punctuation">,</span> <span class="StringLit">&quot;Pass an initialized set!&quot;</span>
  881. <span class="Comment"># Do stuff here, may crash in release builds!</span></pre>
  882. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L609" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  883. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L609" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  884. </dd>
  885. </div>
  886. </div>
  887. <div id="len-procs-all">
  888. <div id="len,HashSet[A]">
  889. <dt><pre><span class="Keyword">proc</span> <a href="#len%2CHashSet%5BA%5D"><span class="Identifier">len</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a></pre></dt>
  890. <dd>
  891. <p>Returns the number of elements in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  892. <p>Due to an implementation detail you can call this proc on variables which have not been initialized yet. The proc will return zero as the length then.</p>
  893. <p><strong class="examples_text">Example:</strong></p>
  894. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">HashSet</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span>
  895. <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>
  896. <span class="Keyword">let</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  897. <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span></pre>
  898. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L172" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  899. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L172" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  900. </dd>
  901. </div>
  902. <div id="len,OrderedSet[A]">
  903. <dt><pre><span class="Keyword">proc</span> <a href="#len%2COrderedSet%5BA%5D"><span class="Identifier">len</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</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>
  904. <dd>
  905. <p>Returns the number of elements in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  906. <p>Due to an implementation detail you can call this proc on variables which have not been initialized yet. The proc will return zero as the length then.</p>
  907. <p><strong class="examples_text">Example:</strong></p>
  908. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">OrderedSet</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span>
  909. <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>
  910. <span class="Keyword">let</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  911. <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span></pre>
  912. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L825" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  913. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L825" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  914. </dd>
  915. </div>
  916. </div>
  917. <div id="map-procs-all">
  918. <div id="map,HashSet[A],proc(A)">
  919. <dt><pre><span class="Keyword">proc</span> <a href="#map%2CHashSet%5BA%5D%2Cproc%28A%29"><span class="Identifier">map</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">,</span> <span class="Identifier">B</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">data</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">op</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">B</span> {.<span class="Identifier">closure</span>.}<span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">B</span><span class="Other">]</span> {.
  920. <span class="Identifier">effectsOf</span><span class="Other">:</span> <span class="Identifier">op</span>.}</pre></dt>
  921. <dd>
  922. <p>Returns a new set after applying <tt class="docutils literal"><span class="pre"><span class="Identifier">op</span></span></tt> proc on each of the elements of <tt class="docutils literal"><span class="pre"><span class="Identifier">data</span></span></tt> set.</p>
  923. <p>You can use this proc to transform the elements from a set.</p>
  924. <p><strong class="examples_text">Example:</strong></p>
  925. <pre class="listing"><span class="Keyword">let</span>
  926. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  927. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">map</span><span class="Punctuation">(</span><span class="Keyword">proc</span> <span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">string</span> <span class="Operator">=</span> <span class="Operator">$</span><span class="Identifier">x</span><span class="Punctuation">)</span>
  928. <span class="Identifier">assert</span> <span class="Identifier">b</span> <span class="Operator">==</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;1&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;2&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;3&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
  929. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L567" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  930. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L567" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  931. </dd>
  932. </div>
  933. </div>
  934. <div id="missingOrExcl-procs-all">
  935. <div id="missingOrExcl,HashSet[A],A">
  936. <dt><pre><span class="Keyword">proc</span> <a href="#missingOrExcl%2CHashSet%5BA%5D%2CA"><span class="Identifier">missingOrExcl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a></pre></dt>
  937. <dd>
  938. <p>Excludes <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> in the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and tells if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was already missing from <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  939. <p>The difference with regards to the <a class="reference external" href="#excl,HashSet[A],A">excl proc</a> is that this proc returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was missing from <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. The proc will return <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and it was removed during this call.</p>
  940. <p>See also:</p>
  941. <ul class="simple"><li><a class="reference external" href="#excl,HashSet[A],A">excl proc</a> for excluding an element</li>
  942. <li><a class="reference external" href="#excl,HashSet[A],HashSet[A]">excl proc</a> for excluding other set</li>
  943. <li><a class="reference external" href="#containsOrIncl,HashSet[A],A">containsOrIncl proc</a></li>
  944. </ul>
  945. <p><strong class="examples_text">Example:</strong></p>
  946. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">6</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  947. <span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">missingOrExcl</span><span class="Punctuation">(</span><span class="DecNumber">4</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  948. <span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">missingOrExcl</span><span class="Punctuation">(</span><span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  949. <span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">missingOrExcl</span><span class="Punctuation">(</span><span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span></pre>
  950. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L330" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  951. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L330" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  952. </dd>
  953. </div>
  954. <div id="missingOrExcl,OrderedSet[A],A">
  955. <dt><pre><span class="Keyword">proc</span> <a href="#missingOrExcl%2COrderedSet%5BA%5D%2CA"><span class="Identifier">missingOrExcl</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a></pre></dt>
  956. <dd>
  957. <p>Excludes <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> in the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and tells if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was already missing from <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. Efficiency: O(n).</p>
  958. <p>The difference with regards to the <a class="reference external" href="#excl,OrderedSet[A],A">excl proc</a> is that this proc returns <tt class="docutils literal"><span class="pre"><span class="Identifier">true</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was missing from <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>. The proc will return <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt> if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> was in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> and it was removed during this call.</p>
  959. <p>See also:</p>
  960. <ul class="simple"><li><a class="reference external" href="#excl,OrderedSet[A],A">excl proc</a></li>
  961. <li><a class="reference external" href="#containsOrIncl,OrderedSet[A],A">containsOrIncl proc</a></li>
  962. </ul>
  963. <p><strong class="examples_text">Example:</strong></p>
  964. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">6</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  965. <span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">missingOrExcl</span><span class="Punctuation">(</span><span class="DecNumber">4</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span>
  966. <span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">missingOrExcl</span><span class="Punctuation">(</span><span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">false</span>
  967. <span class="Identifier">assert</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">missingOrExcl</span><span class="Punctuation">(</span><span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">true</span></pre>
  968. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L785" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  969. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L785" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  970. </dd>
  971. </div>
  972. </div>
  973. <div id="pop-procs-all">
  974. <div id="pop,HashSet[A]">
  975. <dt><pre><span class="Keyword">proc</span> <a href="#pop%2CHashSet%5BA%5D"><span class="Identifier">pop</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">A</span></pre></dt>
  976. <dd>
  977. <p>Removes and returns an arbitrary element from the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  978. <p>Raises <tt class="docutils literal"><span class="pre"><span class="Identifier">KeyError</span></span></tt> if the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> is empty.</p>
  979. <p>See also:</p>
  980. <ul class="simple"><li><a class="reference external" href="#clear,HashSet[A]">clear proc</a></li>
  981. </ul>
  982. <p><strong class="examples_text">Example:</strong></p>
  983. <pre class="listing"><span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  984. <span class="Identifier">assert</span> <span class="Punctuation">[</span><span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">pop</span><span class="Punctuation">,</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">pop</span><span class="Punctuation">]</span> <span class="Keyword">in</span> <span class="Punctuation">[</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</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">1</span><span class="Punctuation">]</span><span class="Punctuation">]</span> <span class="Comment"># order unspecified</span>
  985. <span class="Identifier">doAssertRaises</span><span class="Punctuation">(</span><span class="Identifier">KeyError</span><span class="Punctuation">,</span> <span class="Identifier">echo</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">pop</span><span class="Punctuation">)</span></pre>
  986. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L350" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  987. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L350" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  988. </dd>
  989. </div>
  990. </div>
  991. <div id="symmetricDifference-procs-all">
  992. <div id="symmetricDifference,HashSet[A],HashSet[A]">
  993. <dt><pre><span class="Keyword">proc</span> <a href="#symmetricDifference%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">symmetricDifference</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s1</span><span class="Other">,</span> <span class="Identifier">s2</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  994. <dd>
  995. <p>Returns the symmetric difference of the sets <tt class="docutils literal"><span class="pre"><span class="Identifier">s1</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">s2</span></span></tt>.</p>
  996. <p>The same as <a class="reference external" href="#-+-,HashSet[A],HashSet[A]">s1 -+- s2</a>.</p>
  997. <p>The symmetric difference of two sets is represented mathematically as <em>A △ B</em> or <em>A ⊖ B</em> and is the set of all objects that are members of <tt class="docutils literal"><span class="pre"><span class="Identifier">s1</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Identifier">s2</span></span></tt> but not both at the same time.</p>
  998. <p>See also:</p>
  999. <ul class="simple"><li><a class="reference external" href="#union,HashSet[A],HashSet[A]">union proc</a></li>
  1000. <li><a class="reference external" href="#intersection,HashSet[A],HashSet[A]">intersection proc</a></li>
  1001. <li><a class="reference external" href="#difference,HashSet[A],HashSet[A]">difference proc</a></li>
  1002. </ul>
  1003. <p><strong class="examples_text">Example:</strong></p>
  1004. <pre class="listing"><span class="Keyword">let</span>
  1005. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  1006. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;b&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;c&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  1007. <span class="Identifier">c</span> <span class="Operator">=</span> <span class="Identifier">symmetricDifference</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">)</span>
  1008. <span class="Identifier">assert</span> <span class="Identifier">c</span> <span class="Operator">==</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;c&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
  1009. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L467" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1010. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L467" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1011. </dd>
  1012. </div>
  1013. </div>
  1014. <div id="toHashSet-procs-all">
  1015. <div id="toHashSet,openArray[A]">
  1016. <dt><pre><span class="Keyword">proc</span> <a href="#toHashSet%2CopenArray%5BA%5D"><span class="Identifier">toHashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">keys</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  1017. <dd>
  1018. <p>Creates a new hash set that contains the members of the given collection (seq, array, or string) <tt class="docutils literal"><span class="pre"><span class="Identifier">keys</span></span></tt>.</p>
  1019. <p>Duplicates are removed.</p>
  1020. <p>See also:</p>
  1021. <ul class="simple"><li><a class="reference external" href="#initHashSet">initHashSet proc</a></li>
  1022. </ul>
  1023. <p><strong class="examples_text">Example:</strong></p>
  1024. <pre class="listing"><span class="Keyword">let</span>
  1025. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  1026. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="StringLit">&quot;abracadabra&quot;</span><span class="Punctuation">)</span>
  1027. <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>
  1028. <span class="Comment">## a == {2, 3, 5}</span>
  1029. <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">b</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
  1030. <span class="Comment">## b == {'a', 'b', 'c', 'd', 'r'}</span></pre>
  1031. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L228" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1032. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L228" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1033. </dd>
  1034. </div>
  1035. </div>
  1036. <div id="toOrderedSet-procs-all">
  1037. <div id="toOrderedSet,openArray[A]">
  1038. <dt><pre><span class="Keyword">proc</span> <a href="#toOrderedSet%2CopenArray%5BA%5D"><span class="Identifier">toOrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">keys</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  1039. <dd>
  1040. <p>Creates a new hash set that contains the members of the given collection (seq, array, or string) <tt class="docutils literal"><span class="pre"><span class="Identifier">keys</span></span></tt>.</p>
  1041. <p>Duplicates are removed.</p>
  1042. <p>See also:</p>
  1043. <ul class="simple"><li><a class="reference external" href="#initOrderedSet">initOrderedSet proc</a></li>
  1044. </ul>
  1045. <p><strong class="examples_text">Example:</strong></p>
  1046. <pre class="listing"><span class="Keyword">let</span>
  1047. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  1048. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="StringLit">&quot;abracadabra&quot;</span><span class="Punctuation">)</span>
  1049. <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>
  1050. <span class="Comment">## a == {5, 3, 2} # different than in HashSet</span>
  1051. <span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">b</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
  1052. <span class="Comment">## b == {'a', 'b', 'r', 'c', 'd'} # different than in HashSet</span></pre>
  1053. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L676" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1054. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L676" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1055. </dd>
  1056. </div>
  1057. </div>
  1058. <div id="toSet-procs-all">
  1059. <div id="toSet,openArray[A]">
  1060. <dt><pre><span class="Keyword">proc</span> <a href="#toSet%2CopenArray%5BA%5D"><span class="Identifier">toSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">keys</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span> {.
  1061. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">&quot;Deprecated since v0.20, use \'toHashSet\'&quot;</span></span>.}</pre></dt>
  1062. <dd>
  1063. <div class="deprecation-message">
  1064. <b>Deprecated:</b> Deprecated since v0.20, use &apos;toHashSet&apos;
  1065. </div>
  1066. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L606" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1067. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L606" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1068. </dd>
  1069. </div>
  1070. </div>
  1071. <div id="union-procs-all">
  1072. <div id="union,HashSet[A],HashSet[A]">
  1073. <dt><pre><span class="Keyword">proc</span> <a href="#union%2CHashSet%5BA%5D%2CHashSet%5BA%5D"><span class="Identifier">union</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s1</span><span class="Other">,</span> <span class="Identifier">s2</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  1074. <dd>
  1075. <p>Returns the union of the sets <tt class="docutils literal"><span class="pre"><span class="Identifier">s1</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">s2</span></span></tt>.</p>
  1076. <p>The same as <a class="reference external" href="#+,HashSet[A],HashSet[A]">s1 + s2</a>.</p>
  1077. <p>The union of two sets is represented mathematically as <em>A ∪ B</em> and is the set of all objects that are members of <tt class="docutils literal"><span class="pre"><span class="Identifier">s1</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">s2</span></span></tt> or both.</p>
  1078. <p>See also:</p>
  1079. <ul class="simple"><li><a class="reference external" href="#intersection,HashSet[A],HashSet[A]">intersection proc</a></li>
  1080. <li><a class="reference external" href="#difference,HashSet[A],HashSet[A]">difference proc</a></li>
  1081. <li><a class="reference external" href="#symmetricDifference,HashSet[A],HashSet[A]">symmetricDifference proc</a></li>
  1082. </ul>
  1083. <p><strong class="examples_text">Example:</strong></p>
  1084. <pre class="listing"><span class="Keyword">let</span>
  1085. <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  1086. <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;b&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;c&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  1087. <span class="Identifier">c</span> <span class="Operator">=</span> <span class="Identifier">union</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">)</span>
  1088. <span class="Identifier">assert</span> <span class="Identifier">c</span> <span class="Operator">==</span> <span class="Identifier">toHashSet</span><span class="Punctuation">(</span><span class="Punctuation">[</span><span class="StringLit">&quot;a&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;b&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;c&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
  1089. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L390" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1090. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L390" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1091. </dd>
  1092. </div>
  1093. </div>
  1094. </dl>
  1095. </div>
  1096. <div class="section" id="15">
  1097. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  1098. <dl class="item">
  1099. <div id="items-iterators-all">
  1100. <div id="items.i,HashSet[A]">
  1101. <dt><pre><span class="Keyword">iterator</span> <a href="#items.i%2CHashSet%5BA%5D"><span class="Identifier">items</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#HashSet"><span class="Identifier">HashSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">A</span></pre></dt>
  1102. <dd>
  1103. <p>Iterates over elements of the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
  1104. <p>If you need a sequence with the elements you can use <a class="reference external" href="sequtils.html#toSeq.t,untyped">sequtils.toSeq template</a>.</p>
  1105. <p><pre class="listing"><span class="Keyword">type</span>
  1106. <span class="Identifier">pair</span> <span class="Operator">=</span> <span class="Keyword">tuple</span><span class="Punctuation">[</span><span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">]</span>
  1107. <span class="Keyword">var</span>
  1108. <span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">initHashSet</span><span class="Punctuation">[</span><span class="Identifier">pair</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1109. <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  1110. <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  1111. <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  1112. <span class="Keyword">for</span> <span class="Identifier">x</span><span class="Punctuation">,</span> <span class="Identifier">y</span> <span class="Keyword">in</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">items</span><span class="Punctuation">:</span>
  1113. <span class="Identifier">b</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="Punctuation">(</span><span class="Identifier">x</span> <span class="Operator">-</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="Identifier">y</span> <span class="Operator">+</span> <span class="DecNumber">1</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  1114. <span class="Identifier">assert</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
  1115. <span class="Identifier">echo</span> <span class="Identifier">b</span>
  1116. <span class="Comment"># --&gt; {(a: 1, b: 3), (a: 0, b: 4)}</span></pre></p>
  1117. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L248" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1118. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L248" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1119. </dd>
  1120. </div>
  1121. <div id="items.i,OrderedSet[A]">
  1122. <dt><pre><span class="Keyword">iterator</span> <a href="#items.i%2COrderedSet%5BA%5D"><span class="Identifier">items</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">A</span></pre></dt>
  1123. <dd>
  1124. <p>Iterates over keys in the ordered set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> in insertion order.</p>
  1125. <p>If you need a sequence with the elements you can use <a class="reference external" href="sequtils.html#toSeq.t,untyped">sequtils.toSeq template</a>.</p>
  1126. <p><pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">initOrderedSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1127. <span class="Keyword">for</span> <span class="Identifier">value</span> <span class="Keyword">in</span> <span class="Punctuation">[</span><span class="DecNumber">9</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">8</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">]</span><span class="Punctuation">:</span>
  1128. <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="Identifier">value</span><span class="Punctuation">)</span>
  1129. <span class="Keyword">for</span> <span class="Identifier">value</span> <span class="Keyword">in</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">items</span><span class="Punctuation">:</span>
  1130. <span class="Identifier">echo</span> <span class="StringLit">&quot;Got &quot;</span><span class="Punctuation">,</span> <span class="Identifier">value</span>
  1131. <span class="Comment"># --&gt; Got 9</span>
  1132. <span class="Comment"># --&gt; Got 2</span>
  1133. <span class="Comment"># --&gt; Got 1</span>
  1134. <span class="Comment"># --&gt; Got 5</span>
  1135. <span class="Comment"># --&gt; Got 8</span>
  1136. <span class="Comment"># --&gt; Got 4</span></pre></p>
  1137. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L894" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1138. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L894" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1139. </dd>
  1140. </div>
  1141. </div>
  1142. <div id="pairs-iterators-all">
  1143. <div id="pairs.i,OrderedSet[A]">
  1144. <dt><pre><span class="Keyword">iterator</span> <a href="#pairs.i%2COrderedSet%5BA%5D"><span class="Identifier">pairs</span></a><span class="Other">[</span><span class="Identifier">A</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="sets.html#OrderedSet"><span class="Identifier">OrderedSet</span></a><span class="Other">[</span><span class="Identifier">A</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">a</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <span class="Identifier">b</span><span class="Other">:</span> <span class="Identifier">A</span><span class="Other">]</span></pre></dt>
  1145. <dd>
  1146. Iterates through (position, value) tuples of OrderedSet <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
  1147. <p><strong class="examples_text">Example:</strong></p>
  1148. <pre class="listing"><span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="StringLit">&quot;abracadabra&quot;</span><span class="Punctuation">)</span>
  1149. <span class="Keyword">var</span> <span class="Identifier">p</span> <span class="Operator">=</span> <span class="Identifier">newSeq</span><span class="Punctuation">[</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">char</span><span class="Punctuation">)</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  1150. <span class="Keyword">for</span> <span class="Identifier">x</span> <span class="Keyword">in</span> <span class="Identifier">pairs</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  1151. <span class="Identifier">p</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">)</span>
  1152. <span class="Identifier">assert</span> <span class="Identifier">p</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="CharLit">'a'</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="CharLit">'b'</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="CharLit">'r'</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="CharLit">'c'</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="Punctuation">(</span><span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="CharLit">'d'</span><span class="Punctuation">)</span><span class="Punctuation">]</span></pre>
  1153. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L918" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1154. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/sets.nim#L918" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1155. </dd>
  1156. </div>
  1157. </div>
  1158. </dl>
  1159. </div>
  1160. </div>
  1161. </div>
  1162. <div class="twelve-columns footer">
  1163. <span class="nim-sprite"></span>
  1164. <br>
  1165. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-06 22:28:17 UTC</small>
  1166. </div>
  1167. </div>
  1168. </div>
  1169. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  1170. </body>
  1171. </html>