Files
Nim/sets.html
github-actions[bot] ef3d9e7b38 Deploy to GitHub pages
2025-12-28 15:55:52 +00:00

1419 lines
160 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This file is generated by Nim. -->
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>std/sets</title>
<!-- Google fonts -->
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
<!-- JS -->
<script type="text/javascript" src="dochack.js?v=2.3.1"></script>
</head>
<body>
<div class="document" id="documentId">
<div class="container">
<h1 class="title">std/sets</h1>
<div class="row">
<div class="three columns">
<div class="theme-select-wrapper">
<label for="theme-select">Theme:&nbsp;</label>
<select id="theme-select" onchange="setTheme(this.value)">
<option value="auto">🌗 Match OS</option>
<option value="dark">🌑 Dark</option>
<option value="light">🌕 Light</option>
</select>
</div>
<div id="global-links">
<ul class="simple-boot">
<li><a href="manual.html">Manual</a></li>
<li><a href="lib.html">Standard library</a></li>
<li> <a id="indexLink" href="theindex.html">Index</a></li>
<li><a href="compiler/theindex.html">Compiler docs</a></li>
<li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
<li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
</ul>
</div>
<div id="searchInputDiv">
Search: <input type="search" id="searchInput"
oninput="search()" />
</div>
<ul class="simple simple-toc" id="toc-list">
<li>
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#HashSet" title="HashSet[A] {..} = object">HashSet</a></li>
<li><a class="reference" href="#OrderedSet" title="OrderedSet[A] {..} = object">OrderedSet</a></li>
<li><a class="reference" href="#SomeSet" title="SomeSet[A] = HashSet[A] | OrderedSet[A]">SomeSet</a></li>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#defaultInitialSize" title="defaultInitialSize = 64">defaultInitialSize</a></li>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">$
<li><a class="reference" href="#%24%2CHashSet%5BA%5D" title="`$`[A](s: HashSet[A]): string">`$`[A](s: HashSet[A]): string</a></li>
<li><a class="reference" href="#%24%2COrderedSet%5BA%5D" title="`$`[A](s: OrderedSet[A]): string">`$`[A](s: OrderedSet[A]): string</a></li>
</ul>
<ul class="simple nested-toc-section">*
<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>
</ul>
<ul class="simple nested-toc-section">+
<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>
</ul>
<ul class="simple nested-toc-section">-
<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>
</ul>
<ul class="simple nested-toc-section">-+-
<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>
</ul>
<ul class="simple nested-toc-section"><
<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>
</ul>
<ul class="simple nested-toc-section"><=
<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>
</ul>
<ul class="simple nested-toc-section">==
<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>
<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>
</ul>
<ul class="simple nested-toc-section">[]
<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>
</ul>
<ul class="simple nested-toc-section">card
<li><a class="reference" href="#card%2CHashSet%5BA%5D" title="card[A](s: HashSet[A]): int">card[A](s: HashSet[A]): int</a></li>
<li><a class="reference" href="#card%2COrderedSet%5BA%5D" title="card[A](s: OrderedSet[A]): int">card[A](s: OrderedSet[A]): int</a></li>
</ul>
<ul class="simple nested-toc-section">clear
<li><a class="reference" href="#clear%2CHashSet%5BA%5D" title="clear[A](s: var HashSet[A])">clear[A](s: var HashSet[A])</a></li>
<li><a class="reference" href="#clear%2COrderedSet%5BA%5D" title="clear[A](s: var OrderedSet[A])">clear[A](s: var OrderedSet[A])</a></li>
</ul>
<ul class="simple nested-toc-section">contains
<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>
<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>
</ul>
<ul class="simple nested-toc-section">containsOrIncl
<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>
<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>
</ul>
<ul class="simple nested-toc-section">difference
<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>
</ul>
<ul class="simple nested-toc-section">disjoint
<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>
</ul>
<ul class="simple nested-toc-section">excl
<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>
<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>
<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>
</ul>
<ul class="simple nested-toc-section">hash
<li><a class="reference" href="#hash%2CHashSet%5BA%5D" title="hash[A](s: HashSet[A]): Hash">hash[A](s: HashSet[A]): Hash</a></li>
<li><a class="reference" href="#hash%2COrderedSet%5BA%5D" title="hash[A](s: OrderedSet[A]): Hash">hash[A](s: OrderedSet[A]): Hash</a></li>
</ul>
<ul class="simple nested-toc-section">incl
<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>
<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>
<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>
<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>
</ul>
<ul class="simple nested-toc-section">init
<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>
<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>
</ul>
<ul class="simple nested-toc-section">initHashSet
<li><a class="reference" href="#initHashSet" title="initHashSet[A](initialSize = defaultInitialSize): HashSet[A]">initHashSet[A](initialSize = defaultInitialSize): HashSet[A]</a></li>
</ul>
<ul class="simple nested-toc-section">initOrderedSet
<li><a class="reference" href="#initOrderedSet" title="initOrderedSet[A](initialSize = defaultInitialSize): OrderedSet[A]">initOrderedSet[A](initialSize = defaultInitialSize): OrderedSet[A]</a></li>
</ul>
<ul class="simple nested-toc-section">initSet
<li><a class="reference" href="#initSet" title="initSet[A](initialSize = defaultInitialSize): HashSet[A]">initSet[A](initialSize = defaultInitialSize): HashSet[A]</a></li>
</ul>
<ul class="simple nested-toc-section">intersection
<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>
</ul>
<ul class="simple nested-toc-section">isValid
<li><a class="reference" href="#isValid%2CHashSet%5BA%5D" title="isValid[A](s: HashSet[A]): bool">isValid[A](s: HashSet[A]): bool</a></li>
</ul>
<ul class="simple nested-toc-section">len
<li><a class="reference" href="#len%2CHashSet%5BA%5D" title="len[A](s: HashSet[A]): int">len[A](s: HashSet[A]): int</a></li>
<li><a class="reference" href="#len%2COrderedSet%5BA%5D" title="len[A](s: OrderedSet[A]): int">len[A](s: OrderedSet[A]): int</a></li>
</ul>
<ul class="simple nested-toc-section">map
<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>
</ul>
<ul class="simple nested-toc-section">missingOrExcl
<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>
<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>
</ul>
<ul class="simple nested-toc-section">pop
<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>
</ul>
<ul class="simple nested-toc-section">symmetricDifference
<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>
</ul>
<ul class="simple nested-toc-section">toHashSet
<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>
</ul>
<ul class="simple nested-toc-section">toOrderedSet
<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>
</ul>
<ul class="simple nested-toc-section">toSet
<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>
</ul>
<ul class="simple nested-toc-section">union
<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>
</ul>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">items
<li><a class="reference" href="#items.i%2CHashSet%5BA%5D" title="items[A](s: HashSet[A]): A">items[A](s: HashSet[A]): A</a></li>
<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>
</ul>
<ul class="simple nested-toc-section">pairs
<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>
</ul>
</ul>
</details>
</li>
</ul>
</div>
<div class="nine columns" id="content">
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<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;
<div id="tocRoot"></div>
<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>
<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>
<p>Common usages of sets:</p>
<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>
<li>membership testing</li>
<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>
</ul>
<p><strong>Examples:</strong></p>
<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>
<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>
<span class="Keyword">let</span>
<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>
<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>
<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>
<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>
<span class="Identifier">echo</span> <span class="Identifier">s1</span> <span class="Operator">*</span> <span class="Identifier">s2</span> <span class="Comment"># {5}</span>
<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>
<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>
<p><strong>See also:</strong></p>
<ul class="simple"><li><a class="reference external" href="intsets.html">intsets module</a> for efficient int sets</li>
<li><a class="reference external" href="tables.html">tables module</a> for hash tables</li>
</ul>
</p>
<div class="section" id="6">
<h1><a class="toc-backref" href="#6">Imports</a></h1>
<dl class="item">
<a class="reference external" href="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>
</dl>
</div>
<div class="section" id="7">
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="HashSet">
<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>
<dd>
<p>
A generic hash set.</p>
<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>
<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;
<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;
</dd>
</div>
<div id="OrderedSet">
<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>
<dd>
<p>
A generic hash set that remembers insertion order.</p>
<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>
<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;
<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;
</dd>
</div>
<div id="SomeSet">
<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>
<dd>
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>.
<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;
<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;
</dd>
</div>
</dl>
</div>
<div class="section" id="10">
<h1><a class="toc-backref" href="#10">Consts</a></h1>
<dl class="item">
<div id="defaultInitialSize">
<dt><pre><a href="sets.html#defaultInitialSize"><span class="Identifier">defaultInitialSize</span></a> <span class="Other">=</span> <span class="DecNumber">64</span></pre></dt>
<dd>
<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;
<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;
</dd>
</div>
</dl>
</div>
<div class="section" id="12">
<h1><a class="toc-backref" href="#12">Procs</a></h1>
<dl class="item">
<div id="$-procs-all">
<div id="$,HashSet[A]">
<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>
<dd>
<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>
<p>Don't use this proc for serialization, the representation may change at any moment and values are not escaped.</p>
<p><strong>Examples:</strong></p>
<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>
<span class="Comment"># --&gt; {2, 4, 5}</span>
<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>
<span class="Comment"># --&gt; {no, esc'aping, is &quot; provided}</span></pre></p>
<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;
<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;
</dd>
</div>
<div id="$,OrderedSet[A]">
<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>
<dd>
<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>
<p>Don't use this proc for serialization, the representation may change at any moment and values are not escaped.</p>
<p><strong>Examples:</strong></p>
<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>
<span class="Comment"># --&gt; {2, 4, 5}</span>
<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>
<span class="Comment"># --&gt; {no, esc'aping, is &quot; provided}</span></pre></p>
<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;
<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;
</dd>
</div>
</div>
<div id="*-procs-all">
<div id="*,HashSet[A],HashSet[A]">
<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>
<dd>
Alias for <a class="reference external" href="#intersection,HashSet[A],HashSet[A]">intersection(s1, s2)</a>.
<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;
<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;
</dd>
</div>
</div>
<div id="+-procs-all">
<div id="+,HashSet[A],HashSet[A]">
<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>
<dd>
Alias for <a class="reference external" href="#union,HashSet[A],HashSet[A]">union(s1, s2)</a>.
<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;
<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;
</dd>
</div>
</div>
<div id="--procs-all">
<div id="-,HashSet[A],HashSet[A]">
<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>
<dd>
Alias for <a class="reference external" href="#difference,HashSet[A],HashSet[A]">difference(s1, s2)</a>.
<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;
<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;
</dd>
</div>
</div>
<div id="-+--procs-all">
<div id="-+-,HashSet[A],HashSet[A]">
<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>
<dd>
Alias for <a class="reference external" href="#symmetricDifference,HashSet[A],HashSet[A]">symmetricDifference(s1, s2)</a>.
<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;
<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;
</dd>
</div>
</div>
<div id="&lt;-procs-all">
<div id="<,HashSet[A],HashSet[A]">
<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>
<dd>
<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>
<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>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="&lt;=-procs-all">
<div id="<=,HashSet[A],HashSet[A]">
<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>
<dd>
<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>
<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>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<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>
<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>
<span class="Identifier">assert</span> <span class="Identifier">a</span> <span class="Operator">&lt;=</span> <span class="Identifier">a</span></pre>
<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;
<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;
</dd>
</div>
</div>
<div id="==-procs-all">
<div id="==,HashSet[A],HashSet[A]">
<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>
<dd>
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.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<span class="Identifier">assert</span> <span class="Identifier">a</span> <span class="Operator">==</span> <span class="Identifier">b</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/sets.nim#L557" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<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;
</dd>
</div>
<div id="==,OrderedSet[A],OrderedSet[A]">
<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>
<dd>
Equality for ordered sets.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="[]-procs-all">
<div id="[],HashSet[A],A">
<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>
<dd>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="card-procs-all">
<div id="card,HashSet[A]">
<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>
<dd>
<p>Alias for <a class="reference external" href="#len,HashSet[A]">len()</a>.</p>
<p>Card stands for the <a class="reference external" href="https://en.wikipedia.org/wiki/Cardinality">cardinality</a> of a set.</p>
<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;
<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;
</dd>
</div>
<div id="card,OrderedSet[A]">
<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>
<dd>
<p>Alias for <a class="reference external" href="#len,OrderedSet[A]">len()</a>.</p>
<p>Card stands for the <a class="reference external" href="https://en.wikipedia.org/wiki/Cardinality">cardinality</a> of a set.</p>
<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;
<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;
</dd>
</div>
</div>
<div id="clear-procs-all">
<div id="clear,HashSet[A]">
<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>
<dd>
<p>Clears the HashSet back to an empty state, without shrinking any of the existing storage.</p>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#pop,HashSet[A]">pop proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<span class="Identifier">clear</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">)</span>
<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>
<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;
<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;
</dd>
</div>
<div id="clear,OrderedSet[A]">
<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>
<dd>
<p>Clears the OrderedSet back to an empty state, without shrinking any of the existing storage.</p>
<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>
<p><strong class="examples_text">Example:</strong></p>
<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>
<span class="Identifier">clear</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">)</span>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="contains-procs-all">
<div id="contains,HashSet[A],A">
<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>
<dd>
<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>
<p>This allows the usage of <tt class="docutils literal"><span class="pre"><span class="Keyword">in</span></span></tt> operator.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#incl,HashSet[A],A">incl proc</a></li>
<li><a class="reference external" href="#containsOrIncl,HashSet[A],A">containsOrIncl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<span class="Identifier">assert</span> <span class="DecNumber">2</span> <span class="Keyword">notin</span> <span class="Identifier">values</span>
<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>
<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>
<span class="Identifier">assert</span> <span class="DecNumber">2</span> <span class="Keyword">in</span> <span class="Identifier">values</span></pre>
<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;
<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;
</dd>
</div>
<div id="contains,OrderedSet[A],A">
<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>
<dd>
<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>
<p>This allows the usage of <tt class="docutils literal"><span class="pre"><span class="Keyword">in</span></span></tt> operator.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#incl,OrderedSet[A],A">incl proc</a></li>
<li><a class="reference external" href="#containsOrIncl,OrderedSet[A],A">containsOrIncl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<span class="Identifier">assert</span> <span class="DecNumber">2</span> <span class="Keyword">notin</span> <span class="Identifier">values</span>
<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>
<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>
<span class="Identifier">assert</span> <span class="DecNumber">2</span> <span class="Keyword">in</span> <span class="Identifier">values</span></pre>
<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;
<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;
</dd>
</div>
</div>
<div id="containsOrIncl-procs-all">
<div id="containsOrIncl,HashSet[A],A">
<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>
<dd>
<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>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#incl,HashSet[A],A">incl proc</a> for including an element</li>
<li><a class="reference external" href="#incl,HashSet[A],HashSet[A]">incl proc</a> for including other set</li>
<li><a class="reference external" href="#missingOrExcl,HashSet[A],A">missingOrExcl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
<div id="containsOrIncl,OrderedSet[A],A">
<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>
<dd>
<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>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#incl,OrderedSet[A],A">incl proc</a> for including an element</li>
<li><a class="reference external" href="#missingOrExcl,OrderedSet[A],A">missingOrExcl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="difference-procs-all">
<div id="difference,HashSet[A],HashSet[A]">
<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>
<dd>
<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>
<p>The same as <a class="reference external" href="#-,HashSet[A],HashSet[A]">s1 - s2</a>.</p>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#union,HashSet[A],HashSet[A]">union proc</a></li>
<li><a class="reference external" href="#intersection,HashSet[A],HashSet[A]">intersection proc</a></li>
<li><a class="reference external" href="#symmetricDifference,HashSet[A],HashSet[A]">symmetricDifference proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="disjoint-procs-all">
<div id="disjoint,HashSet[A],HashSet[A]">
<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>
<dd>
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.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="excl-procs-all">
<div id="excl,HashSet[A],A">
<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>
<dd>
<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>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#incl,HashSet[A],A">incl proc</a> for including an element</li>
<li><a class="reference external" href="#excl,HashSet[A],HashSet[A]">excl proc</a> for excluding other set</li>
<li><a class="reference external" href="#missingOrExcl,HashSet[A],A">missingOrExcl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
<div id="excl,HashSet[A],HashSet[A]">
<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>
<dd>
<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>
<p>This is the in-place version of <a class="reference external" href="#-,HashSet[A],HashSet[A]">s - other</a>.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#incl,HashSet[A],HashSet[A]">incl proc</a> for including other set</li>
<li><a class="reference external" href="#excl,HashSet[A],A">excl proc</a> for excluding an element</li>
<li><a class="reference external" href="#missingOrExcl,HashSet[A],A">missingOrExcl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span>
<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>
<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>
<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>
<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>
<span class="Comment">## numbers == {1, 3, 5}</span></pre>
<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;
<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;
</dd>
</div>
<div id="excl,OrderedSet[A],A">
<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>
<dd>
<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>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#incl,OrderedSet[A],A">incl proc</a> for including an element</li>
<li><a class="reference external" href="#missingOrExcl,OrderedSet[A],A">missingOrExcl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="hash-procs-all">
<div id="hash,HashSet[A]">
<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>
<dd>
Hashing of HashSet.
<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;
<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;
</dd>
</div>
<div id="hash,OrderedSet[A]">
<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>
<dd>
Hashing of OrderedSet.
<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;
<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;
</dd>
</div>
</div>
<div id="incl-procs-all">
<div id="incl,HashSet[A],A">
<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>
<dd>
<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>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#excl,HashSet[A],A">excl proc</a> for excluding an element</li>
<li><a class="reference external" href="#incl,HashSet[A],HashSet[A]">incl proc</a> for including other set</li>
<li><a class="reference external" href="#containsOrIncl,HashSet[A],A">containsOrIncl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
<div id="incl,HashSet[A],HashSet[A]">
<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>
<dd>
<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>
<p>This is the in-place version of <a class="reference external" href="#+,HashSet[A],HashSet[A]">s + other</a>.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#excl,HashSet[A],HashSet[A]">excl proc</a> for excluding other set</li>
<li><a class="reference external" href="#incl,HashSet[A],A">incl proc</a> for including an element</li>
<li><a class="reference external" href="#containsOrIncl,HashSet[A],A">containsOrIncl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
<div id="incl,HashSet[A],OrderedSet[A]">
<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>
<dd>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#incl,OrderedSet[A],A">incl proc</a> for including an element</li>
<li><a class="reference external" href="#containsOrIncl,OrderedSet[A],A">containsOrIncl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
<div id="incl,OrderedSet[A],A">
<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>
<dd>
<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>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#excl,OrderedSet[A],A">excl proc</a> for excluding an element</li>
<li><a class="reference external" href="#incl,HashSet[A],OrderedSet[A]">incl proc</a> for including other set</li>
<li><a class="reference external" href="#containsOrIncl,OrderedSet[A],A">containsOrIncl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="init-procs-all">
<div id="init,HashSet[A]">
<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>
<dd>
<p>Initializes a hash set.</p>
<p>Starting from Nim v0.20, sets are initialized by default and it is not necessary to call this function explicitly.</p>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#initHashSet">initHashSet proc</a></li>
<li><a class="reference external" href="#toHashSet,openArray[A]">toHashSet proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">HashSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span>
<span class="Identifier">init</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span></pre>
<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;
<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;
</dd>
</div>
<div id="init,OrderedSet[A]">
<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>
<dd>
<p>Initializes an ordered hash set.</p>
<p>Starting from Nim v0.20, sets are initialized by default and it is not necessary to call this function explicitly.</p>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#initOrderedSet">initOrderedSet proc</a></li>
<li><a class="reference external" href="#toOrderedSet,openArray[A]">toOrderedSet proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">OrderedSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span>
<span class="Identifier">init</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span></pre>
<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;
<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;
</dd>
</div>
</div>
<div id="initHashSet-procs-all">
<div id="initHashSet">
<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>
<dd>
<p>Wrapper around <a class="reference external" href="#init,HashSet[A]">init proc</a> for initialization of hash sets.</p>
<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>
<p>Starting from Nim v0.20, sets are initialized by default and it is not necessary to call this function explicitly.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#toHashSet,openArray[A]">toHashSet proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">initHashSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
<span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre>
<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;
<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;
</dd>
</div>
</div>
<div id="initOrderedSet-procs-all">
<div id="initOrderedSet">
<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>
<dd>
<p>Wrapper around <a class="reference external" href="#init,OrderedSet[A]">init proc</a> for initialization of ordered hash sets.</p>
<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>
<p>Starting from Nim v0.20, sets are initialized by default and it is not necessary to call this function explicitly.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#toOrderedSet,openArray[A]">toOrderedSet proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">initOrderedSet</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
<span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre>
<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;
<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;
</dd>
</div>
</div>
<div id="initSet-procs-all">
<div id="initSet">
<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> {.
<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>
<dd>
<div class="deprecation-message">
<b>Deprecated:</b> Deprecated since v0.20, use &apos;initHashSet&apos;
</div>
<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;
<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;
</dd>
</div>
</div>
<div id="intersection-procs-all">
<div id="intersection,HashSet[A],HashSet[A]">
<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>
<dd>
<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>
<p>The same as <a class="reference external" href="#*,HashSet[A],HashSet[A]">s1 * s2</a>.</p>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#union,HashSet[A],HashSet[A]">union proc</a></li>
<li><a class="reference external" href="#difference,HashSet[A],HashSet[A]">difference proc</a></li>
<li><a class="reference external" href="#symmetricDifference,HashSet[A],HashSet[A]">symmetricDifference proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="isValid-procs-all">
<div id="isValid,HashSet[A]">
<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>
<dd>
<div class="deprecation-message">
<b>Deprecated:</b> Deprecated since v0.20; sets are initialized by default
</div>
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>).
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<span class="Comment"># Do stuff here, may crash in release builds!</span></pre>
<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;
<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;
</dd>
</div>
</div>
<div id="len-procs-all">
<div id="len,HashSet[A]">
<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>
<dd>
<p>Returns the number of elements in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
<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>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">HashSet</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span>
<span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
<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>
<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>
<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;
<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;
</dd>
</div>
<div id="len,OrderedSet[A]">
<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>
<dd>
<p>Returns the number of elements in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
<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>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">OrderedSet</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span>
<span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="map-procs-all">
<div id="map,HashSet[A],proc(A)">
<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> {.
<span class="Identifier">effectsOf</span><span class="Other">:</span> <span class="Identifier">op</span>.}</pre></dt>
<dd>
<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>
<p>You can use this proc to transform the elements from a set.</p>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="missingOrExcl-procs-all">
<div id="missingOrExcl,HashSet[A],A">
<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>
<dd>
<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>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#excl,HashSet[A],A">excl proc</a> for excluding an element</li>
<li><a class="reference external" href="#excl,HashSet[A],HashSet[A]">excl proc</a> for excluding other set</li>
<li><a class="reference external" href="#containsOrIncl,HashSet[A],A">containsOrIncl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
<div id="missingOrExcl,OrderedSet[A],A">
<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>
<dd>
<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>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#excl,OrderedSet[A],A">excl proc</a></li>
<li><a class="reference external" href="#containsOrIncl,OrderedSet[A],A">containsOrIncl proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="pop-procs-all">
<div id="pop,HashSet[A]">
<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>
<dd>
<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>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#clear,HashSet[A]">clear proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="symmetricDifference-procs-all">
<div id="symmetricDifference,HashSet[A],HashSet[A]">
<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>
<dd>
<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>
<p>The same as <a class="reference external" href="#-+-,HashSet[A],HashSet[A]">s1 -+- s2</a>.</p>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#union,HashSet[A],HashSet[A]">union proc</a></li>
<li><a class="reference external" href="#intersection,HashSet[A],HashSet[A]">intersection proc</a></li>
<li><a class="reference external" href="#difference,HashSet[A],HashSet[A]">difference proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
<div id="toHashSet-procs-all">
<div id="toHashSet,openArray[A]">
<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>
<dd>
<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>
<p>Duplicates are removed.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#initHashSet">initHashSet proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
<span class="Comment">## a == {2, 3, 5}</span>
<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>
<span class="Comment">## b == {'a', 'b', 'c', 'd', 'r'}</span></pre>
<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;
<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;
</dd>
</div>
</div>
<div id="toOrderedSet-procs-all">
<div id="toOrderedSet,openArray[A]">
<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>
<dd>
<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>
<p>Duplicates are removed.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#initOrderedSet">initOrderedSet proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<span class="Identifier">assert</span> <span class="Identifier">len</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
<span class="Comment">## a == {5, 3, 2} # different than in HashSet</span>
<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>
<span class="Comment">## b == {'a', 'b', 'r', 'c', 'd'} # different than in HashSet</span></pre>
<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;
<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;
</dd>
</div>
</div>
<div id="toSet-procs-all">
<div id="toSet,openArray[A]">
<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> {.
<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>
<dd>
<div class="deprecation-message">
<b>Deprecated:</b> Deprecated since v0.20, use &apos;toHashSet&apos;
</div>
<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;
<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;
</dd>
</div>
</div>
<div id="union-procs-all">
<div id="union,HashSet[A],HashSet[A]">
<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>
<dd>
<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>
<p>The same as <a class="reference external" href="#+,HashSet[A],HashSet[A]">s1 + s2</a>.</p>
<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>
<p>See also:</p>
<ul class="simple"><li><a class="reference external" href="#intersection,HashSet[A],HashSet[A]">intersection proc</a></li>
<li><a class="reference external" href="#difference,HashSet[A],HashSet[A]">difference proc</a></li>
<li><a class="reference external" href="#symmetricDifference,HashSet[A],HashSet[A]">symmetricDifference proc</a></li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span>
<span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
</dl>
</div>
<div class="section" id="15">
<h1><a class="toc-backref" href="#15">Iterators</a></h1>
<dl class="item">
<div id="items-iterators-all">
<div id="items.i,HashSet[A]">
<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>
<dd>
<p>Iterates over elements of the set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</p>
<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>
<p><pre class="listing"><span class="Keyword">type</span>
<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>
<span class="Keyword">var</span>
<span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span> <span class="Operator">=</span> <span class="Identifier">initHashSet</span><span class="Punctuation">[</span><span class="Identifier">pair</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
<span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">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>
<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>
<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>
<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>
<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>
<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>
<span class="Identifier">echo</span> <span class="Identifier">b</span>
<span class="Comment"># --&gt; {(a: 1, b: 3), (a: 0, b: 4)}</span></pre></p>
<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;
<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;
</dd>
</div>
<div id="items.i,OrderedSet[A]">
<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>
<dd>
<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>
<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>
<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>
<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>
<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>
<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>
<span class="Identifier">echo</span> <span class="StringLit">&quot;Got &quot;</span><span class="Punctuation">,</span> <span class="Identifier">value</span>
<span class="Comment"># --&gt; Got 9</span>
<span class="Comment"># --&gt; Got 2</span>
<span class="Comment"># --&gt; Got 1</span>
<span class="Comment"># --&gt; Got 5</span>
<span class="Comment"># --&gt; Got 8</span>
<span class="Comment"># --&gt; Got 4</span></pre></p>
<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;
<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;
</dd>
</div>
</div>
<div id="pairs-iterators-all">
<div id="pairs.i,OrderedSet[A]">
<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>
<dd>
Iterates through (position, value) tuples of OrderedSet <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">a</span> <span class="Operator">=</span> <span class="Identifier">toOrderedSet</span><span class="Punctuation">(</span><span class="StringLit">&quot;abracadabra&quot;</span><span class="Punctuation">)</span>
<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>
<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>
<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>
<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>
<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;
<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;
</dd>
</div>
</div>
</dl>
</div>
</div>
</div>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2025-12-28 15:55:12 UTC</small>
</div>
</div>
</div>
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
</body>
</html>