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,456 @@
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::PriorityQueue</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::PriorityQueue</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../../files/lib/containers/priority_queue_rb.html">
59
+ lib/containers/priority_queue.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="#M000044">clear</a>&nbsp;&nbsp;
90
+ <a href="#M000050">delete</a>&nbsp;&nbsp;
91
+ <a href="#M000045">empty?</a>&nbsp;&nbsp;
92
+ <a href="#M000046">has_priority?</a>&nbsp;&nbsp;
93
+ <a href="#M000042">length</a>&nbsp;&nbsp;
94
+ <a href="#M000040">new</a>&nbsp;&nbsp;
95
+ <a href="#M000047">next</a>&nbsp;&nbsp;
96
+ <a href="#M000049">next!</a>&nbsp;&nbsp;
97
+ <a href="#M000048">pop</a>&nbsp;&nbsp;
98
+ <a href="#M000043">push</a>&nbsp;&nbsp;
99
+ <a href="#M000041">size</a>&nbsp;&nbsp;
100
+ </div>
101
+ </div>
102
+
103
+ </div>
104
+
105
+
106
+ <!-- if includes -->
107
+ <div id="includes">
108
+ <h3 class="section-bar">Included Modules</h3>
109
+
110
+ <div id="includes-list">
111
+ <span class="include-name">Enumerable</span>
112
+ </div>
113
+ </div>
114
+
115
+ <div id="section">
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+ <!-- if method_list -->
125
+ <div id="methods">
126
+ <h3 class="section-bar">Public Class methods</h3>
127
+
128
+ <div id="method-M000040" class="method-detail">
129
+ <a name="M000040"></a>
130
+
131
+ <div class="method-heading">
132
+ <a href="#M000040" class="method-signature">
133
+ <span class="method-name">new</span><span class="method-args">(&amp;block)</span>
134
+ </a>
135
+ </div>
136
+
137
+ <div class="method-description">
138
+ <p>
139
+ Create a <a href="PriorityQueue.html#M000040">new</a>, empty <a
140
+ href="PriorityQueue.html">PriorityQueue</a>
141
+ </p>
142
+ <p><a class="source-toggle" href="#"
143
+ onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
144
+ <div class="method-source-code" id="M000040-source">
145
+ <pre>
146
+ <span class="ruby-comment cmt"># File lib/containers/priority_queue.rb, line 18</span>
147
+ 18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
148
+ 19: <span class="ruby-comment cmt"># We default to a priority queue that returns the largest value</span>
149
+ 20: <span class="ruby-identifier">block</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">lambda</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> }
150
+ 21: <span class="ruby-ivar">@heap</span> = <span class="ruby-constant">Heap</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
151
+ 22: <span class="ruby-keyword kw">end</span>
152
+ </pre>
153
+ </div>
154
+ </div>
155
+ </div>
156
+
157
+ <h3 class="section-bar">Public Instance methods</h3>
158
+
159
+ <div id="method-M000044" class="method-detail">
160
+ <a name="M000044"></a>
161
+
162
+ <div class="method-heading">
163
+ <a href="#M000044" class="method-signature">
164
+ <span class="method-name">clear</span><span class="method-args">()</span>
165
+ </a>
166
+ </div>
167
+
168
+ <div class="method-description">
169
+ <p>
170
+ Clears all the items in the queue.
171
+ </p>
172
+ <p><a class="source-toggle" href="#"
173
+ onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
174
+ <div class="method-source-code" id="M000044-source">
175
+ <pre>
176
+ <span class="ruby-comment cmt"># File lib/containers/priority_queue.rb, line 45</span>
177
+ 45: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear</span>
178
+ 46: <span class="ruby-ivar">@heap</span>.<span class="ruby-identifier">clear</span>
179
+ 47: <span class="ruby-keyword kw">end</span>
180
+ </pre>
181
+ </div>
182
+ </div>
183
+ </div>
184
+
185
+ <div id="method-M000050" class="method-detail">
186
+ <a name="M000050"></a>
187
+
188
+ <div class="method-heading">
189
+ <a href="#M000050" class="method-signature">
190
+ <span class="method-name">delete(priority) &rarr; object<br />
191
+ delete(priority) &rarr; nil<br />
192
+ </span>
193
+ </a>
194
+ </div>
195
+
196
+ <div class="method-description">
197
+ <p>
198
+ Delete an object with specified priority from the queue. If there are
199
+ duplicates, an arbitrary object with that priority is deleted and returned.
200
+ Returns nil if there are no objects with the priority.
201
+ </p>
202
+ <pre>
203
+ q = PriorityQueue.new
204
+ q.push(&quot;Alaska&quot;, 50)
205
+ q.push(&quot;Delaware&quot;, 30)
206
+ q.delete(50) #=&gt; &quot;Alaska&quot;
207
+ q.delete(10) #=&gt; nil
208
+ </pre>
209
+ <p><a class="source-toggle" href="#"
210
+ onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
211
+ <div class="method-source-code" id="M000050-source">
212
+ <pre>
213
+ <span class="ruby-comment cmt"># File lib/containers/priority_queue.rb, line 111</span>
214
+ 111: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">priority</span>)
215
+ 112: <span class="ruby-ivar">@heap</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">priority</span>)
216
+ 113: <span class="ruby-keyword kw">end</span>
217
+ </pre>
218
+ </div>
219
+ </div>
220
+ </div>
221
+
222
+ <div id="method-M000045" class="method-detail">
223
+ <a name="M000045"></a>
224
+
225
+ <div class="method-heading">
226
+ <a href="#M000045" class="method-signature">
227
+ <span class="method-name">empty?</span><span class="method-args">()</span>
228
+ </a>
229
+ </div>
230
+
231
+ <div class="method-description">
232
+ <p>
233
+ Returns true if the queue is empty, false otherwise.
234
+ </p>
235
+ <p><a class="source-toggle" href="#"
236
+ onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
237
+ <div class="method-source-code" id="M000045-source">
238
+ <pre>
239
+ <span class="ruby-comment cmt"># File lib/containers/priority_queue.rb, line 50</span>
240
+ 50: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">empty?</span>
241
+ 51: <span class="ruby-ivar">@heap</span>.<span class="ruby-identifier">empty?</span>
242
+ 52: <span class="ruby-keyword kw">end</span>
243
+ </pre>
244
+ </div>
245
+ </div>
246
+ </div>
247
+
248
+ <div id="method-M000046" class="method-detail">
249
+ <a name="M000046"></a>
250
+
251
+ <div class="method-heading">
252
+ <a href="#M000046" class="method-signature">
253
+ <span class="method-name">has_priority? priority &rarr; boolean<br />
254
+ </span>
255
+ </a>
256
+ </div>
257
+
258
+ <div class="method-description">
259
+ <p>
260
+ Return true if the priority is in the queue, false otherwise.
261
+ </p>
262
+ <pre>
263
+ q = PriorityQueue.new
264
+ q.push(&quot;Alaska&quot;, 1)
265
+
266
+ q.has_priority?(1) #=&gt; true
267
+ q.has_priority?(2) #=&gt; false
268
+ </pre>
269
+ <p><a class="source-toggle" href="#"
270
+ onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
271
+ <div class="method-source-code" id="M000046-source">
272
+ <pre>
273
+ <span class="ruby-comment cmt"># File lib/containers/priority_queue.rb, line 64</span>
274
+ 64: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_priority?</span>(<span class="ruby-identifier">priority</span>)
275
+ 65: <span class="ruby-ivar">@heap</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">priority</span>)
276
+ 66: <span class="ruby-keyword kw">end</span>
277
+ </pre>
278
+ </div>
279
+ </div>
280
+ </div>
281
+
282
+ <div id="method-M000042" class="method-detail">
283
+ <a name="M000042"></a>
284
+
285
+ <div class="method-heading">
286
+ <span class="method-name">length</span><span class="method-args">()</span>
287
+ </div>
288
+
289
+ <div class="method-description">
290
+ <p>
291
+ Alias for <a href="PriorityQueue.html#M000041">size</a>
292
+ </p>
293
+ </div>
294
+ </div>
295
+
296
+ <div id="method-M000047" class="method-detail">
297
+ <a name="M000047"></a>
298
+
299
+ <div class="method-heading">
300
+ <a href="#M000047" class="method-signature">
301
+ <span class="method-name">next &rarr; object<br />
302
+ </span>
303
+ </a>
304
+ </div>
305
+
306
+ <div class="method-description">
307
+ <p>
308
+ Return the object with the <a href="PriorityQueue.html#M000047">next</a>
309
+ highest priority, but does not remove it
310
+ </p>
311
+ <pre>
312
+ q = Algorithms::Containers::PriorityQueue.new
313
+ q.push(&quot;Alaska&quot;, 50)
314
+ q.push(&quot;Delaware&quot;, 30)
315
+ q.push(&quot;Georgia&quot;, 35)
316
+ q.next #=&gt; &quot;Alaska&quot;
317
+ </pre>
318
+ <p><a class="source-toggle" href="#"
319
+ onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
320
+ <div class="method-source-code" id="M000047-source">
321
+ <pre>
322
+ <span class="ruby-comment cmt"># File lib/containers/priority_queue.rb, line 78</span>
323
+ 78: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
324
+ 79: <span class="ruby-ivar">@heap</span>.<span class="ruby-identifier">next</span>
325
+ 80: <span class="ruby-keyword kw">end</span>
326
+ </pre>
327
+ </div>
328
+ </div>
329
+ </div>
330
+
331
+ <div id="method-M000049" class="method-detail">
332
+ <a name="M000049"></a>
333
+
334
+ <div class="method-heading">
335
+ <span class="method-name">next!</span><span class="method-args">()</span>
336
+ </div>
337
+
338
+ <div class="method-description">
339
+ <p>
340
+ Alias for <a href="PriorityQueue.html#M000048">pop</a>
341
+ </p>
342
+ </div>
343
+ </div>
344
+
345
+ <div id="method-M000048" class="method-detail">
346
+ <a name="M000048"></a>
347
+
348
+ <div class="method-heading">
349
+ <a href="#M000048" class="method-signature">
350
+ <span class="method-name">pop &rarr; object<br />
351
+ </span>
352
+ </a>
353
+ </div>
354
+
355
+ <div class="method-description">
356
+ <p>
357
+ Return the object with the <a href="PriorityQueue.html#M000047">next</a>
358
+ highest priority and removes it from the queue
359
+ </p>
360
+ <pre>
361
+ q = Algorithms::Containers::PriorityQueue.new
362
+ q.push(&quot;Alaska&quot;, 50)
363
+ q.push(&quot;Delaware&quot;, 30)
364
+ q.push(&quot;Georgia&quot;, 35)
365
+ q.pop #=&gt; &quot;Alaska&quot;
366
+ q.size #=&gt; 2
367
+ </pre>
368
+ <p><a class="source-toggle" href="#"
369
+ onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
370
+ <div class="method-source-code" id="M000048-source">
371
+ <pre>
372
+ <span class="ruby-comment cmt"># File lib/containers/priority_queue.rb, line 93</span>
373
+ 93: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pop</span>
374
+ 94: <span class="ruby-ivar">@heap</span>.<span class="ruby-identifier">pop</span>
375
+ 95: <span class="ruby-keyword kw">end</span>
376
+ </pre>
377
+ </div>
378
+ </div>
379
+ </div>
380
+
381
+ <div id="method-M000043" class="method-detail">
382
+ <a name="M000043"></a>
383
+
384
+ <div class="method-heading">
385
+ <a href="#M000043" class="method-signature">
386
+ <span class="method-name">push</span><span class="method-args">(object, priority)</span>
387
+ </a>
388
+ </div>
389
+
390
+ <div class="method-description">
391
+ <p>
392
+ Add an object to the queue with associated priority.
393
+ </p>
394
+ <pre>
395
+ q = Algorithms::Containers::PriorityQueue.new
396
+ q.push(&quot;Alaska&quot;, 1)
397
+ q.pop #=&gt; &quot;Alaska&quot;
398
+ </pre>
399
+ <p><a class="source-toggle" href="#"
400
+ onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
401
+ <div class="method-source-code" id="M000043-source">
402
+ <pre>
403
+ <span class="ruby-comment cmt"># File lib/containers/priority_queue.rb, line 40</span>
404
+ 40: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">push</span>(<span class="ruby-identifier">object</span>, <span class="ruby-identifier">priority</span>)
405
+ 41: <span class="ruby-ivar">@heap</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">priority</span>, <span class="ruby-identifier">object</span>)
406
+ 42: <span class="ruby-keyword kw">end</span>
407
+ </pre>
408
+ </div>
409
+ </div>
410
+ </div>
411
+
412
+ <div id="method-M000041" class="method-detail">
413
+ <a name="M000041"></a>
414
+
415
+ <div class="method-heading">
416
+ <a href="#M000041" class="method-signature">
417
+ <span class="method-name">size</span><span class="method-args">()</span>
418
+ </a>
419
+ </div>
420
+
421
+ <div class="method-description">
422
+ <p>
423
+ Returns the number of elements in the queue.
424
+ </p>
425
+ <pre>
426
+ q = Algorithms::Containers::PriorityQueue.new
427
+ q.size #=&gt; 0
428
+ q.push(&quot;Alaska&quot;, 1)
429
+ q.size #=&gt; 1
430
+ </pre>
431
+ <p><a class="source-toggle" href="#"
432
+ onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
433
+ <div class="method-source-code" id="M000041-source">
434
+ <pre>
435
+ <span class="ruby-comment cmt"># File lib/containers/priority_queue.rb, line 30</span>
436
+ 30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>
437
+ 31: <span class="ruby-ivar">@heap</span>.<span class="ruby-identifier">size</span>
438
+ 32: <span class="ruby-keyword kw">end</span>
439
+ </pre>
440
+ </div>
441
+ </div>
442
+ </div>
443
+
444
+
445
+ </div>
446
+
447
+
448
+ </div>
449
+
450
+
451
+ <div id="validator-badges">
452
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
453
+ </div>
454
+
455
+ </body>
456
+ </html>