| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>pypdevsbbl.extra.heap module — Python(P)DEVS-BBL documentation</title>
- <link rel="stylesheet" href="_static/nature.css" type="text/css" />
- <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
- <link rel="stylesheet" type="text/css" href="_static/custom.css" />
- <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
- <script type="text/javascript" src="_static/jquery.js"></script>
- <script type="text/javascript" src="_static/underscore.js"></script>
- <script type="text/javascript" src="_static/doctools.js"></script>
- <script type="text/javascript" src="_static/language_data.js"></script>
- <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
- <link rel="index" title="Index" href="genindex.html" />
- <link rel="search" title="Search" href="search.html" />
- <link rel="next" title="pypdevsbbl.extra.mathutils module" href="pypdevsbbl.extra.mathutils.html" />
- <link rel="prev" title="pypdevsbbl.extra.fileutils module" href="pypdevsbbl.extra.fileutils.html" />
- </head><body>
- <div class="related" role="navigation" aria-label="related navigation">
- <h3>Navigation</h3>
- <ul>
- <li class="right" style="margin-right: 10px">
- <a href="genindex.html" title="General Index"
- accesskey="I">index</a></li>
- <li class="right" >
- <a href="py-modindex.html" title="Python Module Index"
- >modules</a> |</li>
- <li class="right" >
- <a href="pypdevsbbl.extra.mathutils.html" title="pypdevsbbl.extra.mathutils module"
- accesskey="N">next</a> |</li>
- <li class="right" >
- <a href="pypdevsbbl.extra.fileutils.html" title="pypdevsbbl.extra.fileutils module"
- accesskey="P">previous</a> |</li>
- <li class="nav-item nav-item-0"><a href="index.html">Python(P)DEVS-BBL documentation</a> »</li>
- <li class="nav-item nav-item-1"><a href="pypdevsbbl.html" >pypdevsbbl package</a> »</li>
- <li class="nav-item nav-item-2"><a href="pypdevsbbl.extra.html" accesskey="U">pypdevsbbl.extra package</a> »</li>
- </ul>
- </div>
- <div class="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
- <div class="body" role="main">
-
- <div class="section" id="module-pypdevsbbl.extra.heap">
- <span id="pypdevsbbl-extra-heap-module"></span><h1>pypdevsbbl.extra.heap module<a class="headerlink" href="#module-pypdevsbbl.extra.heap" title="Permalink to this headline">¶</a></h1>
- <p>This file is a python-implementation for a heap.</p>
- <p>This file allows for both a min-heap and a max-heap by making
- use of the <a class="reference internal" href="#pypdevsbbl.extra.heap.MIN_HEAP" title="pypdevsbbl.extra.heap.MIN_HEAP"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MIN_HEAP()</span></code></a> and <a class="reference internal" href="#pypdevsbbl.extra.heap.MAX_HEAP" title="pypdevsbbl.extra.heap.MAX_HEAP"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MAX_HEAP()</span></code></a> comparator
- functions listed below.</p>
- <dl class="function">
- <dt id="pypdevsbbl.extra.heap.MIN_HEAP">
- <code class="descclassname">pypdevsbbl.extra.heap.</code><code class="descname">MIN_HEAP</code><span class="sig-paren">(</span><em>x</em>, <em>l</em><span class="sig-paren">)</span><a class="headerlink" href="#pypdevsbbl.extra.heap.MIN_HEAP" title="Permalink to this definition">¶</a></dt>
- <dd><p>Comparator function, indicating to use a min-heap as the heap.</p>
- <div class="admonition seealso">
- <p class="first admonition-title">See also</p>
- <p class="last"><a class="reference internal" href="#pypdevsbbl.extra.heap.heap" title="pypdevsbbl.extra.heap.heap"><code class="xref py py-class docutils literal notranslate"><span class="pre">heap</span></code></a></p>
- </div>
- </dd></dl>
- <dl class="function">
- <dt id="pypdevsbbl.extra.heap.MAX_HEAP">
- <code class="descclassname">pypdevsbbl.extra.heap.</code><code class="descname">MAX_HEAP</code><span class="sig-paren">(</span><em>x</em>, <em>l</em><span class="sig-paren">)</span><a class="headerlink" href="#pypdevsbbl.extra.heap.MAX_HEAP" title="Permalink to this definition">¶</a></dt>
- <dd><p>Comparator function, indicating to use a max-heap as the heap.</p>
- <div class="admonition seealso">
- <p class="first admonition-title">See also</p>
- <p class="last"><a class="reference internal" href="#pypdevsbbl.extra.heap.heap" title="pypdevsbbl.extra.heap.heap"><code class="xref py py-class docutils literal notranslate"><span class="pre">heap</span></code></a></p>
- </div>
- </dd></dl>
- <dl class="class">
- <dt id="pypdevsbbl.extra.heap.heap">
- <em class="property">class </em><code class="descclassname">pypdevsbbl.extra.heap.</code><code class="descname">heap</code><span class="sig-paren">(</span><em>comparator=<function <lambda>></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/heap.html#heap"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.heap.heap" title="Permalink to this definition">¶</a></dt>
- <dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
- <p>The heap class is a simple heap implementation.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p>The comparator function takes two arguments (<code class="docutils literal notranslate"><span class="pre">x</span></code> and <code class="docutils literal notranslate"><span class="pre">l</span></code>, as
- described below) and should return <code class="docutils literal notranslate"><span class="pre">True</span></code> if <code class="docutils literal notranslate"><span class="pre">x</span></code> should be
- swapped with <code class="docutils literal notranslate"><span class="pre">l</span></code>.</p>
- <ul class="last simple">
- <li><code class="docutils literal notranslate"><span class="pre">x</span></code>: The value of a node in the heap.</li>
- <li><code class="docutils literal notranslate"><span class="pre">l</span></code>: The root to compare <code class="docutils literal notranslate"><span class="pre">x</span></code> to.</li>
- </ul>
- </div>
- <div class="admonition warning">
- <p class="first admonition-title">Warning</p>
- <p class="last">You shouldn’t need any other than <a class="reference internal" href="#pypdevsbbl.extra.heap.MIN_HEAP" title="pypdevsbbl.extra.heap.MIN_HEAP"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MIN_HEAP()</span></code></a> or <a class="reference internal" href="#pypdevsbbl.extra.heap.MAX_HEAP" title="pypdevsbbl.extra.heap.MAX_HEAP"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MAX_HEAP()</span></code></a>
- for the comparison function. If you do, you’re probably doing strange
- things and you should consider using another datastructure.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>comparator</strong> (<em>def</em>) – The comparison function. Defaults to <a class="reference internal" href="#pypdevsbbl.extra.heap.MAX_HEAP" title="pypdevsbbl.extra.heap.MAX_HEAP"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MAX_HEAP()</span></code></a>.</td>
- </tr>
- </tbody>
- </table>
- <dl class="method">
- <dt id="pypdevsbbl.extra.heap.heap.items">
- <code class="descname">items</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/heap.html#heap.items"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.heap.heap.items" title="Permalink to this definition">¶</a></dt>
- <dd><p>Get a copy of the contents of the heap as a list.</p>
- </dd></dl>
- <dl class="method">
- <dt id="pypdevsbbl.extra.heap.heap.empty">
- <code class="descname">empty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/heap.html#heap.empty"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.heap.heap.empty" title="Permalink to this definition">¶</a></dt>
- <dd><p>Check if the heap is empty.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><code class="docutils literal notranslate"><span class="pre">True</span></code> if the heap is empty, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="pypdevsbbl.extra.heap.heap._heapify">
- <code class="descname">_heapify</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/heap.html#heap._heapify"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.heap.heap._heapify" title="Permalink to this definition">¶</a></dt>
- <dd><p>Fix the heap, making sure the heap condition remains satisfied.</p>
- <div class="admonition warning">
- <p class="first admonition-title">Warning</p>
- <p class="last">This function should not be called from an external source.</p>
- </div>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>i</strong> (<em>int</em>) – Index of the root node to heapify.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="pypdevsbbl.extra.heap.heap.insert">
- <code class="descname">insert</code><span class="sig-paren">(</span><em>node</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/heap.html#heap.insert"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.heap.heap.insert" title="Permalink to this definition">¶</a></dt>
- <dd><p>Insert a new node into the heap.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>node</strong> (<em>object</em>) – A comparable object to insert.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="pypdevsbbl.extra.heap.heap.pop">
- <code class="descname">pop</code><span class="sig-paren">(</span><em>i=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/heap.html#heap.pop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.heap.heap.pop" title="Permalink to this definition">¶</a></dt>
- <dd><p>Remove the ith item of the heap.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>i</strong> (<em>int</em>) – The index of the node to pop.
- Defaults to 0 (the top).</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The item that was removed.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="pypdevsbbl.extra.heap.heap.indexOf">
- <code class="descname">indexOf</code><span class="sig-paren">(</span><em>node</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/heap.html#heap.indexOf"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.heap.heap.indexOf" title="Permalink to this definition">¶</a></dt>
- <dd><p>Gets the index of a node.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>node</strong> (<em>object</em>) – The node to get the index for.</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The index of that node.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- <dl class="method">
- <dt id="pypdevsbbl.extra.heap.heap.peek">
- <code class="descname">peek</code><span class="sig-paren">(</span><em>i=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pypdevsbbl/extra/heap.html#heap.peek"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pypdevsbbl.extra.heap.heap.peek" title="Permalink to this definition">¶</a></dt>
- <dd><p>Look at the item at location i in the heap.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>i</strong> (<em>int</em>) – The index of the node to peek.
- Defaults to 0 (the top).</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><code class="docutils literal notranslate"><span class="pre">None</span></code> if the heap is empty, otherwise the item at index <code class="docutils literal notranslate"><span class="pre">i</span></code>.</td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><strong>IndexError</strong> – When the index is not found.</td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
- </dd></dl>
- </div>
- </div>
- </div>
- </div>
- <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
- <div class="sphinxsidebarwrapper">
- <h4>Previous topic</h4>
- <p class="topless"><a href="pypdevsbbl.extra.fileutils.html"
- title="previous chapter">pypdevsbbl.extra.fileutils module</a></p>
- <h4>Next topic</h4>
- <p class="topless"><a href="pypdevsbbl.extra.mathutils.html"
- title="next chapter">pypdevsbbl.extra.mathutils module</a></p>
- <div id="searchbox" style="display: none" role="search">
- <h3>Quick search</h3>
- <div class="searchformwrapper">
- <form class="search" action="search.html" method="get">
- <input type="text" name="q" />
- <input type="submit" value="Go" />
- <input type="hidden" name="check_keywords" value="yes" />
- <input type="hidden" name="area" value="default" />
- </form>
- </div>
- </div>
- <script type="text/javascript">$('#searchbox').show(0);</script>
- </div>
- </div>
- <div class="clearer"></div>
- </div>
- <div class="related" role="navigation" aria-label="related navigation">
- <h3>Navigation</h3>
- <ul>
- <li class="right" style="margin-right: 10px">
- <a href="genindex.html" title="General Index"
- >index</a></li>
- <li class="right" >
- <a href="py-modindex.html" title="Python Module Index"
- >modules</a> |</li>
- <li class="right" >
- <a href="pypdevsbbl.extra.mathutils.html" title="pypdevsbbl.extra.mathutils module"
- >next</a> |</li>
- <li class="right" >
- <a href="pypdevsbbl.extra.fileutils.html" title="pypdevsbbl.extra.fileutils module"
- >previous</a> |</li>
- <li class="nav-item nav-item-0"><a href="index.html">Python(P)DEVS-BBL documentation</a> »</li>
- <li class="nav-item nav-item-1"><a href="pypdevsbbl.html" >pypdevsbbl package</a> »</li>
- <li class="nav-item nav-item-2"><a href="pypdevsbbl.extra.html" >pypdevsbbl.extra package</a> »</li>
- </ul>
- </div>
- <div class="footer" role="contentinfo">
- © Copyright 2020, Randy Paredis.
- Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
- </div>
- </body>
- </html>
|