ds 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +13 -0
- data/doc/Array.html +264 -0
- data/doc/DS.html +292 -0
- data/doc/DS/Array2D.html +345 -0
- data/doc/DS/BinaryHeap.html +493 -0
- data/doc/DS/BinarySearchTree.html +313 -0
- data/doc/DS/BinaryTree.html +433 -0
- data/doc/DS/CompleteBinaryTree.html +550 -0
- data/doc/DS/CyclicList.html +234 -0
- data/doc/DS/Digraph.html +299 -0
- data/doc/DS/Edge.html +283 -0
- data/doc/DS/ExpandableArray.html +316 -0
- data/doc/DS/Graph.html +739 -0
- data/doc/DS/GraphAsList.html +361 -0
- data/doc/DS/GraphAsMatrix.html +633 -0
- data/doc/DS/GraphAsTriMatrix.html +274 -0
- data/doc/DS/List.html +1263 -0
- data/doc/DS/ListElement.html +344 -0
- data/doc/DS/Queue.html +517 -0
- data/doc/DS/Ring.html +323 -0
- data/doc/DS/Stack.html +407 -0
- data/doc/DS/Tree.html +770 -0
- data/doc/DS/TreeWalker.html +561 -0
- data/doc/DS/TriMatrix.html +338 -0
- data/doc/created.rid +25 -0
- data/doc/ds/graphs/digraph_rb.html +52 -0
- data/doc/ds/graphs/edge_rb.html +52 -0
- data/doc/ds/graphs/graph_as_list_rb.html +52 -0
- data/doc/ds/graphs/graph_as_matrix_rb.html +52 -0
- data/doc/ds/graphs/graph_as_tri_matrix_rb.html +52 -0
- data/doc/ds/graphs/graph_rb.html +52 -0
- data/doc/ds/lists/cyclic_list_rb.html +52 -0
- data/doc/ds/lists/list_element_rb.html +52 -0
- data/doc/ds/lists/list_rb.html +52 -0
- data/doc/ds/lists/ring_rb.html +52 -0
- data/doc/ds/matrixes/array_2d_rb.html +52 -0
- data/doc/ds/matrixes/expandable_array_rb.html +52 -0
- data/doc/ds/matrixes/tri_matrix_rb.html +52 -0
- data/doc/ds/queues/queue_rb.html +52 -0
- data/doc/ds/stacks/stack_rb.html +52 -0
- data/doc/ds/trees/binary_heap_rb.html +52 -0
- data/doc/ds/trees/binary_search_tree_rb.html +52 -0
- data/doc/ds/trees/binary_tree_rb.html +52 -0
- data/doc/ds/trees/complete_binary_tree_rb.html +52 -0
- data/doc/ds/trees/tree_rb.html +52 -0
- data/doc/ds/trees/tree_walker_rb.html +52 -0
- data/doc/ds/version_rb.html +52 -0
- data/doc/ds_rb.html +98 -0
- data/doc/ext/ext_rb.html +52 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +375 -0
- data/doc/js/darkfish.js +116 -0
- data/doc/js/jquery.js +32 -0
- data/doc/js/quicksearch.js +114 -0
- data/doc/js/thickbox-compressed.js +10 -0
- data/doc/rdoc.css +763 -0
- data/ds.gemspec +20 -0
- data/lib/ds.rb +38 -0
- data/lib/ds/graphs/digraph.rb +20 -0
- data/lib/ds/graphs/edge.rb +15 -0
- data/lib/ds/graphs/graph.rb +107 -0
- data/lib/ds/graphs/graph_as_list.rb +48 -0
- data/lib/ds/graphs/graph_as_matrix.rb +114 -0
- data/lib/ds/graphs/graph_as_tri_matrix.rb +25 -0
- data/lib/ds/lists/cyclic_list.rb +21 -0
- data/lib/ds/lists/list.rb +303 -0
- data/lib/ds/lists/list_element.rb +26 -0
- data/lib/ds/lists/ring.rb +42 -0
- data/lib/ds/matrixes/array_2d.rb +35 -0
- data/lib/ds/matrixes/expandable_array.rb +37 -0
- data/lib/ds/matrixes/tri_matrix.rb +30 -0
- data/lib/ds/queues/queue.rb +53 -0
- data/lib/ds/stacks/stack.rb +39 -0
- data/lib/ds/trees/binary_heap.rb +71 -0
- data/lib/ds/trees/binary_search_tree.rb +32 -0
- data/lib/ds/trees/binary_tree.rb +65 -0
- data/lib/ds/trees/complete_binary_tree.rb +52 -0
- data/lib/ds/trees/tree.rb +117 -0
- data/lib/ds/trees/tree_walker.rb +179 -0
- data/lib/ds/version.rb +3 -0
- data/lib/ext/ext.rb +15 -0
- data/test/help.rb +8 -0
- data/test/test_array2d.rb +51 -0
- data/test/test_binary_heap.rb +35 -0
- data/test/test_binary_search_tree.rb +32 -0
- data/test/test_binary_tree.rb +51 -0
- data/test/test_complete_binary_tree.rb +30 -0
- data/test/test_digraph.rb +134 -0
- data/test/test_expandable_array.rb +26 -0
- data/test/test_graph.rb +71 -0
- data/test/test_list.rb +138 -0
- data/test/test_list_element.rb +56 -0
- data/test/test_queue.rb +110 -0
- data/test/test_ring.rb +28 -0
- data/test/test_stack.rb +87 -0
- data/test/test_tree.rb +48 -0
- data/test/test_tree_walker.rb +69 -0
- data/test/test_tri_matrix.rb +22 -0
- metadata +184 -0
data/doc/DS/Tree.html
ADDED
@@ -0,0 +1,770 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
7
|
+
|
8
|
+
<title>Class: DS::Tree</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
|
11
|
+
|
12
|
+
<script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
<script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script>
|
16
|
+
|
17
|
+
</head>
|
18
|
+
<body id="top" class="class">
|
19
|
+
|
20
|
+
<div id="metadata">
|
21
|
+
<div id="home-metadata">
|
22
|
+
<div id="home-section" class="section">
|
23
|
+
<h3 class="section-header">
|
24
|
+
<a href="../index.html">Home</a>
|
25
|
+
<a href="../index.html#classes">Classes</a>
|
26
|
+
<a href="../index.html#methods">Methods</a>
|
27
|
+
</h3>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<div id="file-metadata">
|
32
|
+
<div id="file-list-section" class="section">
|
33
|
+
<h3 class="section-header">In Files</h3>
|
34
|
+
<div class="section-body">
|
35
|
+
<ul>
|
36
|
+
|
37
|
+
<li><a href="../ds/trees/tree_rb.html?TB_iframe=true&height=550&width=785"
|
38
|
+
class="thickbox" title="ds/trees/tree.rb">ds/trees/tree.rb</a></li>
|
39
|
+
|
40
|
+
</ul>
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<div id="class-metadata">
|
48
|
+
|
49
|
+
<!-- Parent Class -->
|
50
|
+
<div id="parent-class-section" class="section">
|
51
|
+
<h3 class="section-header">Parent</h3>
|
52
|
+
|
53
|
+
<p class="link">Object</p>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
<!-- Method Quickref -->
|
64
|
+
<div id="method-list-section" class="section">
|
65
|
+
<h3 class="section-header">Methods</h3>
|
66
|
+
<ul class="link-list">
|
67
|
+
|
68
|
+
<li><a href="#method-c-new">::new</a></li>
|
69
|
+
|
70
|
+
<li><a href="#method-i-3C-3C">#<<</a></li>
|
71
|
+
|
72
|
+
<li><a href="#method-i-each">#each</a></li>
|
73
|
+
|
74
|
+
<li><a href="#method-i-get_leaves">#get_leaves</a></li>
|
75
|
+
|
76
|
+
<li><a href="#method-i-h">#h</a></li>
|
77
|
+
|
78
|
+
<li><a href="#method-i-height">#height</a></li>
|
79
|
+
|
80
|
+
<li><a href="#method-i-izometric-3F">#izometric?</a></li>
|
81
|
+
|
82
|
+
<li><a href="#method-i-leaf-3F">#leaf?</a></li>
|
83
|
+
|
84
|
+
<li><a href="#method-i-leaf_count">#leaf_count</a></li>
|
85
|
+
|
86
|
+
<li><a href="#method-i-levels">#levels</a></li>
|
87
|
+
|
88
|
+
<li><a href="#method-i-lowest_height">#lowest_height</a></li>
|
89
|
+
|
90
|
+
<li><a href="#method-i-mirror-21">#mirror!</a></li>
|
91
|
+
|
92
|
+
<li><a href="#method-i-to_a">#to_a</a></li>
|
93
|
+
|
94
|
+
<li><a href="#method-i-width">#width</a></li>
|
95
|
+
|
96
|
+
</ul>
|
97
|
+
</div>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
<!-- Included Modules -->
|
102
|
+
<div id="includes-section" class="section">
|
103
|
+
<h3 class="section-header">Included Modules</h3>
|
104
|
+
<ul class="link-list">
|
105
|
+
|
106
|
+
|
107
|
+
<li><span class="include">Enumerable</span></li>
|
108
|
+
|
109
|
+
|
110
|
+
</ul>
|
111
|
+
</div>
|
112
|
+
|
113
|
+
</div>
|
114
|
+
|
115
|
+
<div id="project-metadata">
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
<div id="classindex-section" class="section project-section">
|
120
|
+
<h3 class="section-header">Class/Module Index
|
121
|
+
<span class="search-toggle"><img src="../images/find.png"
|
122
|
+
height="16" width="16" alt="[+]"
|
123
|
+
title="show/hide quicksearch" /></span></h3>
|
124
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
125
|
+
<fieldset>
|
126
|
+
<legend>Quicksearch</legend>
|
127
|
+
<input type="text" name="quicksearch" value=""
|
128
|
+
class="quicksearch-field" />
|
129
|
+
</fieldset>
|
130
|
+
</form>
|
131
|
+
|
132
|
+
<ul class="link-list">
|
133
|
+
|
134
|
+
<li><a href="../DS.html">DS</a></li>
|
135
|
+
|
136
|
+
<li><a href="../DS/Array2D.html">DS::Array2D</a></li>
|
137
|
+
|
138
|
+
<li><a href="../DS/BinaryHeap.html">DS::BinaryHeap</a></li>
|
139
|
+
|
140
|
+
<li><a href="../DS/BinarySearchTree.html">DS::BinarySearchTree</a></li>
|
141
|
+
|
142
|
+
<li><a href="../DS/BinaryTree.html">DS::BinaryTree</a></li>
|
143
|
+
|
144
|
+
<li><a href="../DS/CompleteBinaryTree.html">DS::CompleteBinaryTree</a></li>
|
145
|
+
|
146
|
+
<li><a href="../DS/CyclicList.html">DS::CyclicList</a></li>
|
147
|
+
|
148
|
+
<li><a href="../DS/Digraph.html">DS::Digraph</a></li>
|
149
|
+
|
150
|
+
<li><a href="../DS/Edge.html">DS::Edge</a></li>
|
151
|
+
|
152
|
+
<li><a href="../DS/ExpandableArray.html">DS::ExpandableArray</a></li>
|
153
|
+
|
154
|
+
<li><a href="../DS/Graph.html">DS::Graph</a></li>
|
155
|
+
|
156
|
+
<li><a href="../DS/GraphAsList.html">DS::GraphAsList</a></li>
|
157
|
+
|
158
|
+
<li><a href="../DS/GraphAsMatrix.html">DS::GraphAsMatrix</a></li>
|
159
|
+
|
160
|
+
<li><a href="../DS/GraphAsTriMatrix.html">DS::GraphAsTriMatrix</a></li>
|
161
|
+
|
162
|
+
<li><a href="../DS/List.html">DS::List</a></li>
|
163
|
+
|
164
|
+
<li><a href="../DS/ListElement.html">DS::ListElement</a></li>
|
165
|
+
|
166
|
+
<li><a href="../DS/Queue.html">DS::Queue</a></li>
|
167
|
+
|
168
|
+
<li><a href="../DS/Ring.html">DS::Ring</a></li>
|
169
|
+
|
170
|
+
<li><a href="../DS/Stack.html">DS::Stack</a></li>
|
171
|
+
|
172
|
+
<li><a href="../DS/Tree.html">DS::Tree</a></li>
|
173
|
+
|
174
|
+
<li><a href="../DS/TreeWalker.html">DS::TreeWalker</a></li>
|
175
|
+
|
176
|
+
<li><a href="../DS/TriMatrix.html">DS::TriMatrix</a></li>
|
177
|
+
|
178
|
+
<li><a href="../Array.html">Array</a></li>
|
179
|
+
|
180
|
+
</ul>
|
181
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
182
|
+
</div>
|
183
|
+
|
184
|
+
|
185
|
+
</div>
|
186
|
+
</div>
|
187
|
+
|
188
|
+
<div id="documentation">
|
189
|
+
<h1 class="class">DS::Tree</h1>
|
190
|
+
|
191
|
+
<div id="description" class="description">
|
192
|
+
|
193
|
+
</div><!-- description -->
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
<div id="5Buntitled-5D" class="documentation-section">
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
<!-- Attributes -->
|
207
|
+
<div id="attribute-method-details" class="method-section section">
|
208
|
+
<h3 class="section-header">Attributes</h3>
|
209
|
+
|
210
|
+
|
211
|
+
<div id="children-attribute-method" class="method-detail">
|
212
|
+
<a name="children"></a>
|
213
|
+
|
214
|
+
<div class="method-heading attribute-method-heading">
|
215
|
+
<span class="method-name">children</span><span
|
216
|
+
class="attribute-access-type">[R]</span>
|
217
|
+
</div>
|
218
|
+
|
219
|
+
<div class="method-description">
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
</div>
|
224
|
+
</div>
|
225
|
+
|
226
|
+
<div id="data-attribute-method" class="method-detail">
|
227
|
+
<a name="data"></a>
|
228
|
+
|
229
|
+
<a name="data="></a>
|
230
|
+
|
231
|
+
<div class="method-heading attribute-method-heading">
|
232
|
+
<span class="method-name">data</span><span
|
233
|
+
class="attribute-access-type">[RW]</span>
|
234
|
+
</div>
|
235
|
+
|
236
|
+
<div class="method-description">
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
</div>
|
241
|
+
</div>
|
242
|
+
|
243
|
+
</div><!-- attribute-method-details -->
|
244
|
+
|
245
|
+
|
246
|
+
<!-- Methods -->
|
247
|
+
|
248
|
+
<div id="public-class-method-details" class="method-section section">
|
249
|
+
<h3 class="section-header">Public Class Methods</h3>
|
250
|
+
|
251
|
+
|
252
|
+
<div id="new-method" class="method-detail ">
|
253
|
+
<a name="method-c-new"></a>
|
254
|
+
|
255
|
+
|
256
|
+
<div class="method-heading">
|
257
|
+
<span class="method-name">new</span><span
|
258
|
+
class="method-args">(value=nil)</span>
|
259
|
+
<span class="method-click-advice">click to toggle source</span>
|
260
|
+
</div>
|
261
|
+
|
262
|
+
|
263
|
+
<div class="method-description">
|
264
|
+
|
265
|
+
<p>Returns a new tree.</p>
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
<div class="method-source-code" id="new-source">
|
270
|
+
<pre>
|
271
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 10</span>
|
272
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">value</span>=<span class="ruby-keyword">nil</span>)
|
273
|
+
<span class="ruby-ivar">@data</span> = <span class="ruby-identifier">value</span>
|
274
|
+
<span class="ruby-ivar">@children</span> = []
|
275
|
+
<span class="ruby-keyword">end</span></pre>
|
276
|
+
</div><!-- new-source -->
|
277
|
+
|
278
|
+
</div>
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
</div><!-- new-method -->
|
284
|
+
|
285
|
+
|
286
|
+
</div><!-- public-class-method-details -->
|
287
|
+
|
288
|
+
<div id="public-instance-method-details" class="method-section section">
|
289
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
290
|
+
|
291
|
+
|
292
|
+
<div id="3C-3C-method" class="method-detail ">
|
293
|
+
<a name="method-i-3C-3C"></a>
|
294
|
+
|
295
|
+
|
296
|
+
<div class="method-heading">
|
297
|
+
<span class="method-name"><<</span><span
|
298
|
+
class="method-args">(value)</span>
|
299
|
+
<span class="method-click-advice">click to toggle source</span>
|
300
|
+
</div>
|
301
|
+
|
302
|
+
|
303
|
+
<div class="method-description">
|
304
|
+
|
305
|
+
<p>Inserts a new subtree.</p>
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
<div class="method-source-code" id="3C-3C-source">
|
310
|
+
<pre>
|
311
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 16</span>
|
312
|
+
<span class="ruby-keyword">def</span> <span class="ruby-operator"><<</span> (<span class="ruby-identifier">value</span>)
|
313
|
+
<span class="ruby-identifier">subtree</span> = <span class="ruby-constant">Tree</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span>)
|
314
|
+
<span class="ruby-ivar">@children</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">subtree</span>
|
315
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">subtree</span>
|
316
|
+
<span class="ruby-keyword">end</span></pre>
|
317
|
+
</div><!-- 3C-3C-source -->
|
318
|
+
|
319
|
+
</div>
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
</div><!-- 3C-3C-method -->
|
325
|
+
|
326
|
+
|
327
|
+
<div id="each-method" class="method-detail ">
|
328
|
+
<a name="method-i-each"></a>
|
329
|
+
|
330
|
+
|
331
|
+
<div class="method-heading">
|
332
|
+
<span class="method-name">each</span><span
|
333
|
+
class="method-args">()</span>
|
334
|
+
<span class="method-click-advice">click to toggle source</span>
|
335
|
+
</div>
|
336
|
+
|
337
|
+
|
338
|
+
<div class="method-description">
|
339
|
+
|
340
|
+
<p>Iterates tree in BFS order.</p>
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
<div class="method-source-code" id="each-source">
|
345
|
+
<pre>
|
346
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 108</span>
|
347
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">each</span>
|
348
|
+
<span class="ruby-constant">TreeWalker</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>).<span class="ruby-identifier">traverse</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-identifier">t</span> }
|
349
|
+
<span class="ruby-keyword">end</span></pre>
|
350
|
+
</div><!-- each-source -->
|
351
|
+
|
352
|
+
</div>
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
</div><!-- each-method -->
|
358
|
+
|
359
|
+
|
360
|
+
<div id="get_leaves-method" class="method-detail ">
|
361
|
+
<a name="method-i-get_leaves"></a>
|
362
|
+
|
363
|
+
|
364
|
+
<div class="method-heading">
|
365
|
+
<span class="method-name">get_leaves</span><span
|
366
|
+
class="method-args">(tree=self)</span>
|
367
|
+
<span class="method-click-advice">click to toggle source</span>
|
368
|
+
</div>
|
369
|
+
|
370
|
+
|
371
|
+
<div class="method-description">
|
372
|
+
|
373
|
+
<p>Returns leaf list.</p>
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
<div class="method-source-code" id="get_leaves-source">
|
378
|
+
<pre>
|
379
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 28</span>
|
380
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_leaves</span>(<span class="ruby-identifier">tree</span>=<span class="ruby-keyword">self</span>)
|
381
|
+
<span class="ruby-identifier">list</span> = <span class="ruby-constant">List</span>.<span class="ruby-identifier">new</span>
|
382
|
+
<span class="ruby-identifier">walker</span> = <span class="ruby-constant">TreeWalker</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>)
|
383
|
+
<span class="ruby-identifier">walker</span>.<span class="ruby-identifier">traverse</span>(<span class="ruby-value">:postorder</span>){<span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">list</span>.<span class="ruby-identifier">append</span>(<span class="ruby-identifier">t</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">leaf?</span> }
|
384
|
+
<span class="ruby-identifier">list</span>
|
385
|
+
<span class="ruby-keyword">end</span></pre>
|
386
|
+
</div><!-- get_leaves-source -->
|
387
|
+
|
388
|
+
</div>
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
</div><!-- get_leaves-method -->
|
394
|
+
|
395
|
+
|
396
|
+
<div id="h-method" class="method-detail ">
|
397
|
+
<a name="method-i-h"></a>
|
398
|
+
|
399
|
+
|
400
|
+
<div class="method-heading">
|
401
|
+
<span class="method-name">h</span><span
|
402
|
+
class="method-args">(tree)</span>
|
403
|
+
<span class="method-click-advice">click to toggle source</span>
|
404
|
+
</div>
|
405
|
+
|
406
|
+
|
407
|
+
<div class="method-description">
|
408
|
+
|
409
|
+
<p>Returns subtree height.</p>
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
<div class="method-source-code" id="h-source">
|
414
|
+
<pre>
|
415
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 67</span>
|
416
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">h</span>(<span class="ruby-identifier">tree</span>)
|
417
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">tree</span>.<span class="ruby-identifier">leaf?</span>
|
418
|
+
<span class="ruby-identifier">tree</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>(<span class="ruby-identifier">t</span>) }.<span class="ruby-identifier">max</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
|
419
|
+
<span class="ruby-keyword">else</span>
|
420
|
+
<span class="ruby-value">1</span>
|
421
|
+
<span class="ruby-keyword">end</span>
|
422
|
+
<span class="ruby-keyword">end</span></pre>
|
423
|
+
</div><!-- h-source -->
|
424
|
+
|
425
|
+
</div>
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
</div><!-- h-method -->
|
431
|
+
|
432
|
+
|
433
|
+
<div id="height-method" class="method-detail ">
|
434
|
+
<a name="method-i-height"></a>
|
435
|
+
|
436
|
+
|
437
|
+
<div class="method-heading">
|
438
|
+
<span class="method-name">height</span><span
|
439
|
+
class="method-args">()</span>
|
440
|
+
<span class="method-click-advice">click to toggle source</span>
|
441
|
+
</div>
|
442
|
+
|
443
|
+
|
444
|
+
<div class="method-description">
|
445
|
+
|
446
|
+
<p>Returns tree height.</p>
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
<div class="method-source-code" id="height-source">
|
451
|
+
<pre>
|
452
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 76</span>
|
453
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">height</span>
|
454
|
+
<span class="ruby-identifier">h</span>(<span class="ruby-keyword">self</span>)
|
455
|
+
<span class="ruby-keyword">end</span></pre>
|
456
|
+
</div><!-- height-source -->
|
457
|
+
|
458
|
+
</div>
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
</div><!-- height-method -->
|
464
|
+
|
465
|
+
|
466
|
+
<div id="izometric-3F-method" class="method-detail ">
|
467
|
+
<a name="method-i-izometric-3F"></a>
|
468
|
+
|
469
|
+
|
470
|
+
<div class="method-heading">
|
471
|
+
<span class="method-name">izometric?</span><span
|
472
|
+
class="method-args">(other)</span>
|
473
|
+
<span class="method-click-advice">click to toggle source</span>
|
474
|
+
</div>
|
475
|
+
|
476
|
+
|
477
|
+
<div class="method-description">
|
478
|
+
|
479
|
+
<p>Checks if tree is isometric to another tree.</p>
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
<div class="method-source-code" id="izometric-3F-source">
|
484
|
+
<pre>
|
485
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 94</span>
|
486
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">izometric?</span>(<span class="ruby-identifier">other</span>)
|
487
|
+
<span class="ruby-identifier">tree</span> = <span class="ruby-keyword">self</span>
|
488
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">tree</span>.<span class="ruby-identifier">leaf?</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">leaf?</span>
|
489
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">tree</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">size</span>
|
490
|
+
<span class="ruby-identifier">tree</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">each_with_index</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">t</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">izometric?</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">children</span>[<span class="ruby-identifier">i</span>])}
|
491
|
+
<span class="ruby-keyword">else</span>
|
492
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
|
493
|
+
<span class="ruby-keyword">end</span>
|
494
|
+
<span class="ruby-keyword">end</span>
|
495
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">true</span>
|
496
|
+
<span class="ruby-keyword">end</span></pre>
|
497
|
+
</div><!-- izometric-3F-source -->
|
498
|
+
|
499
|
+
</div>
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
|
504
|
+
</div><!-- izometric-3F-method -->
|
505
|
+
|
506
|
+
|
507
|
+
<div id="leaf-3F-method" class="method-detail ">
|
508
|
+
<a name="method-i-leaf-3F"></a>
|
509
|
+
|
510
|
+
|
511
|
+
<div class="method-heading">
|
512
|
+
<span class="method-name">leaf?</span><span
|
513
|
+
class="method-args">()</span>
|
514
|
+
<span class="method-click-advice">click to toggle source</span>
|
515
|
+
</div>
|
516
|
+
|
517
|
+
|
518
|
+
<div class="method-description">
|
519
|
+
|
520
|
+
<p>Checks if node is leaf.</p>
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
<div class="method-source-code" id="leaf-3F-source">
|
525
|
+
<pre>
|
526
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 23</span>
|
527
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">leaf?</span>
|
528
|
+
<span class="ruby-keyword">self</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">empty?</span>
|
529
|
+
<span class="ruby-keyword">end</span></pre>
|
530
|
+
</div><!-- leaf-3F-source -->
|
531
|
+
|
532
|
+
</div>
|
533
|
+
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
</div><!-- leaf-3F-method -->
|
538
|
+
|
539
|
+
|
540
|
+
<div id="leaf_count-method" class="method-detail ">
|
541
|
+
<a name="method-i-leaf_count"></a>
|
542
|
+
|
543
|
+
|
544
|
+
<div class="method-heading">
|
545
|
+
<span class="method-name">leaf_count</span><span
|
546
|
+
class="method-args">(tree=self)</span>
|
547
|
+
<span class="method-click-advice">click to toggle source</span>
|
548
|
+
</div>
|
549
|
+
|
550
|
+
|
551
|
+
<div class="method-description">
|
552
|
+
|
553
|
+
<p>Returns the number of leaves for given subtree.</p>
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
<div class="method-source-code" id="leaf_count-source">
|
558
|
+
<pre>
|
559
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 36</span>
|
560
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">leaf_count</span>(<span class="ruby-identifier">tree</span>=<span class="ruby-keyword">self</span>)
|
561
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">tree</span>.<span class="ruby-identifier">leaf?</span>
|
562
|
+
<span class="ruby-value">1</span>
|
563
|
+
<span class="ruby-keyword">else</span>
|
564
|
+
<span class="ruby-identifier">tree</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value">0</span>){<span class="ruby-operator">|</span><span class="ruby-identifier">m</span>,<span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">leaf_count</span>(<span class="ruby-identifier">t</span>)}
|
565
|
+
<span class="ruby-keyword">end</span>
|
566
|
+
<span class="ruby-keyword">end</span></pre>
|
567
|
+
</div><!-- leaf_count-source -->
|
568
|
+
|
569
|
+
</div>
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
</div><!-- leaf_count-method -->
|
575
|
+
|
576
|
+
|
577
|
+
<div id="levels-method" class="method-detail ">
|
578
|
+
<a name="method-i-levels"></a>
|
579
|
+
|
580
|
+
|
581
|
+
<div class="method-heading">
|
582
|
+
<span class="method-name">levels</span><span
|
583
|
+
class="method-args">()</span>
|
584
|
+
<span class="method-click-advice">click to toggle source</span>
|
585
|
+
</div>
|
586
|
+
|
587
|
+
|
588
|
+
<div class="method-description">
|
589
|
+
|
590
|
+
<p>Returns number of nodes for each tree level. {1=>1, 2=>4, 3=>5}</p>
|
591
|
+
|
592
|
+
|
593
|
+
|
594
|
+
<div class="method-source-code" id="levels-source">
|
595
|
+
<pre>
|
596
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 47</span>
|
597
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">levels</span>
|
598
|
+
<span class="ruby-identifier">walker</span> = <span class="ruby-constant">TreeWalker</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>)
|
599
|
+
<span class="ruby-identifier">nodes</span>={}
|
600
|
+
|
601
|
+
<span class="ruby-identifier">walker</span>.<span class="ruby-identifier">traverse_with_h</span>(<span class="ruby-keyword">self</span>,<span class="ruby-value">1</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span>,<span class="ruby-identifier">level</span><span class="ruby-operator">|</span>
|
602
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">nodes</span>[<span class="ruby-identifier">level</span>]
|
603
|
+
<span class="ruby-identifier">nodes</span>[<span class="ruby-identifier">level</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
604
|
+
<span class="ruby-keyword">else</span>
|
605
|
+
<span class="ruby-identifier">nodes</span>[<span class="ruby-identifier">level</span>] = <span class="ruby-value">1</span>
|
606
|
+
<span class="ruby-keyword">end</span>
|
607
|
+
<span class="ruby-keyword">end</span>
|
608
|
+
<span class="ruby-identifier">nodes</span>
|
609
|
+
<span class="ruby-keyword">end</span></pre>
|
610
|
+
</div><!-- levels-source -->
|
611
|
+
|
612
|
+
</div>
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
</div><!-- levels-method -->
|
618
|
+
|
619
|
+
|
620
|
+
<div id="lowest_height-method" class="method-detail ">
|
621
|
+
<a name="method-i-lowest_height"></a>
|
622
|
+
|
623
|
+
|
624
|
+
<div class="method-heading">
|
625
|
+
<span class="method-name">lowest_height</span><span
|
626
|
+
class="method-args">()</span>
|
627
|
+
<span class="method-click-advice">click to toggle source</span>
|
628
|
+
</div>
|
629
|
+
|
630
|
+
|
631
|
+
<div class="method-description">
|
632
|
+
|
633
|
+
<p>Returns node which lies closest to the root.</p>
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
<div class="method-source-code" id="lowest_height-source">
|
638
|
+
<pre>
|
639
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 81</span>
|
640
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">lowest_height</span>
|
641
|
+
<span class="ruby-identifier">find</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">leaf?</span> }.<span class="ruby-identifier">data</span>
|
642
|
+
<span class="ruby-keyword">end</span></pre>
|
643
|
+
</div><!-- lowest_height-source -->
|
644
|
+
|
645
|
+
</div>
|
646
|
+
|
647
|
+
|
648
|
+
|
649
|
+
|
650
|
+
</div><!-- lowest_height-method -->
|
651
|
+
|
652
|
+
|
653
|
+
<div id="mirror-21-method" class="method-detail ">
|
654
|
+
<a name="method-i-mirror-21"></a>
|
655
|
+
|
656
|
+
|
657
|
+
<div class="method-heading">
|
658
|
+
<span class="method-name">mirror!</span><span
|
659
|
+
class="method-args">(tree=self)</span>
|
660
|
+
<span class="method-click-advice">click to toggle source</span>
|
661
|
+
</div>
|
662
|
+
|
663
|
+
|
664
|
+
<div class="method-description">
|
665
|
+
|
666
|
+
<p>Mirrors tree.</p>
|
667
|
+
|
668
|
+
|
669
|
+
|
670
|
+
<div class="method-source-code" id="mirror-21-source">
|
671
|
+
<pre>
|
672
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 86</span>
|
673
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mirror!</span>(<span class="ruby-identifier">tree</span>=<span class="ruby-keyword">self</span>)
|
674
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">tree</span>.<span class="ruby-identifier">leaf?</span>
|
675
|
+
<span class="ruby-identifier">tree</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">reverse!</span>
|
676
|
+
<span class="ruby-identifier">tree</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">mirror!</span>(<span class="ruby-identifier">t</span>)}
|
677
|
+
<span class="ruby-keyword">end</span>
|
678
|
+
<span class="ruby-keyword">end</span></pre>
|
679
|
+
</div><!-- mirror-21-source -->
|
680
|
+
|
681
|
+
</div>
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
|
686
|
+
</div><!-- mirror-21-method -->
|
687
|
+
|
688
|
+
|
689
|
+
<div id="to_a-method" class="method-detail ">
|
690
|
+
<a name="method-i-to_a"></a>
|
691
|
+
|
692
|
+
|
693
|
+
<div class="method-heading">
|
694
|
+
<span class="method-name">to_a</span><span
|
695
|
+
class="method-args">()</span>
|
696
|
+
<span class="method-click-advice">click to toggle source</span>
|
697
|
+
</div>
|
698
|
+
|
699
|
+
|
700
|
+
<div class="method-description">
|
701
|
+
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
|
706
|
+
<div class="method-source-code" id="to_a-source">
|
707
|
+
<pre>
|
708
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 112</span>
|
709
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">to_a</span>
|
710
|
+
<span class="ruby-identifier">map</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">data</span> }
|
711
|
+
<span class="ruby-keyword">end</span></pre>
|
712
|
+
</div><!-- to_a-source -->
|
713
|
+
|
714
|
+
</div>
|
715
|
+
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
</div><!-- to_a-method -->
|
720
|
+
|
721
|
+
|
722
|
+
<div id="width-method" class="method-detail ">
|
723
|
+
<a name="method-i-width"></a>
|
724
|
+
|
725
|
+
|
726
|
+
<div class="method-heading">
|
727
|
+
<span class="method-name">width</span><span
|
728
|
+
class="method-args">()</span>
|
729
|
+
<span class="method-click-advice">click to toggle source</span>
|
730
|
+
</div>
|
731
|
+
|
732
|
+
|
733
|
+
<div class="method-description">
|
734
|
+
|
735
|
+
<p>Returns tree width.</p>
|
736
|
+
|
737
|
+
|
738
|
+
|
739
|
+
<div class="method-source-code" id="width-source">
|
740
|
+
<pre>
|
741
|
+
<span class="ruby-comment"># File ds/trees/tree.rb, line 62</span>
|
742
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">width</span>
|
743
|
+
<span class="ruby-identifier">levels</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">max</span>
|
744
|
+
<span class="ruby-keyword">end</span></pre>
|
745
|
+
</div><!-- width-source -->
|
746
|
+
|
747
|
+
</div>
|
748
|
+
|
749
|
+
|
750
|
+
|
751
|
+
|
752
|
+
</div><!-- width-method -->
|
753
|
+
|
754
|
+
|
755
|
+
</div><!-- public-instance-method-details -->
|
756
|
+
|
757
|
+
</div><!-- 5Buntitled-5D -->
|
758
|
+
|
759
|
+
|
760
|
+
</div><!-- documentation -->
|
761
|
+
|
762
|
+
<div id="validator-badges">
|
763
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
764
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
765
|
+
Rdoc Generator</a> 2</small>.</p>
|
766
|
+
</div>
|
767
|
+
|
768
|
+
</body>
|
769
|
+
</html>
|
770
|
+
|