grosser-algorithms 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/Manifest +45 -0
  2. data/VERSION +1 -0
  3. data/ext/containers/bst/bst.c +249 -0
  4. data/ext/containers/bst/extconf.rb +4 -0
  5. data/grosser-algorithms.gemspec +4 -4
  6. data/rdoc/classes/Algorithms.html +221 -0
  7. data/rdoc/classes/Algorithms/Algorithms.html +115 -0
  8. data/rdoc/classes/Algorithms/Algorithms/Sort.html +569 -0
  9. data/rdoc/classes/Algorithms/Containers.html +162 -0
  10. data/rdoc/classes/Algorithms/Containers/Heap.html +690 -0
  11. data/rdoc/classes/Algorithms/Containers/KDTree.html +195 -0
  12. data/rdoc/classes/Algorithms/Containers/MaxHeap.html +238 -0
  13. data/rdoc/classes/Algorithms/Containers/MinHeap.html +238 -0
  14. data/rdoc/classes/Algorithms/Containers/PriorityQueue.html +456 -0
  15. data/rdoc/classes/Algorithms/Containers/Queue.html +363 -0
  16. data/rdoc/classes/Algorithms/Containers/RubyDeque.html +617 -0
  17. data/rdoc/classes/Algorithms/Containers/RubyRBTreeMap.html +662 -0
  18. data/rdoc/classes/Algorithms/Containers/RubySplayTreeMap.html +623 -0
  19. data/rdoc/classes/Algorithms/Containers/Stack.html +363 -0
  20. data/rdoc/classes/Algorithms/Containers/SuffixArray.html +246 -0
  21. data/rdoc/classes/Algorithms/Containers/Trie.html +555 -0
  22. data/rdoc/classes/Algorithms/Search.html +273 -0
  23. data/rdoc/created.rid +1 -0
  24. data/rdoc/files/History_txt.html +281 -0
  25. data/rdoc/files/README_markdown.html +248 -0
  26. data/rdoc/files/lib/algorithms/search_rb.html +108 -0
  27. data/rdoc/files/lib/algorithms/sort_rb.html +108 -0
  28. data/rdoc/files/lib/algorithms/string_rb.html +115 -0
  29. data/rdoc/files/lib/algorithms_rb.html +252 -0
  30. data/rdoc/files/lib/containers/deque_rb.html +119 -0
  31. data/rdoc/files/lib/containers/heap_rb.html +124 -0
  32. data/rdoc/files/lib/containers/kd_tree_rb.html +135 -0
  33. data/rdoc/files/lib/containers/priority_queue_rb.html +108 -0
  34. data/rdoc/files/lib/containers/queue_rb.html +108 -0
  35. data/rdoc/files/lib/containers/rb_tree_map_rb.html +109 -0
  36. data/rdoc/files/lib/containers/splay_tree_map_rb.html +109 -0
  37. data/rdoc/files/lib/containers/stack_rb.html +108 -0
  38. data/rdoc/files/lib/containers/suffix_array_rb.html +113 -0
  39. data/rdoc/files/lib/containers/trie_rb.html +117 -0
  40. data/rdoc/fr_class_index.html +43 -0
  41. data/rdoc/fr_file_index.html +42 -0
  42. data/rdoc/fr_method_index.html +147 -0
  43. data/rdoc/index.html +24 -0
  44. data/rdoc/rdoc-style.css +208 -0
  45. data/spec/bst_gc_mark_spec.rb +25 -0
  46. data/spec/bst_spec.rb +25 -0
  47. metadata +50 -3
@@ -0,0 +1,195 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Algorithms::Containers::KDTree</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Algorithms::Containers::KDTree</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../../files/lib/containers/kd_tree_rb.html">
59
+ lib/containers/kd_tree.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+
82
+
83
+ </div>
84
+
85
+ <div id="method-list">
86
+ <h3 class="section-bar">Methods</h3>
87
+
88
+ <div class="name-list">
89
+ <a href="#M000026">find_nearest</a>&nbsp;&nbsp;
90
+ <a href="#M000025">new</a>&nbsp;&nbsp;
91
+ </div>
92
+ </div>
93
+
94
+ </div>
95
+
96
+
97
+ <!-- if includes -->
98
+
99
+ <div id="section">
100
+
101
+
102
+ <div id="constants-list">
103
+ <h3 class="section-bar">Constants</h3>
104
+
105
+ <div class="name-list">
106
+ <table summary="Constants">
107
+ <tr class="top-aligned-row context-row">
108
+ <td class="context-item-name">Node</td>
109
+ <td>=</td>
110
+ <td class="context-item-value">Struct.new(:id, :coords, :left, :right)</td>
111
+ </tr>
112
+ </table>
113
+ </div>
114
+ </div>
115
+
116
+
117
+
118
+
119
+
120
+
121
+ <!-- if method_list -->
122
+ <div id="methods">
123
+ <h3 class="section-bar">Public Class methods</h3>
124
+
125
+ <div id="method-M000025" class="method-detail">
126
+ <a name="M000025"></a>
127
+
128
+ <div class="method-heading">
129
+ <a href="#M000025" class="method-signature">
130
+ <span class="method-name">new</span><span class="method-args">(points)</span>
131
+ </a>
132
+ </div>
133
+
134
+ <div class="method-description">
135
+ <p>
136
+ Points is a hash of id =&gt; [coord, coord] pairs.
137
+ </p>
138
+ <p><a class="source-toggle" href="#"
139
+ onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
140
+ <div class="method-source-code" id="M000025-source">
141
+ <pre>
142
+ <span class="ruby-comment cmt"># File lib/containers/kd_tree.rb, line 31</span>
143
+ 31: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">points</span>)
144
+ 32: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;must pass in a hash&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">points</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Hash</span>)
145
+ 33: <span class="ruby-ivar">@dimensions</span> = <span class="ruby-identifier">points</span>[ <span class="ruby-identifier">points</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">first</span> ].<span class="ruby-identifier">size</span>
146
+ 34: <span class="ruby-ivar">@root</span> = <span class="ruby-identifier">build_tree</span>(<span class="ruby-identifier">points</span>.<span class="ruby-identifier">to_a</span>)
147
+ 35: <span class="ruby-ivar">@nearest</span> = []
148
+ 36: <span class="ruby-keyword kw">end</span>
149
+ </pre>
150
+ </div>
151
+ </div>
152
+ </div>
153
+
154
+ <h3 class="section-bar">Public Instance methods</h3>
155
+
156
+ <div id="method-M000026" class="method-detail">
157
+ <a name="M000026"></a>
158
+
159
+ <div class="method-heading">
160
+ <a href="#M000026" class="method-signature">
161
+ <span class="method-name">find_nearest</span><span class="method-args">(target, k_nearest)</span>
162
+ </a>
163
+ </div>
164
+
165
+ <div class="method-description">
166
+ <p>
167
+ Find k closest points to given coordinates
168
+ </p>
169
+ <p><a class="source-toggle" href="#"
170
+ onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
171
+ <div class="method-source-code" id="M000026-source">
172
+ <pre>
173
+ <span class="ruby-comment cmt"># File lib/containers/kd_tree.rb, line 39</span>
174
+ 39: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_nearest</span>(<span class="ruby-identifier">target</span>, <span class="ruby-identifier">k_nearest</span>)
175
+ 40: <span class="ruby-ivar">@nearest</span> = []
176
+ 41: <span class="ruby-identifier">nearest</span>(<span class="ruby-ivar">@root</span>, <span class="ruby-identifier">target</span>, <span class="ruby-identifier">k_nearest</span>, <span class="ruby-value">0</span>)
177
+ 42: <span class="ruby-keyword kw">end</span>
178
+ </pre>
179
+ </div>
180
+ </div>
181
+ </div>
182
+
183
+
184
+ </div>
185
+
186
+
187
+ </div>
188
+
189
+
190
+ <div id="validator-badges">
191
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
192
+ </div>
193
+
194
+ </body>
195
+ </html>
@@ -0,0 +1,238 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Algorithms::Containers::MaxHeap</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Algorithms::Containers::MaxHeap</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../../files/lib/containers/heap_rb.html">
59
+ lib/containers/heap.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ <a href="Heap.html">
69
+ Heap
70
+ </a>
71
+ </td>
72
+ </tr>
73
+ </table>
74
+ </div>
75
+ <!-- banner header -->
76
+
77
+ <div id="bodyContent">
78
+
79
+
80
+
81
+ <div id="contextContent">
82
+
83
+ <div id="description">
84
+ <p>
85
+ A <a href="MaxHeap.html">MaxHeap</a> is a heap where the items are returned
86
+ in descending order of key value.
87
+ </p>
88
+
89
+ </div>
90
+
91
+
92
+ </div>
93
+
94
+ <div id="method-list">
95
+ <h3 class="section-bar">Methods</h3>
96
+
97
+ <div class="name-list">
98
+ <a href="#M000094">max</a>&nbsp;&nbsp;
99
+ <a href="#M000095">max!</a>&nbsp;&nbsp;
100
+ <a href="#M000093">new</a>&nbsp;&nbsp;
101
+ </div>
102
+ </div>
103
+
104
+ </div>
105
+
106
+
107
+ <!-- if includes -->
108
+
109
+ <div id="section">
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ <!-- if method_list -->
119
+ <div id="methods">
120
+ <h3 class="section-bar">Public Class methods</h3>
121
+
122
+ <div id="method-M000093" class="method-detail">
123
+ <a name="M000093"></a>
124
+
125
+ <div class="method-heading">
126
+ <a href="#M000093" class="method-signature">
127
+ <span class="method-name">MaxHeap.new(ary) &rarr; new_heap<br />
128
+ </span>
129
+ </a>
130
+ </div>
131
+
132
+ <div class="method-description">
133
+ <p>
134
+ Creates a <a href="MaxHeap.html#M000093">new</a> <a
135
+ href="MaxHeap.html">MaxHeap</a> with an optional array parameter of items
136
+ to insert into the heap. A <a href="MaxHeap.html">MaxHeap</a> is created by
137
+ calling <a href="Heap.html#M000053">Heap.new</a> { |x, y| (x &lt;=&gt; y)
138
+ == 1 }, so this is a convenience class.
139
+ </p>
140
+ <pre>
141
+ maxheap = MaxHeap.new([1, 2, 3, 4])
142
+ maxheap.pop #=&gt; 4
143
+ maxheap.pop #=&gt; 3
144
+ </pre>
145
+ <p><a class="source-toggle" href="#"
146
+ onclick="toggleCode('M000093-source');return false;">[Source]</a></p>
147
+ <div class="method-source-code" id="M000093-source">
148
+ <pre>
149
+ <span class="ruby-comment cmt"># File lib/containers/heap.rb, line 430</span>
150
+ 430: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">ary</span>=[])
151
+ 431: <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">ary</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">x</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">y</span>) <span class="ruby-operator">==</span> <span class="ruby-value">1</span> }
152
+ 432: <span class="ruby-keyword kw">end</span>
153
+ </pre>
154
+ </div>
155
+ </div>
156
+ </div>
157
+
158
+ <h3 class="section-bar">Public Instance methods</h3>
159
+
160
+ <div id="method-M000094" class="method-detail">
161
+ <a name="M000094"></a>
162
+
163
+ <div class="method-heading">
164
+ <a href="#M000094" class="method-signature">
165
+ <span class="method-name">max &rarr; value<br />
166
+ max &rarr; nil<br />
167
+ </span>
168
+ </a>
169
+ </div>
170
+
171
+ <div class="method-description">
172
+ <p>
173
+ Returns the item with the largest key, but does not remove it from the
174
+ heap.
175
+ </p>
176
+ <pre>
177
+ maxheap = MaxHeap.new([1, 2, 3, 4])
178
+ maxheap.max #=&gt; 4
179
+ </pre>
180
+ <p><a class="source-toggle" href="#"
181
+ onclick="toggleCode('M000094-source');return false;">[Source]</a></p>
182
+ <div class="method-source-code" id="M000094-source">
183
+ <pre>
184
+ <span class="ruby-comment cmt"># File lib/containers/heap.rb, line 443</span>
185
+ 443: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">max</span>
186
+ 444: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">next</span>
187
+ 445: <span class="ruby-keyword kw">end</span>
188
+ </pre>
189
+ </div>
190
+ </div>
191
+ </div>
192
+
193
+ <div id="method-M000095" class="method-detail">
194
+ <a name="M000095"></a>
195
+
196
+ <div class="method-heading">
197
+ <a href="#M000095" class="method-signature">
198
+ <span class="method-name">max! &rarr; value<br />
199
+ max! &rarr; nil<br />
200
+ </span>
201
+ </a>
202
+ </div>
203
+
204
+ <div class="method-description">
205
+ <p>
206
+ Returns the item with the largest key and removes it from the heap.
207
+ </p>
208
+ <pre>
209
+ maxheap = MaxHeap.new([1, 2, 3, 4])
210
+ maxheap.max! #=&gt; 4
211
+ maxheap.size #=&gt; 3
212
+ </pre>
213
+ <p><a class="source-toggle" href="#"
214
+ onclick="toggleCode('M000095-source');return false;">[Source]</a></p>
215
+ <div class="method-source-code" id="M000095-source">
216
+ <pre>
217
+ <span class="ruby-comment cmt"># File lib/containers/heap.rb, line 456</span>
218
+ 456: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">max!</span>
219
+ 457: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pop</span>
220
+ 458: <span class="ruby-keyword kw">end</span>
221
+ </pre>
222
+ </div>
223
+ </div>
224
+ </div>
225
+
226
+
227
+ </div>
228
+
229
+
230
+ </div>
231
+
232
+
233
+ <div id="validator-badges">
234
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
235
+ </div>
236
+
237
+ </body>
238
+ </html>
@@ -0,0 +1,238 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Algorithms::Containers::MinHeap</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Algorithms::Containers::MinHeap</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../../files/lib/containers/heap_rb.html">
59
+ lib/containers/heap.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ <a href="Heap.html">
69
+ Heap
70
+ </a>
71
+ </td>
72
+ </tr>
73
+ </table>
74
+ </div>
75
+ <!-- banner header -->
76
+
77
+ <div id="bodyContent">
78
+
79
+
80
+
81
+ <div id="contextContent">
82
+
83
+ <div id="description">
84
+ <p>
85
+ A <a href="MinHeap.html">MinHeap</a> is a heap where the items are returned
86
+ in ascending order of key value.
87
+ </p>
88
+
89
+ </div>
90
+
91
+
92
+ </div>
93
+
94
+ <div id="method-list">
95
+ <h3 class="section-bar">Methods</h3>
96
+
97
+ <div class="name-list">
98
+ <a href="#M000023">min</a>&nbsp;&nbsp;
99
+ <a href="#M000024">min!</a>&nbsp;&nbsp;
100
+ <a href="#M000022">new</a>&nbsp;&nbsp;
101
+ </div>
102
+ </div>
103
+
104
+ </div>
105
+
106
+
107
+ <!-- if includes -->
108
+
109
+ <div id="section">
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ <!-- if method_list -->
119
+ <div id="methods">
120
+ <h3 class="section-bar">Public Class methods</h3>
121
+
122
+ <div id="method-M000022" class="method-detail">
123
+ <a name="M000022"></a>
124
+
125
+ <div class="method-heading">
126
+ <a href="#M000022" class="method-signature">
127
+ <span class="method-name">MinHeap.new(ary) &rarr; new_heap<br />
128
+ </span>
129
+ </a>
130
+ </div>
131
+
132
+ <div class="method-description">
133
+ <p>
134
+ Creates a <a href="MinHeap.html#M000022">new</a> <a
135
+ href="MinHeap.html">MinHeap</a> with an optional array parameter of items
136
+ to insert into the heap. A <a href="MinHeap.html">MinHeap</a> is created by
137
+ calling <a href="Heap.html#M000053">Heap.new</a> { |x, y| (x &lt;=&gt; y)
138
+ == -1 }, so this is a convenience class.
139
+ </p>
140
+ <pre>
141
+ minheap = MinHeap.new([1, 2, 3, 4])
142
+ minheap.pop #=&gt; 1
143
+ minheap.pop #=&gt; 2
144
+ </pre>
145
+ <p><a class="source-toggle" href="#"
146
+ onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
147
+ <div class="method-source-code" id="M000022-source">
148
+ <pre>
149
+ <span class="ruby-comment cmt"># File lib/containers/heap.rb, line 476</span>
150
+ 476: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">ary</span>=[])
151
+ 477: <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">ary</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">x</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">y</span>) <span class="ruby-operator">==</span> <span class="ruby-value">-1</span> }
152
+ 478: <span class="ruby-keyword kw">end</span>
153
+ </pre>
154
+ </div>
155
+ </div>
156
+ </div>
157
+
158
+ <h3 class="section-bar">Public Instance methods</h3>
159
+
160
+ <div id="method-M000023" class="method-detail">
161
+ <a name="M000023"></a>
162
+
163
+ <div class="method-heading">
164
+ <a href="#M000023" class="method-signature">
165
+ <span class="method-name">min &rarr; value<br />
166
+ min &rarr; nil<br />
167
+ </span>
168
+ </a>
169
+ </div>
170
+
171
+ <div class="method-description">
172
+ <p>
173
+ Returns the item with the smallest key, but does not remove it from the
174
+ heap.
175
+ </p>
176
+ <pre>
177
+ minheap = MinHeap.new([1, 2, 3, 4])
178
+ minheap.min #=&gt; 1
179
+ </pre>
180
+ <p><a class="source-toggle" href="#"
181
+ onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
182
+ <div class="method-source-code" id="M000023-source">
183
+ <pre>
184
+ <span class="ruby-comment cmt"># File lib/containers/heap.rb, line 489</span>
185
+ 489: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">min</span>
186
+ 490: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">next</span>
187
+ 491: <span class="ruby-keyword kw">end</span>
188
+ </pre>
189
+ </div>
190
+ </div>
191
+ </div>
192
+
193
+ <div id="method-M000024" class="method-detail">
194
+ <a name="M000024"></a>
195
+
196
+ <div class="method-heading">
197
+ <a href="#M000024" class="method-signature">
198
+ <span class="method-name">min! &rarr; value<br />
199
+ min! &rarr; nil<br />
200
+ </span>
201
+ </a>
202
+ </div>
203
+
204
+ <div class="method-description">
205
+ <p>
206
+ Returns the item with the smallest key and removes it from the heap.
207
+ </p>
208
+ <pre>
209
+ minheap = MinHeap.new([1, 2, 3, 4])
210
+ minheap.min! #=&gt; 1
211
+ minheap.size #=&gt; 3
212
+ </pre>
213
+ <p><a class="source-toggle" href="#"
214
+ onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
215
+ <div class="method-source-code" id="M000024-source">
216
+ <pre>
217
+ <span class="ruby-comment cmt"># File lib/containers/heap.rb, line 502</span>
218
+ 502: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">min!</span>
219
+ 503: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pop</span>
220
+ 504: <span class="ruby-keyword kw">end</span>
221
+ </pre>
222
+ </div>
223
+ </div>
224
+ </div>
225
+
226
+
227
+ </div>
228
+
229
+
230
+ </div>
231
+
232
+
233
+ <div id="validator-badges">
234
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
235
+ </div>
236
+
237
+ </body>
238
+ </html>