ds 0.0.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.
- 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
|
@@ -0,0 +1,361 @@
|
|
|
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::GraphAsList</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/graphs/graph_as_list_rb.html?TB_iframe=true&height=550&width=785"
|
|
38
|
+
class="thickbox" title="ds/graphs/graph_as_list.rb">ds/graphs/graph_as_list.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-add_edge">#add_edge</a></li>
|
|
71
|
+
|
|
72
|
+
<li><a href="#method-i-add_edges">#add_edges</a></li>
|
|
73
|
+
|
|
74
|
+
<li><a href="#method-i-each_vertex">#each_vertex</a></li>
|
|
75
|
+
|
|
76
|
+
</ul>
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<div id="project-metadata">
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
<div id="classindex-section" class="section project-section">
|
|
88
|
+
<h3 class="section-header">Class/Module Index
|
|
89
|
+
<span class="search-toggle"><img src="../images/find.png"
|
|
90
|
+
height="16" width="16" alt="[+]"
|
|
91
|
+
title="show/hide quicksearch" /></span></h3>
|
|
92
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
|
93
|
+
<fieldset>
|
|
94
|
+
<legend>Quicksearch</legend>
|
|
95
|
+
<input type="text" name="quicksearch" value=""
|
|
96
|
+
class="quicksearch-field" />
|
|
97
|
+
</fieldset>
|
|
98
|
+
</form>
|
|
99
|
+
|
|
100
|
+
<ul class="link-list">
|
|
101
|
+
|
|
102
|
+
<li><a href="../DS.html">DS</a></li>
|
|
103
|
+
|
|
104
|
+
<li><a href="../DS/Array2D.html">DS::Array2D</a></li>
|
|
105
|
+
|
|
106
|
+
<li><a href="../DS/BinaryHeap.html">DS::BinaryHeap</a></li>
|
|
107
|
+
|
|
108
|
+
<li><a href="../DS/BinarySearchTree.html">DS::BinarySearchTree</a></li>
|
|
109
|
+
|
|
110
|
+
<li><a href="../DS/BinaryTree.html">DS::BinaryTree</a></li>
|
|
111
|
+
|
|
112
|
+
<li><a href="../DS/CompleteBinaryTree.html">DS::CompleteBinaryTree</a></li>
|
|
113
|
+
|
|
114
|
+
<li><a href="../DS/CyclicList.html">DS::CyclicList</a></li>
|
|
115
|
+
|
|
116
|
+
<li><a href="../DS/Digraph.html">DS::Digraph</a></li>
|
|
117
|
+
|
|
118
|
+
<li><a href="../DS/Edge.html">DS::Edge</a></li>
|
|
119
|
+
|
|
120
|
+
<li><a href="../DS/ExpandableArray.html">DS::ExpandableArray</a></li>
|
|
121
|
+
|
|
122
|
+
<li><a href="../DS/Graph.html">DS::Graph</a></li>
|
|
123
|
+
|
|
124
|
+
<li><a href="../DS/GraphAsList.html">DS::GraphAsList</a></li>
|
|
125
|
+
|
|
126
|
+
<li><a href="../DS/GraphAsMatrix.html">DS::GraphAsMatrix</a></li>
|
|
127
|
+
|
|
128
|
+
<li><a href="../DS/GraphAsTriMatrix.html">DS::GraphAsTriMatrix</a></li>
|
|
129
|
+
|
|
130
|
+
<li><a href="../DS/List.html">DS::List</a></li>
|
|
131
|
+
|
|
132
|
+
<li><a href="../DS/ListElement.html">DS::ListElement</a></li>
|
|
133
|
+
|
|
134
|
+
<li><a href="../DS/Queue.html">DS::Queue</a></li>
|
|
135
|
+
|
|
136
|
+
<li><a href="../DS/Ring.html">DS::Ring</a></li>
|
|
137
|
+
|
|
138
|
+
<li><a href="../DS/Stack.html">DS::Stack</a></li>
|
|
139
|
+
|
|
140
|
+
<li><a href="../DS/Tree.html">DS::Tree</a></li>
|
|
141
|
+
|
|
142
|
+
<li><a href="../DS/TreeWalker.html">DS::TreeWalker</a></li>
|
|
143
|
+
|
|
144
|
+
<li><a href="../DS/TriMatrix.html">DS::TriMatrix</a></li>
|
|
145
|
+
|
|
146
|
+
<li><a href="../Array.html">Array</a></li>
|
|
147
|
+
|
|
148
|
+
</ul>
|
|
149
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<div id="documentation">
|
|
157
|
+
<h1 class="class">DS::GraphAsList</h1>
|
|
158
|
+
|
|
159
|
+
<div id="description" class="description">
|
|
160
|
+
|
|
161
|
+
</div><!-- description -->
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
<div id="5Buntitled-5D" class="documentation-section">
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
<!-- Methods -->
|
|
176
|
+
|
|
177
|
+
<div id="public-class-method-details" class="method-section section">
|
|
178
|
+
<h3 class="section-header">Public Class Methods</h3>
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
<div id="new-method" class="method-detail ">
|
|
182
|
+
<a name="method-c-new"></a>
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
<div class="method-heading">
|
|
186
|
+
<span class="method-name">new</span><span
|
|
187
|
+
class="method-args">()</span>
|
|
188
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
189
|
+
</div>
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
<div class="method-description">
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
<div class="method-source-code" id="new-source">
|
|
199
|
+
<pre>
|
|
200
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_list.rb, line 4</span>
|
|
201
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>
|
|
202
|
+
<span class="ruby-ivar">@store</span> = {} <span class="ruby-comment"># the graph // {node => { edge1 => weight, edge2 => weight}, node2 => ...</span>
|
|
203
|
+
<span class="ruby-ivar">@nodes</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
|
|
204
|
+
<span class="ruby-ivar">@INFINITY</span> = <span class="ruby-value">1</span> <span class="ruby-operator"><<</span> <span class="ruby-value">64</span>
|
|
205
|
+
<span class="ruby-keyword">end</span></pre>
|
|
206
|
+
</div><!-- new-source -->
|
|
207
|
+
|
|
208
|
+
</div>
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
</div><!-- new-method -->
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
</div><!-- public-class-method-details -->
|
|
217
|
+
|
|
218
|
+
<div id="public-instance-method-details" class="method-section section">
|
|
219
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
<div id="add_edge-method" class="method-detail ">
|
|
223
|
+
<a name="method-i-add_edge"></a>
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
<div class="method-heading">
|
|
227
|
+
<span class="method-name">add_edge</span><span
|
|
228
|
+
class="method-args">(x,y,w=nil)</span>
|
|
229
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
230
|
+
</div>
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
<div class="method-description">
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
<div class="method-source-code" id="add_edge-source">
|
|
240
|
+
<pre>
|
|
241
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_list.rb, line 10</span>
|
|
242
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add_edge</span>(<span class="ruby-identifier">x</span>,<span class="ruby-identifier">y</span>,<span class="ruby-identifier">w</span>=<span class="ruby-keyword">nil</span>) <span class="ruby-comment"># s= source, t= target, w= weight</span>
|
|
243
|
+
<span class="ruby-keyword">if</span> (<span class="ruby-keyword">not</span> <span class="ruby-ivar">@store</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">x</span>))
|
|
244
|
+
<span class="ruby-ivar">@store</span>[<span class="ruby-identifier">x</span>] = {<span class="ruby-identifier">y</span>=<span class="ruby-operator">></span><span class="ruby-identifier">w</span>}
|
|
245
|
+
<span class="ruby-keyword">else</span>
|
|
246
|
+
<span class="ruby-ivar">@store</span>[<span class="ruby-identifier">x</span>][<span class="ruby-identifier">y</span>] = <span class="ruby-identifier">w</span>
|
|
247
|
+
<span class="ruby-keyword">end</span>
|
|
248
|
+
|
|
249
|
+
<span class="ruby-comment"># Begin code for non directed graph (inserts the other edge too)</span>
|
|
250
|
+
|
|
251
|
+
<span class="ruby-keyword">if</span> (<span class="ruby-keyword">not</span> <span class="ruby-ivar">@store</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">y</span>))
|
|
252
|
+
<span class="ruby-ivar">@store</span>[<span class="ruby-identifier">y</span>] = {<span class="ruby-identifier">x</span>=<span class="ruby-operator">></span><span class="ruby-identifier">w</span>}
|
|
253
|
+
<span class="ruby-keyword">else</span>
|
|
254
|
+
<span class="ruby-ivar">@store</span>[<span class="ruby-identifier">y</span>][<span class="ruby-identifier">x</span>] = <span class="ruby-identifier">w</span>
|
|
255
|
+
<span class="ruby-keyword">end</span>
|
|
256
|
+
|
|
257
|
+
<span class="ruby-comment"># End code for non directed graph (ie. deleteme if you want it directed)</span>
|
|
258
|
+
|
|
259
|
+
<span class="ruby-keyword">if</span> (<span class="ruby-keyword">not</span> <span class="ruby-ivar">@nodes</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">x</span>))
|
|
260
|
+
<span class="ruby-ivar">@nodes</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">x</span>
|
|
261
|
+
<span class="ruby-keyword">end</span>
|
|
262
|
+
<span class="ruby-keyword">if</span> (<span class="ruby-keyword">not</span> <span class="ruby-ivar">@nodes</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">y</span>))
|
|
263
|
+
<span class="ruby-ivar">@nodes</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">y</span>
|
|
264
|
+
<span class="ruby-keyword">end</span>
|
|
265
|
+
<span class="ruby-keyword">end</span></pre>
|
|
266
|
+
</div><!-- add_edge-source -->
|
|
267
|
+
|
|
268
|
+
</div>
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
</div><!-- add_edge-method -->
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
<div id="add_edges-method" class="method-detail ">
|
|
277
|
+
<a name="method-i-add_edges"></a>
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
<div class="method-heading">
|
|
281
|
+
<span class="method-name">add_edges</span><span
|
|
282
|
+
class="method-args">(edges)</span>
|
|
283
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
284
|
+
</div>
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
<div class="method-description">
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
<div class="method-source-code" id="add_edges-source">
|
|
294
|
+
<pre>
|
|
295
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_list.rb, line 35</span>
|
|
296
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add_edges</span>(<span class="ruby-identifier">edges</span>)
|
|
297
|
+
<span class="ruby-keyword">for</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">edges</span>
|
|
298
|
+
<span class="ruby-identifier">add</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">from</span>,<span class="ruby-identifier">e</span>.<span class="ruby-identifier">to</span>)
|
|
299
|
+
<span class="ruby-keyword">end</span>
|
|
300
|
+
<span class="ruby-keyword">end</span></pre>
|
|
301
|
+
</div><!-- add_edges-source -->
|
|
302
|
+
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
</div><!-- add_edges-method -->
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
<div id="each_vertex-method" class="method-detail ">
|
|
312
|
+
<a name="method-i-each_vertex"></a>
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
<div class="method-heading">
|
|
316
|
+
<span class="method-name">each_vertex</span><span
|
|
317
|
+
class="method-args">()</span>
|
|
318
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
319
|
+
</div>
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
<div class="method-description">
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
<div class="method-source-code" id="each_vertex-source">
|
|
329
|
+
<pre>
|
|
330
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_list.rb, line 41</span>
|
|
331
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">each_vertex</span>
|
|
332
|
+
<span class="ruby-ivar">@adj_matrix</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">vertex</span><span class="ruby-operator">|</span>
|
|
333
|
+
<span class="ruby-keyword">yield</span> <span class="ruby-identifier">vertex</span>
|
|
334
|
+
<span class="ruby-keyword">end</span>
|
|
335
|
+
<span class="ruby-keyword">end</span></pre>
|
|
336
|
+
</div><!-- each_vertex-source -->
|
|
337
|
+
|
|
338
|
+
</div>
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
</div><!-- each_vertex-method -->
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
</div><!-- public-instance-method-details -->
|
|
347
|
+
|
|
348
|
+
</div><!-- 5Buntitled-5D -->
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
</div><!-- documentation -->
|
|
352
|
+
|
|
353
|
+
<div id="validator-badges">
|
|
354
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
355
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
|
356
|
+
Rdoc Generator</a> 2</small>.</p>
|
|
357
|
+
</div>
|
|
358
|
+
|
|
359
|
+
</body>
|
|
360
|
+
</html>
|
|
361
|
+
|
|
@@ -0,0 +1,633 @@
|
|
|
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::GraphAsMatrix</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/graphs/graph_as_matrix_rb.html?TB_iframe=true&height=550&width=785"
|
|
38
|
+
class="thickbox" title="ds/graphs/graph_as_matrix.rb">ds/graphs/graph_as_matrix.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-add_edges">#add_edges</a></li>
|
|
71
|
+
|
|
72
|
+
<li><a href="#method-i-degree">#degree</a></li>
|
|
73
|
+
|
|
74
|
+
<li><a href="#method-i-each_edge">#each_edge</a></li>
|
|
75
|
+
|
|
76
|
+
<li><a href="#method-i-each_vertex">#each_vertex</a></li>
|
|
77
|
+
|
|
78
|
+
<li><a href="#method-i-edge-3F">#edge?</a></li>
|
|
79
|
+
|
|
80
|
+
<li><a href="#method-i-get_edge">#get_edge</a></li>
|
|
81
|
+
|
|
82
|
+
<li><a href="#method-i-neighbors">#neighbors</a></li>
|
|
83
|
+
|
|
84
|
+
<li><a href="#method-i-remove">#remove</a></li>
|
|
85
|
+
|
|
86
|
+
<li><a href="#method-i-vertex_size">#vertex_size</a></li>
|
|
87
|
+
|
|
88
|
+
<li><a href="#method-i-vmax">#vmax</a></li>
|
|
89
|
+
|
|
90
|
+
</ul>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div id="project-metadata">
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
<div id="classindex-section" class="section project-section">
|
|
102
|
+
<h3 class="section-header">Class/Module Index
|
|
103
|
+
<span class="search-toggle"><img src="../images/find.png"
|
|
104
|
+
height="16" width="16" alt="[+]"
|
|
105
|
+
title="show/hide quicksearch" /></span></h3>
|
|
106
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
|
107
|
+
<fieldset>
|
|
108
|
+
<legend>Quicksearch</legend>
|
|
109
|
+
<input type="text" name="quicksearch" value=""
|
|
110
|
+
class="quicksearch-field" />
|
|
111
|
+
</fieldset>
|
|
112
|
+
</form>
|
|
113
|
+
|
|
114
|
+
<ul class="link-list">
|
|
115
|
+
|
|
116
|
+
<li><a href="../DS.html">DS</a></li>
|
|
117
|
+
|
|
118
|
+
<li><a href="../DS/Array2D.html">DS::Array2D</a></li>
|
|
119
|
+
|
|
120
|
+
<li><a href="../DS/BinaryHeap.html">DS::BinaryHeap</a></li>
|
|
121
|
+
|
|
122
|
+
<li><a href="../DS/BinarySearchTree.html">DS::BinarySearchTree</a></li>
|
|
123
|
+
|
|
124
|
+
<li><a href="../DS/BinaryTree.html">DS::BinaryTree</a></li>
|
|
125
|
+
|
|
126
|
+
<li><a href="../DS/CompleteBinaryTree.html">DS::CompleteBinaryTree</a></li>
|
|
127
|
+
|
|
128
|
+
<li><a href="../DS/CyclicList.html">DS::CyclicList</a></li>
|
|
129
|
+
|
|
130
|
+
<li><a href="../DS/Digraph.html">DS::Digraph</a></li>
|
|
131
|
+
|
|
132
|
+
<li><a href="../DS/Edge.html">DS::Edge</a></li>
|
|
133
|
+
|
|
134
|
+
<li><a href="../DS/ExpandableArray.html">DS::ExpandableArray</a></li>
|
|
135
|
+
|
|
136
|
+
<li><a href="../DS/Graph.html">DS::Graph</a></li>
|
|
137
|
+
|
|
138
|
+
<li><a href="../DS/GraphAsList.html">DS::GraphAsList</a></li>
|
|
139
|
+
|
|
140
|
+
<li><a href="../DS/GraphAsMatrix.html">DS::GraphAsMatrix</a></li>
|
|
141
|
+
|
|
142
|
+
<li><a href="../DS/GraphAsTriMatrix.html">DS::GraphAsTriMatrix</a></li>
|
|
143
|
+
|
|
144
|
+
<li><a href="../DS/List.html">DS::List</a></li>
|
|
145
|
+
|
|
146
|
+
<li><a href="../DS/ListElement.html">DS::ListElement</a></li>
|
|
147
|
+
|
|
148
|
+
<li><a href="../DS/Queue.html">DS::Queue</a></li>
|
|
149
|
+
|
|
150
|
+
<li><a href="../DS/Ring.html">DS::Ring</a></li>
|
|
151
|
+
|
|
152
|
+
<li><a href="../DS/Stack.html">DS::Stack</a></li>
|
|
153
|
+
|
|
154
|
+
<li><a href="../DS/Tree.html">DS::Tree</a></li>
|
|
155
|
+
|
|
156
|
+
<li><a href="../DS/TreeWalker.html">DS::TreeWalker</a></li>
|
|
157
|
+
|
|
158
|
+
<li><a href="../DS/TriMatrix.html">DS::TriMatrix</a></li>
|
|
159
|
+
|
|
160
|
+
<li><a href="../Array.html">Array</a></li>
|
|
161
|
+
|
|
162
|
+
</ul>
|
|
163
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<div id="documentation">
|
|
171
|
+
<h1 class="class">DS::GraphAsMatrix</h1>
|
|
172
|
+
|
|
173
|
+
<div id="description" class="description">
|
|
174
|
+
|
|
175
|
+
</div><!-- description -->
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
<div id="5Buntitled-5D" class="documentation-section">
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
<!-- Methods -->
|
|
190
|
+
|
|
191
|
+
<div id="public-class-method-details" class="method-section section">
|
|
192
|
+
<h3 class="section-header">Public Class Methods</h3>
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
<div id="new-method" class="method-detail ">
|
|
196
|
+
<a name="method-c-new"></a>
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
<div class="method-heading">
|
|
200
|
+
<span class="method-name">new</span><span
|
|
201
|
+
class="method-args">(edges)</span>
|
|
202
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
<div class="method-description">
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
<div class="method-source-code" id="new-source">
|
|
213
|
+
<pre>
|
|
214
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 4</span>
|
|
215
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">edges</span>)
|
|
216
|
+
<span class="ruby-ivar">@store</span> = <span class="ruby-constant">Array2D</span>.<span class="ruby-identifier">new</span>
|
|
217
|
+
<span class="ruby-ivar">@max</span> = <span class="ruby-value">0</span>
|
|
218
|
+
|
|
219
|
+
<span class="ruby-ivar">@v</span> = <span class="ruby-value">0</span> <span class="ruby-comment">#vertex count</span>
|
|
220
|
+
|
|
221
|
+
<span class="ruby-ivar">@map</span> = [] <span class="ruby-comment">#maps objects to matrix indexes.</span>
|
|
222
|
+
|
|
223
|
+
<span class="ruby-identifier">add_edges</span>(<span class="ruby-identifier">edges</span>)
|
|
224
|
+
<span class="ruby-keyword">end</span></pre>
|
|
225
|
+
</div><!-- new-source -->
|
|
226
|
+
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
</div><!-- new-method -->
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
</div><!-- public-class-method-details -->
|
|
236
|
+
|
|
237
|
+
<div id="public-instance-method-details" class="method-section section">
|
|
238
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
<div id="add_edges-method" class="method-detail ">
|
|
242
|
+
<a name="method-i-add_edges"></a>
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
<div class="method-heading">
|
|
246
|
+
<span class="method-name">add_edges</span><span
|
|
247
|
+
class="method-args">(edges)</span>
|
|
248
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
249
|
+
</div>
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
<div class="method-description">
|
|
253
|
+
|
|
254
|
+
<p>Adds new edges to graph.</p>
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
<div class="method-source-code" id="add_edges-source">
|
|
259
|
+
<pre>
|
|
260
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 23</span>
|
|
261
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add_edges</span>(<span class="ruby-identifier">edges</span>)
|
|
262
|
+
<span class="ruby-keyword">for</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">edges</span>
|
|
263
|
+
<span class="ruby-identifier">x</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">push_uniq</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">from</span>
|
|
264
|
+
<span class="ruby-identifier">y</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">push_uniq</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to</span>
|
|
265
|
+
|
|
266
|
+
<span class="ruby-ivar">@store</span>[<span class="ruby-identifier">x</span>,<span class="ruby-identifier">y</span>] = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">weight</span>
|
|
267
|
+
<span class="ruby-ivar">@max</span> = [<span class="ruby-ivar">@max</span>, <span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span>].<span class="ruby-identifier">max</span>
|
|
268
|
+
<span class="ruby-ivar">@v</span> = <span class="ruby-ivar">@v</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
|
|
269
|
+
<span class="ruby-keyword">end</span>
|
|
270
|
+
<span class="ruby-keyword">end</span></pre>
|
|
271
|
+
</div><!-- add_edges-source -->
|
|
272
|
+
|
|
273
|
+
</div>
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
</div><!-- add_edges-method -->
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
<div id="degree-method" class="method-detail ">
|
|
282
|
+
<a name="method-i-degree"></a>
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
<div class="method-heading">
|
|
286
|
+
<span class="method-name">degree</span><span
|
|
287
|
+
class="method-args">(x,direction=:all)</span>
|
|
288
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
289
|
+
</div>
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
<div class="method-description">
|
|
293
|
+
|
|
294
|
+
<p>Returns vertex degree. Second parameter determines direction - :in incoming
|
|
295
|
+
edges, :out - outcoming edges, :all - incoming and outcoming edges.</p>
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
<div class="method-source-code" id="degree-source">
|
|
300
|
+
<pre>
|
|
301
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 79</span>
|
|
302
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">degree</span>(<span class="ruby-identifier">x</span>,<span class="ruby-identifier">direction</span>=<span class="ruby-value">:all</span>)
|
|
303
|
+
<span class="ruby-identifier">x</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">x</span>)
|
|
304
|
+
<span class="ruby-identifier">sum_in</span> = <span class="ruby-value">0</span>
|
|
305
|
+
<span class="ruby-identifier">sum_out</span> = <span class="ruby-value">0</span>
|
|
306
|
+
<span class="ruby-value">0</span>.<span class="ruby-identifier">upto</span> <span class="ruby-ivar">@max</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
|
307
|
+
<span class="ruby-identifier">sum_in</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">i</span>,<span class="ruby-identifier">x</span>] <span class="ruby-keyword">and</span> <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">i</span>,<span class="ruby-identifier">x</span>] <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
|
308
|
+
<span class="ruby-identifier">sum_out</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">x</span>,<span class="ruby-identifier">i</span>] <span class="ruby-keyword">and</span> <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">x</span>,<span class="ruby-identifier">i</span>] <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
|
309
|
+
<span class="ruby-keyword">end</span>
|
|
310
|
+
|
|
311
|
+
<span class="ruby-keyword">case</span> <span class="ruby-identifier">direction</span>
|
|
312
|
+
<span class="ruby-keyword">when</span> <span class="ruby-value">:all</span>
|
|
313
|
+
<span class="ruby-identifier">sum_in</span><span class="ruby-operator">+</span><span class="ruby-identifier">sum_out</span>
|
|
314
|
+
<span class="ruby-keyword">when</span> <span class="ruby-value">:in</span>
|
|
315
|
+
<span class="ruby-identifier">sum_in</span>
|
|
316
|
+
<span class="ruby-keyword">when</span> <span class="ruby-value">:out</span>
|
|
317
|
+
<span class="ruby-identifier">sum_out</span>
|
|
318
|
+
<span class="ruby-keyword">end</span>
|
|
319
|
+
<span class="ruby-keyword">end</span></pre>
|
|
320
|
+
</div><!-- degree-source -->
|
|
321
|
+
|
|
322
|
+
</div>
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
</div><!-- degree-method -->
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
<div id="each_edge-method" class="method-detail ">
|
|
331
|
+
<a name="method-i-each_edge"></a>
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
<div class="method-heading">
|
|
335
|
+
<span class="method-name">each_edge</span><span
|
|
336
|
+
class="method-args">()</span>
|
|
337
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
338
|
+
</div>
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
<div class="method-description">
|
|
342
|
+
|
|
343
|
+
<p><a href="Edge.html">Edge</a> iterator</p>
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
<div class="method-source-code" id="each_edge-source">
|
|
348
|
+
<pre>
|
|
349
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 105</span>
|
|
350
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">each_edge</span>
|
|
351
|
+
<span class="ruby-keyword">for</span> <span class="ruby-identifier">v0</span> <span class="ruby-keyword">in</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-ivar">@max</span>
|
|
352
|
+
<span class="ruby-keyword">for</span> <span class="ruby-identifier">v1</span> <span class="ruby-keyword">in</span> <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">v0</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>
|
|
353
|
+
<span class="ruby-keyword">yield</span> <span class="ruby-constant">Edge</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@map</span>[<span class="ruby-identifier">v0</span>],<span class="ruby-ivar">@map</span>[<span class="ruby-identifier">v1</span>],<span class="ruby-ivar">@store</span>[<span class="ruby-identifier">v0</span>,<span class="ruby-identifier">v1</span>]) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">v0</span>,<span class="ruby-identifier">v1</span>] <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
|
354
|
+
<span class="ruby-keyword">end</span>
|
|
355
|
+
<span class="ruby-keyword">end</span>
|
|
356
|
+
<span class="ruby-keyword">end</span></pre>
|
|
357
|
+
</div><!-- each_edge-source -->
|
|
358
|
+
|
|
359
|
+
</div>
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
</div><!-- each_edge-method -->
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
<div id="each_vertex-method" class="method-detail ">
|
|
368
|
+
<a name="method-i-each_vertex"></a>
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
<div class="method-heading">
|
|
372
|
+
<span class="method-name">each_vertex</span><span
|
|
373
|
+
class="method-args">()</span>
|
|
374
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
375
|
+
</div>
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
<div class="method-description">
|
|
379
|
+
|
|
380
|
+
<p>Vertex iterator</p>
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
<div class="method-source-code" id="each_vertex-source">
|
|
385
|
+
<pre>
|
|
386
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 100</span>
|
|
387
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">each_vertex</span>
|
|
388
|
+
(<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-ivar">@max</span>).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-ivar">@map</span>[<span class="ruby-identifier">v</span>]}
|
|
389
|
+
<span class="ruby-keyword">end</span></pre>
|
|
390
|
+
</div><!-- each_vertex-source -->
|
|
391
|
+
|
|
392
|
+
</div>
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
</div><!-- each_vertex-method -->
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
<div id="edge-3F-method" class="method-detail ">
|
|
401
|
+
<a name="method-i-edge-3F"></a>
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
<div class="method-heading">
|
|
405
|
+
<span class="method-name">edge?</span><span
|
|
406
|
+
class="method-args">(x,y)</span>
|
|
407
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
408
|
+
</div>
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
<div class="method-description">
|
|
412
|
+
|
|
413
|
+
<p>Checks if two elements are connected.</p>
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
<div class="method-source-code" id="edge-3F-source">
|
|
418
|
+
<pre>
|
|
419
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 16</span>
|
|
420
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">edge?</span> <span class="ruby-identifier">x</span>,<span class="ruby-identifier">y</span>
|
|
421
|
+
<span class="ruby-identifier">v1</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">x</span>)
|
|
422
|
+
<span class="ruby-identifier">v2</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">y</span>)
|
|
423
|
+
<span class="ruby-ivar">@store</span>[<span class="ruby-identifier">v1</span>,<span class="ruby-identifier">v2</span>] <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
|
424
|
+
<span class="ruby-keyword">end</span></pre>
|
|
425
|
+
</div><!-- edge-3F-source -->
|
|
426
|
+
|
|
427
|
+
</div>
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
</div><!-- edge-3F-method -->
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
<div id="get_edge-method" class="method-detail ">
|
|
436
|
+
<a name="method-i-get_edge"></a>
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
<div class="method-heading">
|
|
440
|
+
<span class="method-name">get_edge</span><span
|
|
441
|
+
class="method-args">(x,y)</span>
|
|
442
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
443
|
+
</div>
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
<div class="method-description">
|
|
447
|
+
|
|
448
|
+
<p>Returns Edge(x,y) if exist.</p>
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
<div class="method-source-code" id="get_edge-source">
|
|
453
|
+
<pre>
|
|
454
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 57</span>
|
|
455
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_edge</span> <span class="ruby-identifier">x</span>,<span class="ruby-identifier">y</span>
|
|
456
|
+
<span class="ruby-identifier">s</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">index</span> <span class="ruby-identifier">x</span>
|
|
457
|
+
<span class="ruby-identifier">t</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">index</span> <span class="ruby-identifier">y</span>
|
|
458
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">s</span>,<span class="ruby-identifier">t</span>] <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
|
459
|
+
<span class="ruby-constant">Edge</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@map</span>[<span class="ruby-identifier">s</span>], <span class="ruby-ivar">@map</span>[<span class="ruby-identifier">t</span>], <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">s</span>,<span class="ruby-identifier">t</span>])
|
|
460
|
+
<span class="ruby-keyword">else</span>
|
|
461
|
+
<span class="ruby-keyword">nil</span>
|
|
462
|
+
<span class="ruby-keyword">end</span>
|
|
463
|
+
<span class="ruby-keyword">end</span></pre>
|
|
464
|
+
</div><!-- get_edge-source -->
|
|
465
|
+
|
|
466
|
+
</div>
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
</div><!-- get_edge-method -->
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
<div id="neighbors-method" class="method-detail ">
|
|
475
|
+
<a name="method-i-neighbors"></a>
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
<div class="method-heading">
|
|
479
|
+
<span class="method-name">neighbors</span><span
|
|
480
|
+
class="method-args">(v)</span>
|
|
481
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
482
|
+
</div>
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
<div class="method-description">
|
|
486
|
+
|
|
487
|
+
<p>Returns all neighbors for given vertex.</p>
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
<div class="method-source-code" id="neighbors-source">
|
|
492
|
+
<pre>
|
|
493
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 35</span>
|
|
494
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">neighbors</span>(<span class="ruby-identifier">v</span>)
|
|
495
|
+
<span class="ruby-identifier">n</span> = []
|
|
496
|
+
<span class="ruby-identifier">v</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">v</span>)
|
|
497
|
+
<span class="ruby-value">0</span>.<span class="ruby-identifier">upto</span> <span class="ruby-ivar">@max</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
|
498
|
+
<span class="ruby-identifier">n</span> <span class="ruby-operator"><<</span> <span class="ruby-ivar">@map</span>[<span class="ruby-identifier">i</span>] <span class="ruby-keyword">if</span> <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">v</span>,<span class="ruby-identifier">i</span>] <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
|
499
|
+
<span class="ruby-keyword">end</span>
|
|
500
|
+
<span class="ruby-identifier">n</span>
|
|
501
|
+
<span class="ruby-keyword">end</span></pre>
|
|
502
|
+
</div><!-- neighbors-source -->
|
|
503
|
+
|
|
504
|
+
</div>
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
</div><!-- neighbors-method -->
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
<div id="remove-method" class="method-detail ">
|
|
513
|
+
<a name="method-i-remove"></a>
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
<div class="method-heading">
|
|
517
|
+
<span class="method-name">remove</span><span
|
|
518
|
+
class="method-args">(x,y)</span>
|
|
519
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
520
|
+
</div>
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
<div class="method-description">
|
|
524
|
+
|
|
525
|
+
<p>Removes conection between vertex x and y.</p>
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
<div class="method-source-code" id="remove-source">
|
|
530
|
+
<pre>
|
|
531
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 45</span>
|
|
532
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">remove</span>(<span class="ruby-identifier">x</span>,<span class="ruby-identifier">y</span>)
|
|
533
|
+
<span class="ruby-identifier">v1</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">x</span>)
|
|
534
|
+
<span class="ruby-identifier">v2</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">y</span>)
|
|
535
|
+
|
|
536
|
+
<span class="ruby-ivar">@store</span>[<span class="ruby-identifier">v1</span>,<span class="ruby-identifier">v2</span>] = <span class="ruby-value">0</span>
|
|
537
|
+
<span class="ruby-keyword">if</span> (<span class="ruby-identifier">degree</span> <span class="ruby-ivar">@map</span>[<span class="ruby-ivar">@max</span>]) <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
|
538
|
+
<span class="ruby-ivar">@max</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
|
539
|
+
<span class="ruby-keyword">end</span>
|
|
540
|
+
<span class="ruby-ivar">@v</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
|
541
|
+
<span class="ruby-keyword">end</span></pre>
|
|
542
|
+
</div><!-- remove-source -->
|
|
543
|
+
|
|
544
|
+
</div>
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
</div><!-- remove-method -->
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
<div id="vertex_size-method" class="method-detail ">
|
|
553
|
+
<a name="method-i-vertex_size"></a>
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
<div class="method-heading">
|
|
557
|
+
<span class="method-name">vertex_size</span><span
|
|
558
|
+
class="method-args">()</span>
|
|
559
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
560
|
+
</div>
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
<div class="method-description">
|
|
564
|
+
|
|
565
|
+
<p>Returns vertex counter.</p>
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
<div class="method-source-code" id="vertex_size-source">
|
|
570
|
+
<pre>
|
|
571
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 72</span>
|
|
572
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">vertex_size</span>
|
|
573
|
+
<span class="ruby-ivar">@v</span>
|
|
574
|
+
<span class="ruby-keyword">end</span></pre>
|
|
575
|
+
</div><!-- vertex_size-source -->
|
|
576
|
+
|
|
577
|
+
</div>
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
</div><!-- vertex_size-method -->
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
<div id="vmax-method" class="method-detail ">
|
|
586
|
+
<a name="method-i-vmax"></a>
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
<div class="method-heading">
|
|
590
|
+
<span class="method-name">vmax</span><span
|
|
591
|
+
class="method-args">()</span>
|
|
592
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
593
|
+
</div>
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
<div class="method-description">
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
<div class="method-source-code" id="vmax-source">
|
|
603
|
+
<pre>
|
|
604
|
+
<span class="ruby-comment"># File ds/graphs/graph_as_matrix.rb, line 67</span>
|
|
605
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">vmax</span>
|
|
606
|
+
<span class="ruby-ivar">@max</span>
|
|
607
|
+
<span class="ruby-keyword">end</span></pre>
|
|
608
|
+
</div><!-- vmax-source -->
|
|
609
|
+
|
|
610
|
+
</div>
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
</div><!-- vmax-method -->
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
</div><!-- public-instance-method-details -->
|
|
619
|
+
|
|
620
|
+
</div><!-- 5Buntitled-5D -->
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
</div><!-- documentation -->
|
|
624
|
+
|
|
625
|
+
<div id="validator-badges">
|
|
626
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
627
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
|
628
|
+
Rdoc Generator</a> 2</small>.</p>
|
|
629
|
+
</div>
|
|
630
|
+
|
|
631
|
+
</body>
|
|
632
|
+
</html>
|
|
633
|
+
|