pypdevsbbl.extra.heap.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <title>pypdevsbbl.extra.heap module &#8212; Python(P)DEVS-BBL documentation</title>
  8. <link rel="stylesheet" href="_static/nature.css" type="text/css" />
  9. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  10. <link rel="stylesheet" type="text/css" href="_static/custom.css" />
  11. <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
  12. <script type="text/javascript" src="_static/jquery.js"></script>
  13. <script type="text/javascript" src="_static/underscore.js"></script>
  14. <script type="text/javascript" src="_static/doctools.js"></script>
  15. <script type="text/javascript" src="_static/language_data.js"></script>
  16. <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>
  17. <link rel="index" title="Index" href="genindex.html" />
  18. <link rel="search" title="Search" href="search.html" />
  19. <link rel="next" title="pypdevsbbl.extra.mathutils module" href="pypdevsbbl.extra.mathutils.html" />
  20. <link rel="prev" title="pypdevsbbl.extra.fileutils module" href="pypdevsbbl.extra.fileutils.html" />
  21. </head><body>
  22. <div class="related" role="navigation" aria-label="related navigation">
  23. <h3>Navigation</h3>
  24. <ul>
  25. <li class="right" style="margin-right: 10px">
  26. <a href="genindex.html" title="General Index"
  27. accesskey="I">index</a></li>
  28. <li class="right" >
  29. <a href="py-modindex.html" title="Python Module Index"
  30. >modules</a> |</li>
  31. <li class="right" >
  32. <a href="pypdevsbbl.extra.mathutils.html" title="pypdevsbbl.extra.mathutils module"
  33. accesskey="N">next</a> |</li>
  34. <li class="right" >
  35. <a href="pypdevsbbl.extra.fileutils.html" title="pypdevsbbl.extra.fileutils module"
  36. accesskey="P">previous</a> |</li>
  37. <li class="nav-item nav-item-0"><a href="index.html">Python(P)DEVS-BBL documentation</a> &#187;</li>
  38. <li class="nav-item nav-item-1"><a href="pypdevsbbl.html" >pypdevsbbl package</a> &#187;</li>
  39. <li class="nav-item nav-item-2"><a href="pypdevsbbl.extra.html" accesskey="U">pypdevsbbl.extra package</a> &#187;</li>
  40. </ul>
  41. </div>
  42. <div class="document">
  43. <div class="documentwrapper">
  44. <div class="bodywrapper">
  45. <div class="body" role="main">
  46. <div class="section" id="module-pypdevsbbl.extra.heap">
  47. <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>
  48. <p>This file is a python-implementation for a heap.</p>
  49. <p>This file allows for both a min-heap and a max-heap by making
  50. 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
  51. functions listed below.</p>
  52. <dl class="function">
  53. <dt id="pypdevsbbl.extra.heap.MIN_HEAP">
  54. <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>
  55. <dd><p>Comparator function, indicating to use a min-heap as the heap.</p>
  56. <div class="admonition seealso">
  57. <p class="first admonition-title">See also</p>
  58. <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>
  59. </div>
  60. </dd></dl>
  61. <dl class="function">
  62. <dt id="pypdevsbbl.extra.heap.MAX_HEAP">
  63. <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>
  64. <dd><p>Comparator function, indicating to use a max-heap as the heap.</p>
  65. <div class="admonition seealso">
  66. <p class="first admonition-title">See also</p>
  67. <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>
  68. </div>
  69. </dd></dl>
  70. <dl class="class">
  71. <dt id="pypdevsbbl.extra.heap.heap">
  72. <em class="property">class </em><code class="descclassname">pypdevsbbl.extra.heap.</code><code class="descname">heap</code><span class="sig-paren">(</span><em>comparator=&lt;function &lt;lambda&gt;&gt;</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>
  73. <dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
  74. <p>The heap class is a simple heap implementation.</p>
  75. <div class="admonition note">
  76. <p class="first admonition-title">Note</p>
  77. <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
  78. 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
  79. swapped with <code class="docutils literal notranslate"><span class="pre">l</span></code>.</p>
  80. <ul class="last simple">
  81. <li><code class="docutils literal notranslate"><span class="pre">x</span></code>: The value of a node in the heap.</li>
  82. <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>
  83. </ul>
  84. </div>
  85. <div class="admonition warning">
  86. <p class="first admonition-title">Warning</p>
  87. <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>
  88. for the comparison function. If you do, you’re probably doing strange
  89. things and you should consider using another datastructure.</p>
  90. </div>
  91. <table class="docutils field-list" frame="void" rules="none">
  92. <col class="field-name" />
  93. <col class="field-body" />
  94. <tbody valign="top">
  95. <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>
  96. </tr>
  97. </tbody>
  98. </table>
  99. <dl class="method">
  100. <dt id="pypdevsbbl.extra.heap.heap.items">
  101. <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>
  102. <dd><p>Get a copy of the contents of the heap as a list.</p>
  103. </dd></dl>
  104. <dl class="method">
  105. <dt id="pypdevsbbl.extra.heap.heap.empty">
  106. <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>
  107. <dd><p>Check if the heap is empty.</p>
  108. <table class="docutils field-list" frame="void" rules="none">
  109. <col class="field-name" />
  110. <col class="field-body" />
  111. <tbody valign="top">
  112. <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>
  113. </tr>
  114. </tbody>
  115. </table>
  116. </dd></dl>
  117. <dl class="method">
  118. <dt id="pypdevsbbl.extra.heap.heap._heapify">
  119. <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>
  120. <dd><p>Fix the heap, making sure the heap condition remains satisfied.</p>
  121. <div class="admonition warning">
  122. <p class="first admonition-title">Warning</p>
  123. <p class="last">This function should not be called from an external source.</p>
  124. </div>
  125. <table class="docutils field-list" frame="void" rules="none">
  126. <col class="field-name" />
  127. <col class="field-body" />
  128. <tbody valign="top">
  129. <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>
  130. </tr>
  131. </tbody>
  132. </table>
  133. </dd></dl>
  134. <dl class="method">
  135. <dt id="pypdevsbbl.extra.heap.heap.insert">
  136. <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>
  137. <dd><p>Insert a new node into the heap.</p>
  138. <table class="docutils field-list" frame="void" rules="none">
  139. <col class="field-name" />
  140. <col class="field-body" />
  141. <tbody valign="top">
  142. <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>
  143. </tr>
  144. </tbody>
  145. </table>
  146. </dd></dl>
  147. <dl class="method">
  148. <dt id="pypdevsbbl.extra.heap.heap.pop">
  149. <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>
  150. <dd><p>Remove the ith item of the heap.</p>
  151. <table class="docutils field-list" frame="void" rules="none">
  152. <col class="field-name" />
  153. <col class="field-body" />
  154. <tbody valign="top">
  155. <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.
  156. Defaults to 0 (the top).</td>
  157. </tr>
  158. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The item that was removed.</td>
  159. </tr>
  160. </tbody>
  161. </table>
  162. </dd></dl>
  163. <dl class="method">
  164. <dt id="pypdevsbbl.extra.heap.heap.indexOf">
  165. <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>
  166. <dd><p>Gets the index of a node.</p>
  167. <table class="docutils field-list" frame="void" rules="none">
  168. <col class="field-name" />
  169. <col class="field-body" />
  170. <tbody valign="top">
  171. <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>
  172. </tr>
  173. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The index of that node.</td>
  174. </tr>
  175. </tbody>
  176. </table>
  177. </dd></dl>
  178. <dl class="method">
  179. <dt id="pypdevsbbl.extra.heap.heap.peek">
  180. <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>
  181. <dd><p>Look at the item at location i in the heap.</p>
  182. <table class="docutils field-list" frame="void" rules="none">
  183. <col class="field-name" />
  184. <col class="field-body" />
  185. <tbody valign="top">
  186. <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.
  187. Defaults to 0 (the top).</td>
  188. </tr>
  189. <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>
  190. </tr>
  191. <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>
  192. </tr>
  193. </tbody>
  194. </table>
  195. </dd></dl>
  196. </dd></dl>
  197. </div>
  198. </div>
  199. </div>
  200. </div>
  201. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  202. <div class="sphinxsidebarwrapper">
  203. <h4>Previous topic</h4>
  204. <p class="topless"><a href="pypdevsbbl.extra.fileutils.html"
  205. title="previous chapter">pypdevsbbl.extra.fileutils module</a></p>
  206. <h4>Next topic</h4>
  207. <p class="topless"><a href="pypdevsbbl.extra.mathutils.html"
  208. title="next chapter">pypdevsbbl.extra.mathutils module</a></p>
  209. <div id="searchbox" style="display: none" role="search">
  210. <h3>Quick search</h3>
  211. <div class="searchformwrapper">
  212. <form class="search" action="search.html" method="get">
  213. <input type="text" name="q" />
  214. <input type="submit" value="Go" />
  215. <input type="hidden" name="check_keywords" value="yes" />
  216. <input type="hidden" name="area" value="default" />
  217. </form>
  218. </div>
  219. </div>
  220. <script type="text/javascript">$('#searchbox').show(0);</script>
  221. </div>
  222. </div>
  223. <div class="clearer"></div>
  224. </div>
  225. <div class="related" role="navigation" aria-label="related navigation">
  226. <h3>Navigation</h3>
  227. <ul>
  228. <li class="right" style="margin-right: 10px">
  229. <a href="genindex.html" title="General Index"
  230. >index</a></li>
  231. <li class="right" >
  232. <a href="py-modindex.html" title="Python Module Index"
  233. >modules</a> |</li>
  234. <li class="right" >
  235. <a href="pypdevsbbl.extra.mathutils.html" title="pypdevsbbl.extra.mathutils module"
  236. >next</a> |</li>
  237. <li class="right" >
  238. <a href="pypdevsbbl.extra.fileutils.html" title="pypdevsbbl.extra.fileutils module"
  239. >previous</a> |</li>
  240. <li class="nav-item nav-item-0"><a href="index.html">Python(P)DEVS-BBL documentation</a> &#187;</li>
  241. <li class="nav-item nav-item-1"><a href="pypdevsbbl.html" >pypdevsbbl package</a> &#187;</li>
  242. <li class="nav-item nav-item-2"><a href="pypdevsbbl.extra.html" >pypdevsbbl.extra package</a> &#187;</li>
  243. </ul>
  244. </div>
  245. <div class="footer" role="contentinfo">
  246. &#169; Copyright 2020, Randy Paredis.
  247. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
  248. </div>
  249. </body>
  250. </html>