grosser-algorithms 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +45 -0
- data/VERSION +1 -0
- data/ext/containers/bst/bst.c +249 -0
- data/ext/containers/bst/extconf.rb +4 -0
- data/grosser-algorithms.gemspec +4 -4
- data/rdoc/classes/Algorithms.html +221 -0
- data/rdoc/classes/Algorithms/Algorithms.html +115 -0
- data/rdoc/classes/Algorithms/Algorithms/Sort.html +569 -0
- data/rdoc/classes/Algorithms/Containers.html +162 -0
- data/rdoc/classes/Algorithms/Containers/Heap.html +690 -0
- data/rdoc/classes/Algorithms/Containers/KDTree.html +195 -0
- data/rdoc/classes/Algorithms/Containers/MaxHeap.html +238 -0
- data/rdoc/classes/Algorithms/Containers/MinHeap.html +238 -0
- data/rdoc/classes/Algorithms/Containers/PriorityQueue.html +456 -0
- data/rdoc/classes/Algorithms/Containers/Queue.html +363 -0
- data/rdoc/classes/Algorithms/Containers/RubyDeque.html +617 -0
- data/rdoc/classes/Algorithms/Containers/RubyRBTreeMap.html +662 -0
- data/rdoc/classes/Algorithms/Containers/RubySplayTreeMap.html +623 -0
- data/rdoc/classes/Algorithms/Containers/Stack.html +363 -0
- data/rdoc/classes/Algorithms/Containers/SuffixArray.html +246 -0
- data/rdoc/classes/Algorithms/Containers/Trie.html +555 -0
- data/rdoc/classes/Algorithms/Search.html +273 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/History_txt.html +281 -0
- data/rdoc/files/README_markdown.html +248 -0
- data/rdoc/files/lib/algorithms/search_rb.html +108 -0
- data/rdoc/files/lib/algorithms/sort_rb.html +108 -0
- data/rdoc/files/lib/algorithms/string_rb.html +115 -0
- data/rdoc/files/lib/algorithms_rb.html +252 -0
- data/rdoc/files/lib/containers/deque_rb.html +119 -0
- data/rdoc/files/lib/containers/heap_rb.html +124 -0
- data/rdoc/files/lib/containers/kd_tree_rb.html +135 -0
- data/rdoc/files/lib/containers/priority_queue_rb.html +108 -0
- data/rdoc/files/lib/containers/queue_rb.html +108 -0
- data/rdoc/files/lib/containers/rb_tree_map_rb.html +109 -0
- data/rdoc/files/lib/containers/splay_tree_map_rb.html +109 -0
- data/rdoc/files/lib/containers/stack_rb.html +108 -0
- data/rdoc/files/lib/containers/suffix_array_rb.html +113 -0
- data/rdoc/files/lib/containers/trie_rb.html +117 -0
- data/rdoc/fr_class_index.html +43 -0
- data/rdoc/fr_file_index.html +42 -0
- data/rdoc/fr_method_index.html +147 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/spec/bst_gc_mark_spec.rb +25 -0
- data/spec/bst_spec.rb +25 -0
- metadata +50 -3
@@ -0,0 +1,363 @@
|
|
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::Stack</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::Stack</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../../files/lib/containers/stack_rb.html">
|
59
|
+
lib/containers/stack.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="#M000107"><<</a>
|
90
|
+
<a href="#M000111">each</a>
|
91
|
+
<a href="#M000110">empty?</a>
|
92
|
+
<a href="#M000104">new</a>
|
93
|
+
<a href="#M000105">next</a>
|
94
|
+
<a href="#M000108">pop</a>
|
95
|
+
<a href="#M000106">push</a>
|
96
|
+
<a href="#M000109">size</a>
|
97
|
+
</div>
|
98
|
+
</div>
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
|
103
|
+
<!-- if includes -->
|
104
|
+
<div id="includes">
|
105
|
+
<h3 class="section-bar">Included Modules</h3>
|
106
|
+
|
107
|
+
<div id="includes-list">
|
108
|
+
<span class="include-name">Enumerable</span>
|
109
|
+
</div>
|
110
|
+
</div>
|
111
|
+
|
112
|
+
<div id="section">
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
<!-- if method_list -->
|
122
|
+
<div id="methods">
|
123
|
+
<h3 class="section-bar">Public Class methods</h3>
|
124
|
+
|
125
|
+
<div id="method-M000104" class="method-detail">
|
126
|
+
<a name="M000104"></a>
|
127
|
+
|
128
|
+
<div class="method-heading">
|
129
|
+
<a href="#M000104" class="method-signature">
|
130
|
+
<span class="method-name">new</span><span class="method-args">(ary=[])</span>
|
131
|
+
</a>
|
132
|
+
</div>
|
133
|
+
|
134
|
+
<div class="method-description">
|
135
|
+
<p>
|
136
|
+
Create a <a href="Stack.html#M000104">new</a> stack. Takes an optional
|
137
|
+
array argument to initialize the stack.
|
138
|
+
</p>
|
139
|
+
<pre>
|
140
|
+
s = Algorithms::Containers::Stack.new([1, 2, 3])
|
141
|
+
s.pop #=> 3
|
142
|
+
s.pop #=> 2
|
143
|
+
</pre>
|
144
|
+
<p><a class="source-toggle" href="#"
|
145
|
+
onclick="toggleCode('M000104-source');return false;">[Source]</a></p>
|
146
|
+
<div class="method-source-code" id="M000104-source">
|
147
|
+
<pre>
|
148
|
+
<span class="ruby-comment cmt"># File lib/containers/stack.rb, line 18</span>
|
149
|
+
18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">ary</span>=[])
|
150
|
+
19: <span class="ruby-ivar">@container</span> = <span class="ruby-constant">Deque</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">ary</span>)
|
151
|
+
20: <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-M000107" class="method-detail">
|
160
|
+
<a name="M000107"></a>
|
161
|
+
|
162
|
+
<div class="method-heading">
|
163
|
+
<span class="method-name"><<</span><span class="method-args">(obj)</span>
|
164
|
+
</div>
|
165
|
+
|
166
|
+
<div class="method-description">
|
167
|
+
<p>
|
168
|
+
Alias for <a href="Stack.html#M000106">push</a>
|
169
|
+
</p>
|
170
|
+
</div>
|
171
|
+
</div>
|
172
|
+
|
173
|
+
<div id="method-M000111" class="method-detail">
|
174
|
+
<a name="M000111"></a>
|
175
|
+
|
176
|
+
<div class="method-heading">
|
177
|
+
<a href="#M000111" class="method-signature">
|
178
|
+
<span class="method-name">each</span><span class="method-args">(&block)</span>
|
179
|
+
</a>
|
180
|
+
</div>
|
181
|
+
|
182
|
+
<div class="method-description">
|
183
|
+
<p>
|
184
|
+
Iterate over the <a href="Stack.html">Stack</a> in LIFO order.
|
185
|
+
</p>
|
186
|
+
<p><a class="source-toggle" href="#"
|
187
|
+
onclick="toggleCode('M000111-source');return false;">[Source]</a></p>
|
188
|
+
<div class="method-source-code" id="M000111-source">
|
189
|
+
<pre>
|
190
|
+
<span class="ruby-comment cmt"># File lib/containers/stack.rb, line 65</span>
|
191
|
+
65: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
192
|
+
66: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">each_backward</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
193
|
+
67: <span class="ruby-keyword kw">end</span>
|
194
|
+
</pre>
|
195
|
+
</div>
|
196
|
+
</div>
|
197
|
+
</div>
|
198
|
+
|
199
|
+
<div id="method-M000110" class="method-detail">
|
200
|
+
<a name="M000110"></a>
|
201
|
+
|
202
|
+
<div class="method-heading">
|
203
|
+
<a href="#M000110" class="method-signature">
|
204
|
+
<span class="method-name">empty?</span><span class="method-args">()</span>
|
205
|
+
</a>
|
206
|
+
</div>
|
207
|
+
|
208
|
+
<div class="method-description">
|
209
|
+
<p>
|
210
|
+
Returns true if the stack is empty, false otherwise.
|
211
|
+
</p>
|
212
|
+
<p><a class="source-toggle" href="#"
|
213
|
+
onclick="toggleCode('M000110-source');return false;">[Source]</a></p>
|
214
|
+
<div class="method-source-code" id="M000110-source">
|
215
|
+
<pre>
|
216
|
+
<span class="ruby-comment cmt"># File lib/containers/stack.rb, line 60</span>
|
217
|
+
60: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">empty?</span>
|
218
|
+
61: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">empty?</span>
|
219
|
+
62: <span class="ruby-keyword kw">end</span>
|
220
|
+
</pre>
|
221
|
+
</div>
|
222
|
+
</div>
|
223
|
+
</div>
|
224
|
+
|
225
|
+
<div id="method-M000105" class="method-detail">
|
226
|
+
<a name="M000105"></a>
|
227
|
+
|
228
|
+
<div class="method-heading">
|
229
|
+
<a href="#M000105" class="method-signature">
|
230
|
+
<span class="method-name">next</span><span class="method-args">()</span>
|
231
|
+
</a>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
<div class="method-description">
|
235
|
+
<p>
|
236
|
+
Returns the <a href="Stack.html#M000105">next</a> item from the stack but
|
237
|
+
does not remove it.
|
238
|
+
</p>
|
239
|
+
<pre>
|
240
|
+
s = Algorithms::Containers::Stack.new([1, 2, 3])
|
241
|
+
s.next #=> 3
|
242
|
+
s.size #=> 3
|
243
|
+
</pre>
|
244
|
+
<p><a class="source-toggle" href="#"
|
245
|
+
onclick="toggleCode('M000105-source');return false;">[Source]</a></p>
|
246
|
+
<div class="method-source-code" id="M000105-source">
|
247
|
+
<pre>
|
248
|
+
<span class="ruby-comment cmt"># File lib/containers/stack.rb, line 27</span>
|
249
|
+
27: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
|
250
|
+
28: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">back</span>
|
251
|
+
29: <span class="ruby-keyword kw">end</span>
|
252
|
+
</pre>
|
253
|
+
</div>
|
254
|
+
</div>
|
255
|
+
</div>
|
256
|
+
|
257
|
+
<div id="method-M000108" class="method-detail">
|
258
|
+
<a name="M000108"></a>
|
259
|
+
|
260
|
+
<div class="method-heading">
|
261
|
+
<a href="#M000108" class="method-signature">
|
262
|
+
<span class="method-name">pop</span><span class="method-args">()</span>
|
263
|
+
</a>
|
264
|
+
</div>
|
265
|
+
|
266
|
+
<div class="method-description">
|
267
|
+
<p>
|
268
|
+
Removes the <a href="Stack.html#M000105">next</a> item from the stack and
|
269
|
+
returns it.
|
270
|
+
</p>
|
271
|
+
<pre>
|
272
|
+
s = Algorithms::Containers::Stack.new([1, 2, 3])
|
273
|
+
s.pop #=> 3
|
274
|
+
s.size #=> 2
|
275
|
+
</pre>
|
276
|
+
<p><a class="source-toggle" href="#"
|
277
|
+
onclick="toggleCode('M000108-source');return false;">[Source]</a></p>
|
278
|
+
<div class="method-source-code" id="M000108-source">
|
279
|
+
<pre>
|
280
|
+
<span class="ruby-comment cmt"># File lib/containers/stack.rb, line 47</span>
|
281
|
+
47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pop</span>
|
282
|
+
48: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">pop_back</span>
|
283
|
+
49: <span class="ruby-keyword kw">end</span>
|
284
|
+
</pre>
|
285
|
+
</div>
|
286
|
+
</div>
|
287
|
+
</div>
|
288
|
+
|
289
|
+
<div id="method-M000106" class="method-detail">
|
290
|
+
<a name="M000106"></a>
|
291
|
+
|
292
|
+
<div class="method-heading">
|
293
|
+
<a href="#M000106" class="method-signature">
|
294
|
+
<span class="method-name">push</span><span class="method-args">(obj)</span>
|
295
|
+
</a>
|
296
|
+
</div>
|
297
|
+
|
298
|
+
<div class="method-description">
|
299
|
+
<p>
|
300
|
+
Adds an item to the stack.
|
301
|
+
</p>
|
302
|
+
<pre>
|
303
|
+
s = Algorithms::Containers::Stack.new([1])
|
304
|
+
s.push(2)
|
305
|
+
s.pop #=> 2
|
306
|
+
s.pop #=> 1
|
307
|
+
</pre>
|
308
|
+
<p><a class="source-toggle" href="#"
|
309
|
+
onclick="toggleCode('M000106-source');return false;">[Source]</a></p>
|
310
|
+
<div class="method-source-code" id="M000106-source">
|
311
|
+
<pre>
|
312
|
+
<span class="ruby-comment cmt"># File lib/containers/stack.rb, line 37</span>
|
313
|
+
37: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">push</span>(<span class="ruby-identifier">obj</span>)
|
314
|
+
38: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">push_back</span>(<span class="ruby-identifier">obj</span>)
|
315
|
+
39: <span class="ruby-keyword kw">end</span>
|
316
|
+
</pre>
|
317
|
+
</div>
|
318
|
+
</div>
|
319
|
+
</div>
|
320
|
+
|
321
|
+
<div id="method-M000109" class="method-detail">
|
322
|
+
<a name="M000109"></a>
|
323
|
+
|
324
|
+
<div class="method-heading">
|
325
|
+
<a href="#M000109" class="method-signature">
|
326
|
+
<span class="method-name">size</span><span class="method-args">()</span>
|
327
|
+
</a>
|
328
|
+
</div>
|
329
|
+
|
330
|
+
<div class="method-description">
|
331
|
+
<p>
|
332
|
+
Return the number of items in the stack.
|
333
|
+
</p>
|
334
|
+
<pre>
|
335
|
+
s = Algorithms::Containers::Stack.new([1, 2, 3])
|
336
|
+
s.size #=> 3
|
337
|
+
</pre>
|
338
|
+
<p><a class="source-toggle" href="#"
|
339
|
+
onclick="toggleCode('M000109-source');return false;">[Source]</a></p>
|
340
|
+
<div class="method-source-code" id="M000109-source">
|
341
|
+
<pre>
|
342
|
+
<span class="ruby-comment cmt"># File lib/containers/stack.rb, line 55</span>
|
343
|
+
55: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>
|
344
|
+
56: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">size</span>
|
345
|
+
57: <span class="ruby-keyword kw">end</span>
|
346
|
+
</pre>
|
347
|
+
</div>
|
348
|
+
</div>
|
349
|
+
</div>
|
350
|
+
|
351
|
+
|
352
|
+
</div>
|
353
|
+
|
354
|
+
|
355
|
+
</div>
|
356
|
+
|
357
|
+
|
358
|
+
<div id="validator-badges">
|
359
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
360
|
+
</div>
|
361
|
+
|
362
|
+
</body>
|
363
|
+
</html>
|
@@ -0,0 +1,246 @@
|
|
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::SuffixArray</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::SuffixArray</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../../files/lib/containers/suffix_array_rb.html">
|
59
|
+
lib/containers/suffix_array.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="#M000021">[]</a>
|
90
|
+
<a href="#M000020">has_substring?</a>
|
91
|
+
<a href="#M000019">new</a>
|
92
|
+
</div>
|
93
|
+
</div>
|
94
|
+
|
95
|
+
</div>
|
96
|
+
|
97
|
+
|
98
|
+
<!-- if includes -->
|
99
|
+
|
100
|
+
<div id="section">
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<!-- if method_list -->
|
110
|
+
<div id="methods">
|
111
|
+
<h3 class="section-bar">Public Class methods</h3>
|
112
|
+
|
113
|
+
<div id="method-M000019" class="method-detail">
|
114
|
+
<a name="M000019"></a>
|
115
|
+
|
116
|
+
<div class="method-heading">
|
117
|
+
<a href="#M000019" class="method-signature">
|
118
|
+
<span class="method-name">new</span><span class="method-args">(string)</span>
|
119
|
+
</a>
|
120
|
+
</div>
|
121
|
+
|
122
|
+
<div class="method-description">
|
123
|
+
<p>
|
124
|
+
Creates a <a href="SuffixArray.html#M000019">new</a> <a
|
125
|
+
href="SuffixArray.html">SuffixArray</a> with a given string. Object of any
|
126
|
+
class implementing a to_s method can be passed in, such as integers.
|
127
|
+
</p>
|
128
|
+
<p>
|
129
|
+
Complexity: O(n^2 log n)
|
130
|
+
</p>
|
131
|
+
<pre>
|
132
|
+
s_array = Algorithms::Containers::SuffixArray.new("abracadabra")
|
133
|
+
s_array["abra"] #=> true
|
134
|
+
|
135
|
+
number = Algorithms::Containers::SuffixArray.new(1234567)
|
136
|
+
number[1] #=> true
|
137
|
+
number[13] #=> false
|
138
|
+
</pre>
|
139
|
+
<p><a class="source-toggle" href="#"
|
140
|
+
onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
|
141
|
+
<div class="method-source-code" id="M000019-source">
|
142
|
+
<pre>
|
143
|
+
<span class="ruby-comment cmt"># File lib/containers/suffix_array.rb, line 23</span>
|
144
|
+
23: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">string</span>)
|
145
|
+
24: <span class="ruby-identifier">string</span> = <span class="ruby-identifier">string</span>.<span class="ruby-identifier">to_s</span>
|
146
|
+
25: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"SuffixArray needs to be initialized with a non-empty string"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">string</span>.<span class="ruby-identifier">empty?</span>
|
147
|
+
26: <span class="ruby-ivar">@original_string</span> = <span class="ruby-identifier">string</span>
|
148
|
+
27: <span class="ruby-ivar">@suffixes</span> = []
|
149
|
+
28: <span class="ruby-identifier">string</span>.<span class="ruby-identifier">length</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
150
|
+
29: <span class="ruby-ivar">@suffixes</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">string</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
|
151
|
+
30: <span class="ruby-keyword kw">end</span>
|
152
|
+
31:
|
153
|
+
32: <span class="ruby-comment cmt"># Sort the suffixes in ascending order</span>
|
154
|
+
33: <span class="ruby-ivar">@suffixes</span>.<span class="ruby-identifier">sort!</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"><=></span> <span class="ruby-identifier">y</span> }
|
155
|
+
34: <span class="ruby-keyword kw">end</span>
|
156
|
+
</pre>
|
157
|
+
</div>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
|
161
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
162
|
+
|
163
|
+
<div id="method-M000021" class="method-detail">
|
164
|
+
<a name="M000021"></a>
|
165
|
+
|
166
|
+
<div class="method-heading">
|
167
|
+
<span class="method-name">[]</span><span class="method-args">(substring)</span>
|
168
|
+
</div>
|
169
|
+
|
170
|
+
<div class="method-description">
|
171
|
+
<p>
|
172
|
+
Alias for has_substring?
|
173
|
+
</p>
|
174
|
+
</div>
|
175
|
+
</div>
|
176
|
+
|
177
|
+
<div id="method-M000020" class="method-detail">
|
178
|
+
<a name="M000020"></a>
|
179
|
+
|
180
|
+
<div class="method-heading">
|
181
|
+
<a href="#M000020" class="method-signature">
|
182
|
+
<span class="method-name">has_substring?</span><span class="method-args">(substring)</span>
|
183
|
+
</a>
|
184
|
+
</div>
|
185
|
+
|
186
|
+
<div class="method-description">
|
187
|
+
<p>
|
188
|
+
Returns true if the substring occurs in the string, false otherwise.
|
189
|
+
</p>
|
190
|
+
<p>
|
191
|
+
Complexity: O(m + log n)
|
192
|
+
</p>
|
193
|
+
<pre>
|
194
|
+
s_array = Algorithms::Containers::SuffixArray.new("abracadabra")
|
195
|
+
s_array.has_substring?("a") #=> true
|
196
|
+
s_array.has_substring?("abra") #=> true
|
197
|
+
s_array.has_substring?("abracadabra") #=> true
|
198
|
+
s_array.has_substring?("acadabra") #=> true
|
199
|
+
s_array.has_substring?("adabra") #=> true
|
200
|
+
s_array.has_substring?("bra") #=> true
|
201
|
+
s_array.has_substring?("bracadabra") #=> true
|
202
|
+
s_array.has_substring?("cadabra") #=> true
|
203
|
+
s_array.has_substring?("dabra") #=> true
|
204
|
+
s_array.has_substring?("ra") #=> true
|
205
|
+
s_array.has_substring?("racadabra") #=> true
|
206
|
+
s_array.has_substring?("nope") #=> false
|
207
|
+
</pre>
|
208
|
+
<p><a class="source-toggle" href="#"
|
209
|
+
onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
|
210
|
+
<div class="method-source-code" id="M000020-source">
|
211
|
+
<pre>
|
212
|
+
<span class="ruby-comment cmt"># File lib/containers/suffix_array.rb, line 53</span>
|
213
|
+
53: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_substring?</span>(<span class="ruby-identifier">substring</span>)
|
214
|
+
54: <span class="ruby-identifier">substring</span> = <span class="ruby-identifier">substring</span>.<span class="ruby-identifier">to_s</span>
|
215
|
+
55: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">substring</span>.<span class="ruby-identifier">empty?</span>
|
216
|
+
56: <span class="ruby-identifier">substring_length</span> = <span class="ruby-identifier">substring</span>.<span class="ruby-identifier">length</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>
|
217
|
+
57: <span class="ruby-identifier">l</span>, <span class="ruby-identifier">r</span> = <span class="ruby-value">0</span>, <span class="ruby-ivar">@suffixes</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>
|
218
|
+
58: <span class="ruby-keyword kw">while</span>(<span class="ruby-identifier">l</span> <span class="ruby-operator"><=</span> <span class="ruby-identifier">r</span>)
|
219
|
+
59: <span class="ruby-identifier">mid</span> = (<span class="ruby-identifier">l</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">r</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2</span>
|
220
|
+
60: <span class="ruby-identifier">suffix</span> = <span class="ruby-ivar">@suffixes</span>[<span class="ruby-identifier">mid</span>][<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">substring_length</span>]
|
221
|
+
61: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">substring</span> <span class="ruby-operator"><=></span> <span class="ruby-identifier">suffix</span>
|
222
|
+
62: <span class="ruby-keyword kw">when</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">then</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
|
223
|
+
63: <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">l</span> = <span class="ruby-identifier">mid</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
|
224
|
+
64: <span class="ruby-keyword kw">when</span> <span class="ruby-value">-1</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">r</span> = <span class="ruby-identifier">mid</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
|
225
|
+
65: <span class="ruby-keyword kw">end</span>
|
226
|
+
66: <span class="ruby-keyword kw">end</span>
|
227
|
+
67: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
|
228
|
+
68: <span class="ruby-keyword kw">end</span>
|
229
|
+
</pre>
|
230
|
+
</div>
|
231
|
+
</div>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
|
235
|
+
</div>
|
236
|
+
|
237
|
+
|
238
|
+
</div>
|
239
|
+
|
240
|
+
|
241
|
+
<div id="validator-badges">
|
242
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
243
|
+
</div>
|
244
|
+
|
245
|
+
</body>
|
246
|
+
</html>
|