mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
463 lines
45 KiB
HTML
463 lines
45 KiB
HTML
<?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/heapqueue</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/heapqueue</h1>
|
|
<div class="row">
|
|
<div class="three columns">
|
|
<div class="theme-select-wrapper">
|
|
<label for="theme-select">Theme: </label>
|
|
<select id="theme-select" onchange="setTheme(this.value)">
|
|
<option value="auto">🌗 Match OS</option>
|
|
<option value="dark">🌑 Dark</option>
|
|
<option value="light">🌕 Light</option>
|
|
</select>
|
|
</div>
|
|
<div id="global-links">
|
|
<ul class="simple-boot">
|
|
<li><a href="manual.html">Manual</a></li>
|
|
<li><a href="lib.html">Standard library</a></li>
|
|
<li> <a id="indexLink" href="theindex.html">Index</a></li>
|
|
<li><a href="compiler/theindex.html">Compiler docs</a></li>
|
|
<li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
|
|
<li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="searchInputDiv">
|
|
Search: <input type="search" id="searchInput"
|
|
oninput="search()" />
|
|
</div>
|
|
|
|
<ul class="simple simple-toc" id="toc-list">
|
|
<li><a class="reference" id="basic-usage_toc" href="#basic-usage">Basic usage</a></li>
|
|
<li><a class="reference" id="usage-with-custom-objects_toc" href="#usage-with-custom-objects">Usage with custom objects</a></li>
|
|
<li>
|
|
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
|
|
</li>
|
|
<li>
|
|
<details open>
|
|
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<li><a class="reference" href="#HeapQueue" title="HeapQueue[T] = object">HeapQueue</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%2CHeapQueue%5BT%5D" title="`$`[T](heap: HeapQueue[T]): string">`$`[T](heap: HeapQueue[T]): string</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">[]
|
|
<li><a class="reference" href="#%5B%5D%2CHeapQueue%5BT%5D%2CNatural" title="`[]`[T](heap: HeapQueue[T]; i: Natural): lent T">`[]`[T](heap: HeapQueue[T]; i: Natural): lent T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">clear
|
|
<li><a class="reference" href="#clear%2CHeapQueue%5BT%5D" title="clear[T](heap: var HeapQueue[T])">clear[T](heap: var HeapQueue[T])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">contains
|
|
<li><a class="reference" href="#contains%2CHeapQueue%5BT%5D%2CT" title="contains[T](heap: HeapQueue[T]; x: T): bool">contains[T](heap: HeapQueue[T]; x: T): bool</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">del
|
|
<li><a class="reference" href="#del%2CHeapQueue%5BT%5D%2CNatural" title="del[T](heap: var HeapQueue[T]; index: Natural)">del[T](heap: var HeapQueue[T]; index: Natural)</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">find
|
|
<li><a class="reference" href="#find%2CHeapQueue%5BT%5D%2CT" title="find[T](heap: HeapQueue[T]; x: T): int">find[T](heap: HeapQueue[T]; x: T): int</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">initHeapQueue
|
|
<li><a class="reference" href="#initHeapQueue" title="initHeapQueue[T](): HeapQueue[T]">initHeapQueue[T](): HeapQueue[T]</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">len
|
|
<li><a class="reference" href="#len%2CHeapQueue%5BT%5D" title="len[T](heap: HeapQueue[T]): int">len[T](heap: HeapQueue[T]): int</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">pop
|
|
<li><a class="reference" href="#pop%2CHeapQueue%5BT%5D" title="pop[T](heap: var HeapQueue[T]): T">pop[T](heap: var HeapQueue[T]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">push
|
|
<li><a class="reference" href="#push%2CHeapQueue%5BT%5D%2CsinkT" title="push[T](heap: var HeapQueue[T]; item: sink T)">push[T](heap: var HeapQueue[T]; item: sink T)</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">pushpop
|
|
<li><a class="reference" href="#pushpop%2CHeapQueue%5BT%5D%2CsinkT" title="pushpop[T](heap: var HeapQueue[T]; item: sink T): T">pushpop[T](heap: var HeapQueue[T]; item: sink T): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">replace
|
|
<li><a class="reference" href="#replace%2CHeapQueue%5BT%5D%2CsinkT" title="replace[T](heap: var HeapQueue[T]; item: sink T): T">replace[T](heap: var HeapQueue[T]; item: sink T): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">toHeapQueue
|
|
<li><a class="reference" href="#toHeapQueue%2CopenArray%5BT%5D" title="toHeapQueue[T](x: openArray[T]): HeapQueue[T]">toHeapQueue[T](x: openArray[T]): HeapQueue[T]</a></li>
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
<li>
|
|
<details open>
|
|
<summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<ul class="simple nested-toc-section">items
|
|
<li><a class="reference" href="#items.i%2CHeapQueue%5BT%5D" title="items[T](heap: HeapQueue[T]): lent T">items[T](heap: HeapQueue[T]): lent T</a></li>
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
<div class="nine columns" id="content">
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L1" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
<div id="tocRoot"></div>
|
|
|
|
<p class="module-desc">The <tt class="docutils literal"><span class="pre"><span class="Identifier">heapqueue</span></span></tt> module implements a <a class="reference external" href="https://en.wikipedia.org/wiki/Binary_heap">binary heap data structure</a> that can be used as a <a class="reference external" href="https://en.wikipedia.org/wiki/Priority_queue">priority queue</a>. They are represented as arrays for which <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Punctuation">[</span><span class="Identifier">k</span><span class="Punctuation">]</span> <span class="Operator"><=</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Operator">*</span><span class="Identifier">k</span><span class="Operator">+</span><span class="DecNumber">1</span><span class="Punctuation">]</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Punctuation">[</span><span class="Identifier">k</span><span class="Punctuation">]</span> <span class="Operator"><=</span> <span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">2</span><span class="Operator">*</span><span class="Identifier">k</span><span class="Operator">+</span><span class="DecNumber">2</span><span class="Punctuation">]</span></span></tt> for all indices <tt class="docutils literal"><span class="pre"><span class="Identifier">k</span></span></tt> (counting elements from 0). The interesting property of a heap is that <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span></span></tt> is always its smallest element.
|
|
<h1><a class="toc-backref" id="basic-usage" href="#basic-usage">Basic usage</a></h1>
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">heapqueue</span>
|
|
<span class="Keyword">var</span> <span class="Identifier">heap</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">8</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">push</span><span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">)</span>
|
|
<span class="Comment"># the first element is the lowest element</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
|
|
<span class="Comment"># remove and return the lowest element</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">pop</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
|
|
<span class="Comment"># the lowest element remaining is 5</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">5</span></pre>
|
|
<h1><a class="toc-backref" id="usage-with-custom-objects" href="#usage-with-custom-objects">Usage with custom objects</a></h1><p>To use a <tt class="docutils literal"><span class="pre"><span class="Identifier">HeapQueue</span></span></tt> with a custom object, the <tt class="docutils literal"><span class="pre"><span class="Operator"><</span></span></tt> operator must be implemented.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">heapqueue</span>
|
|
<span class="Keyword">type</span> <span class="Identifier">Job</span> <span class="Operator">=</span> <span class="Keyword">object</span>
|
|
<span class="Identifier">priority</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
|
|
|
|
<span class="Keyword">proc</span> <span class="Punctuation">`</span><span class="Operator"><</span><span class="Punctuation">`</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">Job</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">bool</span> <span class="Operator">=</span> <span class="Identifier">a</span><span class="Operator">.</span><span class="Identifier">priority</span> <span class="Operator"><</span> <span class="Identifier">b</span><span class="Operator">.</span><span class="Identifier">priority</span>
|
|
|
|
<span class="Keyword">var</span> <span class="Identifier">jobs</span> <span class="Operator">=</span> <span class="Identifier">initHeapQueue</span><span class="Punctuation">[</span><span class="Identifier">Job</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">jobs</span><span class="Operator">.</span><span class="Identifier">push</span><span class="Punctuation">(</span><span class="Identifier">Job</span><span class="Punctuation">(</span><span class="Identifier">priority</span><span class="Punctuation">:</span> <span class="DecNumber">1</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">jobs</span><span class="Operator">.</span><span class="Identifier">push</span><span class="Punctuation">(</span><span class="Identifier">Job</span><span class="Punctuation">(</span><span class="Identifier">priority</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="Identifier">jobs</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">priority</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre></p>
|
|
<div class="section" id="6">
|
|
<h1><a class="toc-backref" href="#6">Imports</a></h1>
|
|
<dl class="item">
|
|
<a class="reference external" href="since.html">since</a>, <a class="reference external" href="assertions.html">assertions</a>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="7">
|
|
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
|
<dl class="item">
|
|
<div id="HeapQueue">
|
|
<dt><pre><a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
|
|
<dd>
|
|
|
|
A heap queue, commonly known as a priority queue.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L53" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L53" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="12">
|
|
<h1><a class="toc-backref" href="#12">Procs</a></h1>
|
|
<dl class="item">
|
|
<div id="$-procs-all">
|
|
<div id="$,HeapQueue[T]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#%24%2CHeapQueue%5BT%5D"><span class="Identifier">`$`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
|
|
<dd>
|
|
|
|
Turns a heap into its string representation.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">heap</span> <span class="Operator">=</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="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">heap</span> <span class="Operator">==</span> <span class="StringLit">"[1, 2]"</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L256" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L256" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="[]-procs-all">
|
|
<div id="[],HeapQueue[T],Natural">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CHeapQueue%5BT%5D%2CNatural"><span class="Identifier">`[]`</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Accesses the i-th element of <tt class="docutils literal"><span class="pre"><span class="Identifier">heap</span></span></tt>.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L75" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L75" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="clear-procs-all">
|
|
<div id="clear,HeapQueue[T]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#clear%2CHeapQueue%5BT%5D"><span class="Identifier">clear</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span></pre></dt>
|
|
<dd>
|
|
|
|
Removes all elements from <tt class="docutils literal"><span class="pre"><span class="Identifier">heap</span></span></tt>, making it empty.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">heap</span> <span class="Operator">=</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">8</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">clear</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">0</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L247" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L247" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="contains-procs-all">
|
|
<div id="contains,HeapQueue[T],T">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#contains%2CHeapQueue%5BT%5D%2CT"><span class="Identifier">contains</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">T</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 <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> is in <tt class="docutils literal"><span class="pre"><span class="Identifier">heap</span></span></tt> or false if not found. This is a shortcut for <tt class="docutils literal"><span class="pre"><span class="Identifier">find</span><span class="Punctuation">(</span><span class="Identifier">heap</span><span class="Punctuation">,</span> <span class="Identifier">x</span><span class="Punctuation">)</span> <span class="Operator">>=</span> <span class="DecNumber">0</span></span></tt>.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L191" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L191" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="del-procs-all">
|
|
<div id="del,HeapQueue[T],Natural">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#del%2CHeapQueue%5BT%5D%2CNatural"><span class="Identifier">del</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">index</span><span class="Other">:</span> <a href="system.html#Natural"><span class="Identifier">Natural</span></a><span class="Other">)</span></pre></dt>
|
|
<dd>
|
|
|
|
Removes the element at <tt class="docutils literal"><span class="pre"><span class="Identifier">index</span></span></tt> from <tt class="docutils literal"><span class="pre"><span class="Identifier">heap</span></span></tt>, maintaining the heap invariant.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">heap</span> <span class="Operator">=</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">8</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">del</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L196" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L196" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="find-procs-all">
|
|
<div id="find,HeapQueue[T],T">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#find%2CHeapQueue%5BT%5D%2CT"><span class="Identifier">find</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a></pre></dt>
|
|
<dd>
|
|
|
|
Linear scan to find the index of the item <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> or -1 if not found.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">heap</span> <span class="Operator">=</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">8</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">find</span><span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">find</span><span class="Punctuation">(</span><span class="DecNumber">9</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">find</span><span class="Punctuation">(</span><span class="DecNumber">777</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Operator">-</span><span class="DecNumber">1</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L179" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L179" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="initHeapQueue-procs-all">
|
|
<div id="initHeapQueue">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#initHeapQueue"><span class="Identifier">initHeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span></pre></dt>
|
|
<dd>
|
|
|
|
<p>Creates a new empty heap.</p>
|
|
<p>Heaps are initialized by default, so it is not necessary to call this function explicitly.</p>
|
|
<p><strong>See also:</strong></p>
|
|
<ul class="simple"><li><a class="reference external" href="#toHeapQueue,openArray[T]">toHeapQueue proc</a></li>
|
|
</ul>
|
|
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L57" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L57" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="len-procs-all">
|
|
<div id="len,HeapQueue[T]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#len%2CHeapQueue%5BT%5D"><span class="Identifier">len</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Returns the number of elements of <tt class="docutils literal"><span class="pre"><span class="Identifier">heap</span></span></tt>.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">heap</span> <span class="Operator">=</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">8</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</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/heapqueue.nim#L67" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L67" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="pop-procs-all">
|
|
<div id="pop,HeapQueue[T]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#pop%2CHeapQueue%5BT%5D"><span class="Identifier">pop</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span></pre></dt>
|
|
<dd>
|
|
|
|
Pops and returns the smallest item from <tt class="docutils literal"><span class="pre"><span class="Identifier">heap</span></span></tt>, maintaining the heap invariant.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">heap</span> <span class="Operator">=</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">8</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">pop</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L164" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L164" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="push-procs-all">
|
|
<div id="push,HeapQueue[T],sinkT">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#push%2CHeapQueue%5BT%5D%2CsinkT"><span class="Identifier">push</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">item</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <span class="Identifier">T</span><span class="Other">)</span></pre></dt>
|
|
<dd>
|
|
|
|
Pushes <tt class="docutils literal"><span class="pre"><span class="Identifier">item</span></span></tt> onto <tt class="docutils literal"><span class="pre"><span class="Identifier">heap</span></span></tt>, maintaining the heap invariant.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L144" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L144" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="pushpop-procs-all">
|
|
<div id="pushpop,HeapQueue[T],sinkT">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#pushpop%2CHeapQueue%5BT%5D%2CsinkT"><span class="Identifier">pushpop</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">item</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span></pre></dt>
|
|
<dd>
|
|
|
|
<p>Fast version of a <tt class="docutils literal"><span class="pre"><span class="Identifier">push</span><span class="Punctuation">(</span><span class="Punctuation">)</span></span></tt> followed by a <tt class="docutils literal"><span class="pre"><span class="Identifier">pop</span><span class="Punctuation">(</span><span class="Punctuation">)</span></span></tt>.</p>
|
|
<p><strong>See also:</strong></p>
|
|
<ul class="simple"><li><a class="reference external" href="#replace,HeapQueue[T],sinkT">replace proc</a></li>
|
|
</ul>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">heap</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">12</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">pushpop</span><span class="Punctuation">(</span><span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">pushpop</span><span class="Punctuation">(</span><span class="DecNumber">4</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L230" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L230" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="replace-procs-all">
|
|
<div id="replace,HeapQueue[T],sinkT">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#replace%2CHeapQueue%5BT%5D%2CsinkT"><span class="Identifier">replace</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">item</span><span class="Other">:</span> <a href="system.html#sink"><span class="Identifier">sink</span></a> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span></pre></dt>
|
|
<dd>
|
|
|
|
<p>Pops and returns the current smallest value, and add the new item. This is more efficient than <tt class="docutils literal"><span class="pre"><span class="Identifier">pop</span><span class="Punctuation">(</span><span class="Punctuation">)</span></span></tt> followed by <tt class="docutils literal"><span class="pre"><span class="Identifier">push</span><span class="Punctuation">(</span><span class="Punctuation">)</span></span></tt>, and can be more appropriate when using a fixed-size heap. Note that the value returned may be larger than <tt class="docutils literal"><span class="pre"><span class="Identifier">item</span></span></tt>! That constrains reasonable uses of this routine unless written as part of a conditional replacement.</p>
|
|
<p><strong>See also:</strong></p>
|
|
<ul class="simple"><li><a class="reference external" href="#pushpop,HeapQueue[T],sinkT">pushpop proc</a></li>
|
|
</ul>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">heap</span> <span class="Operator">=</span> <span class="Punctuation">[</span><span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">12</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">replace</span><span class="Punctuation">(</span><span class="DecNumber">6</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">replace</span><span class="Punctuation">(</span><span class="DecNumber">4</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">6</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L210" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L210" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="toHeapQueue-procs-all">
|
|
<div id="toHeapQueue,openArray[T]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#toHeapQueue%2CopenArray%5BT%5D"><span class="Identifier">toHeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span></pre></dt>
|
|
<dd>
|
|
|
|
<p>Creates a new HeapQueue that contains the elements of <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt>.</p>
|
|
<p><strong>See also:</strong></p>
|
|
<ul class="simple"><li><a class="reference external" href="#initHeapQueue">initHeapQueue proc</a></li>
|
|
</ul>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">heap</span> <span class="Operator">=</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">8</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toHeapQueue</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Operator">.</span><span class="Identifier">pop</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
|
|
<span class="Identifier">assert</span> <span class="Identifier">heap</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span> <span class="Operator">==</span> <span class="DecNumber">8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L149" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L149" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="15">
|
|
<h1><a class="toc-backref" href="#15">Iterators</a></h1>
|
|
<dl class="item">
|
|
<div id="items-iterators-all">
|
|
<div id="items.i,HeapQueue[T]">
|
|
<dt><pre><span class="Keyword">iterator</span> <a href="#items.i%2CHeapQueue%5BT%5D"><span class="Identifier">items</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">heap</span><span class="Other">:</span> <a href="heapqueue.html#HeapQueue"><span class="Identifier">HeapQueue</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Iterates over each item of <tt class="docutils literal"><span class="pre"><span class="Identifier">heap</span></span></tt>.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/collections/heapqueue.nim#L79" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/collections/heapqueue.nim#L79" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="twelve-columns footer">
|
|
<span class="nim-sprite"></span>
|
|
<br>
|
|
<small style="color: var(--hint);">Made with Nim. Generated: 2025-12-25 20:13:44 UTC</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
|
|
|
|
</body>
|
|
</html>
|