critbit 0.5.0-java → 0.5.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/config.rb +39 -108
- data/doc/Critbit.html +3351 -0
- data/doc/Critbit/Cursor.html +360 -0
- data/doc/Critbit/DeleteCursor.html +294 -0
- data/doc/Critbit/EachCursor.html +228 -0
- data/doc/Critbit/EachKeyCursor.html +228 -0
- data/doc/Critbit/EachValueCursor.html +228 -0
- data/doc/Critbit/ListCursor.html +456 -0
- data/doc/_index.html +176 -0
- data/doc/class_list.html +58 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +250 -0
- data/doc/file_list.html +60 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +250 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +181 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +345 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/critbit.rb +1 -3
- data/test/test_critbit.rb +3 -4
- data/version.rb +1 -1
- metadata +30 -23
- data/lib/env.rb +0 -12
- data/test/crit.rb +0 -6
@@ -0,0 +1,250 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.7.6
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!file.README.html";
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index</a> »
|
35
|
+
<span class="title">File: README</span>
|
36
|
+
|
37
|
+
|
38
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">
|
42
|
+
|
43
|
+
<a class="full_list_link" id="class_list_link"
|
44
|
+
href="class_list.html">
|
45
|
+
Class List
|
46
|
+
</a>
|
47
|
+
|
48
|
+
<a class="full_list_link" id="method_list_link"
|
49
|
+
href="method_list.html">
|
50
|
+
Method List
|
51
|
+
</a>
|
52
|
+
|
53
|
+
<a class="full_list_link" id="file_list_link"
|
54
|
+
href="file_list.html">
|
55
|
+
File List
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<iframe id="search_frame"></iframe>
|
63
|
+
|
64
|
+
<div id="content"><div id='filecontents'>
|
65
|
+
<h1 id="label-Announcement">Announcement</h1>
|
66
|
+
|
67
|
+
<p>Critbit version 0.5 has been realeased. A crit bit tree, also known as a
|
68
|
+
Binary Patricia Trie is a trie (<a
|
69
|
+
href="https://en.wikipedia.org/wiki/Trie">en.wikipedia.org/wiki/Trie</a>),
|
70
|
+
also called digital tree and sometimes radix tree or prefix tree (as they
|
71
|
+
can be searched by prefixes), is an ordered tree data structure that is
|
72
|
+
used to store a dynamic set or associative array where the keys are usually
|
73
|
+
strings. Unlike a binary search tree, no node in the tree stores the key
|
74
|
+
associated with that node; instead, its position in the tree defines the
|
75
|
+
key with which it is associated. All the descendants of a node have a
|
76
|
+
common prefix of the string associated with that node, and the root is
|
77
|
+
associated with the empty string. Values are normally not associated with
|
78
|
+
every node, only with leaves and some inner nodes that correspond to keys
|
79
|
+
of interest. For the space-optimized presentation of prefix tree, see
|
80
|
+
compact prefix tree.</p>
|
81
|
+
|
82
|
+
<p>[The following is from: <a
|
83
|
+
href="http://cr.yp.to/critbit.html">cr.yp.to/critbit.html</a>]</p>
|
84
|
+
|
85
|
+
<p>A crit-bit tree supports the following operations (and more!) at high
|
86
|
+
speed:</p>
|
87
|
+
<ul><li>
|
88
|
+
<p>See whether a string x is in the tree.</p>
|
89
|
+
</li><li>
|
90
|
+
<p>Add x to the tree.</p>
|
91
|
+
</li><li>
|
92
|
+
<p>Remove x from the tree.</p>
|
93
|
+
</li><li>
|
94
|
+
<p>Find the lexicographically smallest string in the tree larger than x, if
|
95
|
+
there is one.</p>
|
96
|
+
</li><li>
|
97
|
+
<p>Find all suffixes of x in the tree, i.e., all strings in the tree that have
|
98
|
+
x as a prefix. Of course, this can take a long time if there are many such
|
99
|
+
strings, but each string is found quickly.</p>
|
100
|
+
</li></ul>
|
101
|
+
|
102
|
+
<p>A crit-bit tree can be used as a high-speed associative array. For example,
|
103
|
+
an array mapping 54 to 1, 19 to 2, 99 to 3, 85 to 4, and 88 to 5 can be
|
104
|
+
stored as a crit-bit tree containing 54=1, 19=2, 99=3, 85=4, and 88=5. The
|
105
|
+
smallest string in the crit-bit tree larger than 85= is 85=4.</p>
|
106
|
+
|
107
|
+
<p>The standard strategy for many years has been to store searchable data sets
|
108
|
+
as hash tables, in applications that need exact searches but not
|
109
|
+
lexicographic searches; or as heaps, in applications that need to search
|
110
|
+
for the minimum; or as AVL trees, red-black trees, etc. in applications
|
111
|
+
that do not fit the restrictions of hash tables and heaps.</p>
|
112
|
+
|
113
|
+
<p>In Python, for example, the built-in “dict” data type is a hash table. Hash
|
114
|
+
tables don't provide fast access to the smallest entry, so there's
|
115
|
+
also a standard “heapq” library providing heaps. Heaps don't provide
|
116
|
+
fast lookups of other entries, so there are various add-on libraries
|
117
|
+
providing AVL trees and so on. A programmer who's happy creating a
|
118
|
+
“dict” will simply do so, but then another programmer who wants fancier
|
119
|
+
operations on the resulting database has to do an expensive conversion of
|
120
|
+
the “dict” to a fancier data structure.</p>
|
121
|
+
|
122
|
+
<p>I (D. J. Bernstein) have become convinced that this strategy should change.
|
123
|
+
The revised strategy is much simpler: there should be one fundamental
|
124
|
+
set-storage type, namely a crit-bit tree. Here's how a crit-bit tree
|
125
|
+
stacks up against the competition:</p>
|
126
|
+
|
127
|
+
<p>A hash table supports insertion, deletion, and exact searches. A crit-bit
|
128
|
+
tree supports insertion, deletion, exact searches, and ordered operations
|
129
|
+
such as finding the minimum. Another advantage is that a crit-bit tree
|
130
|
+
guarantees good performance: it doesn't have any tricky slowdowns for
|
131
|
+
unusual (or malicious) data.</p>
|
132
|
+
|
133
|
+
<p>A heap supports insertion, deletion, and finding the minimum. A crit-bit
|
134
|
+
tree supports insertion, deletion, finding the minimum, and exact searches,
|
135
|
+
and general suffix searches.</p>
|
136
|
+
|
137
|
+
<p>General-purpose comparison-based structures such as AVL trees and B-trees
|
138
|
+
support exactly the same operations as a crit-bit tree. However, crit-bit
|
139
|
+
trees are faster and simpler, especially for variable-length strings.
|
140
|
+
B-trees advertise a memory layout that's friendly to your disk, but
|
141
|
+
with less effort one can use a similar “clustering” organization for nodes
|
142
|
+
in a crit-bit tree.</p>
|
143
|
+
|
144
|
+
<p>If you're designing a programming language, imagine how much happier
|
145
|
+
your programmers will be if your basic built-in data type allows not just
|
146
|
+
looking up x, but also enumerating the strings after x in sorted order. You
|
147
|
+
can't do this with hash tables. You could do it with an AVL tree, but
|
148
|
+
your operations will be simpler and faster if you use a crit-bit tree.</p>
|
149
|
+
|
150
|
+
<h1 id="label-Critbit+Interface">Critbit Interface</h1>
|
151
|
+
|
152
|
+
<p>This version of Critbit implements a very similar interface as the Hash
|
153
|
+
interface with minor modifications when it makes sense to do so. Besides
|
154
|
+
implementing the Hash interface it also provides features for searching for
|
155
|
+
keys that have a common prefix that are not possible with hashes.</p>
|
156
|
+
|
157
|
+
<p>Here is an example of using Critbit:</p>
|
158
|
+
|
159
|
+
<pre class="code ruby"><code class="ruby"> <span class='id identifier rubyid_crit'>crit</span> <span class='op'>=</span> <span class='const'>Critbit</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
160
|
+
|
161
|
+
<span class='comment'># crit is space efficient and stores prefixes only once and can be used to
|
162
|
+
</span> <span class='comment'># find only strings that match a certain prefix
|
163
|
+
</span> <span class='id identifier rubyid_items'>items</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>u</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>un</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unh</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>uni</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unj</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unim</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unin</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unio</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
164
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>uninc</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unind</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unine</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>uninde</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindf</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
165
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindew</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindex</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindey</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>a</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>z</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span>
|
166
|
+
|
167
|
+
<span class='comment'># add items to the container
|
168
|
+
</span> <span class='id identifier rubyid_items'>items</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_item'>item</span><span class='op'>|</span>
|
169
|
+
<span class='id identifier rubyid_crit'>crit</span><span class='lbracket'>[</span><span class='id identifier rubyid_item'>item</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_item'>item</span>
|
170
|
+
<span class='kw'>end</span>
|
171
|
+
|
172
|
+
<span class='comment'># Does each for all elements in the critbit
|
173
|
+
</span> <span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[</span><span class='tstring_end'>"</span></span>
|
174
|
+
<span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
|
175
|
+
<span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>, </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_value'>value</span><span class='embexpr_end'>}</span><span class='tstring_content'>] </span><span class='tstring_end'>"</span></span>
|
176
|
+
<span class='kw'>end</span>
|
177
|
+
<span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>]</span><span class='tstring_end'>"</span></span>
|
178
|
+
</code></pre>
|
179
|
+
|
180
|
+
<p>Prints:</p>
|
181
|
+
|
182
|
+
<pre class="code ruby"><code class="ruby"> [[a, a] [u, u] [un, un] [unh, unh] [uni, uni] [unim, unim] [unin, unin] [uninc, uninc]
|
183
|
+
[unind, unind] [unindd, unindd] [uninde, uninde] [unindew, unindew] [unindex, unindex]
|
184
|
+
[unindey, unindey] [unindf, unindf] [unine, unine] [unio, unio] [unj, unj] [z, z] ].</code></pre>
|
185
|
+
|
186
|
+
<p>Observe that all elements are printed in sorted order, this is because
|
187
|
+
critbit is naturally sorted. This is one of the benefits of critbit over
|
188
|
+
hashes.</p>
|
189
|
+
|
190
|
+
<p>Critbits also allow for doing prefix traversal. In the next code example
|
191
|
+
the critbit is traversed by only selecting strings that have “unin” as
|
192
|
+
prefix, by passing the prefix as argument to 'each':</p>
|
193
|
+
|
194
|
+
<pre class="code ruby"><code class="ruby"> # Does each for all elements in the critbit
|
195
|
+
print "["
|
196
|
+
crit.each("unin") do |key, value|
|
197
|
+
print "[#{key}, #{value}] "
|
198
|
+
end
|
199
|
+
print "]"
|
200
|
+
|
201
|
+
[[unin, unin] [uninc, uninc] [unind, unind] [unindd, unindd] [uninde, uninde]
|
202
|
+
[unindew, unindew] [unindex, unindex] [unindey, unindey] [unindf, unindf]
|
203
|
+
[unine, unine] ].
|
204
|
+
</code></pre>
|
205
|
+
|
206
|
+
<p>A critbit prefix can also be set by using method 'prefix=':</p>
|
207
|
+
|
208
|
+
<pre class="code ruby"><code class="ruby"> <span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_prefix'>prefix</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unin</span><span class='tstring_end'>"</span></span>
|
209
|
+
|
210
|
+
<span class='comment'># Does each for all elements in the critbit
|
211
|
+
</span> <span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[</span><span class='tstring_end'>"</span></span>
|
212
|
+
<span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
|
213
|
+
<span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>, </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_value'>value</span><span class='embexpr_end'>}</span><span class='tstring_content'>] </span><span class='tstring_end'>"</span></span>
|
214
|
+
<span class='kw'>end</span>
|
215
|
+
<span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>]</span><span class='tstring_end'>"</span></span>
|
216
|
+
</code></pre>
|
217
|
+
|
218
|
+
<h1 id="label-Critbit+installation+and+download%3A">Critbit installation and download:</h1>
|
219
|
+
<ul><li>
|
220
|
+
<p>Install Jruby</p>
|
221
|
+
</li><li>
|
222
|
+
<p>jruby –S gem install critbit</p>
|
223
|
+
</li></ul>
|
224
|
+
|
225
|
+
<h1 id="label-Critbit+Homepages%3A">Critbit Homepages:</h1>
|
226
|
+
<ul><li>
|
227
|
+
<p><a href="http://rubygems.org/gems/critbit">rubygems.org/gems/critbit</a></p>
|
228
|
+
</li><li>
|
229
|
+
<p><a
|
230
|
+
href="https://github.com/rbotafogo/critbit/wiki">github.com/rbotafogo/critbit/wiki</a></p>
|
231
|
+
</li></ul>
|
232
|
+
|
233
|
+
<h1 id="label-Contributors%3A">Contributors:</h1>
|
234
|
+
|
235
|
+
<p>Contributors are welcome.</p>
|
236
|
+
|
237
|
+
<h1 id="label-Critbit+History%3A">Critbit History:</h1>
|
238
|
+
<ul><li>
|
239
|
+
<p>05/04/2013: Version 0.5.0 – Initial release.</p>
|
240
|
+
</li></ul>
|
241
|
+
</div></div>
|
242
|
+
|
243
|
+
<div id="footer">
|
244
|
+
Generated on Wed Jul 22 14:04:04 2015 by
|
245
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
246
|
+
0.8.7.6 (ruby-2.2.2).
|
247
|
+
</div>
|
248
|
+
|
249
|
+
</body>
|
250
|
+
</html>
|
data/doc/file_list.html
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<script type="text/javascript" charset="utf-8">
|
23
|
+
var hasFrames = false;
|
24
|
+
try {
|
25
|
+
hasFrames = window.top.frames.main ? true : false;
|
26
|
+
} catch (e) { }
|
27
|
+
if (hasFrames) {
|
28
|
+
document.getElementById('base_target').target = 'main';
|
29
|
+
document.body.className = 'frames';
|
30
|
+
}
|
31
|
+
</script>
|
32
|
+
<div id="content">
|
33
|
+
<h1 id="full_list_header">File List</h1>
|
34
|
+
<div id="nav">
|
35
|
+
|
36
|
+
<span><a target="_self" href="class_list.html">
|
37
|
+
Classes
|
38
|
+
</a></span>
|
39
|
+
|
40
|
+
<span><a target="_self" href="method_list.html">
|
41
|
+
Methods
|
42
|
+
</a></span>
|
43
|
+
|
44
|
+
<span><a target="_self" href="file_list.html">
|
45
|
+
Files
|
46
|
+
</a></span>
|
47
|
+
|
48
|
+
</div>
|
49
|
+
<div id="search">Search: <input type="text" /></div>
|
50
|
+
|
51
|
+
<ul id="full_list" class="file">
|
52
|
+
|
53
|
+
|
54
|
+
<li class="r1"><span class="object_link"><a href="index.html" title="README">README</a></a></li>
|
55
|
+
|
56
|
+
|
57
|
+
</ul>
|
58
|
+
</div>
|
59
|
+
</body>
|
60
|
+
</html>
|
data/doc/frames.html
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
+
<title>Documentation by YARD 0.8.7.6</title>
|
8
|
+
</head>
|
9
|
+
<script type="text/javascript" charset="utf-8">
|
10
|
+
window.onload = function() {
|
11
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
12
|
+
var name = match ? match[1] : 'index.html';
|
13
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
14
|
+
document.writeln('<frameset cols="20%,*">' +
|
15
|
+
'<frame name="list" src="class_list.html" />' +
|
16
|
+
'<frame name="main" src="' + escape(name) + '" />' +
|
17
|
+
'</frameset>');
|
18
|
+
}
|
19
|
+
</script>
|
20
|
+
<noscript>
|
21
|
+
<frameset cols="20%,*">
|
22
|
+
<frame name="list" src="class_list.html" />
|
23
|
+
<frame name="main" src="index.html" />
|
24
|
+
</frameset>
|
25
|
+
</noscript>
|
26
|
+
</html>
|
data/doc/index.html
ADDED
@@ -0,0 +1,250 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.7.6
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!file.README.html";
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index</a> »
|
35
|
+
<span class="title">File: README</span>
|
36
|
+
|
37
|
+
|
38
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">
|
42
|
+
|
43
|
+
<a class="full_list_link" id="class_list_link"
|
44
|
+
href="class_list.html">
|
45
|
+
Class List
|
46
|
+
</a>
|
47
|
+
|
48
|
+
<a class="full_list_link" id="method_list_link"
|
49
|
+
href="method_list.html">
|
50
|
+
Method List
|
51
|
+
</a>
|
52
|
+
|
53
|
+
<a class="full_list_link" id="file_list_link"
|
54
|
+
href="file_list.html">
|
55
|
+
File List
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<iframe id="search_frame"></iframe>
|
63
|
+
|
64
|
+
<div id="content"><div id='filecontents'>
|
65
|
+
<h1 id="label-Announcement">Announcement</h1>
|
66
|
+
|
67
|
+
<p>Critbit version 0.5 has been realeased. A crit bit tree, also known as a
|
68
|
+
Binary Patricia Trie is a trie (<a
|
69
|
+
href="https://en.wikipedia.org/wiki/Trie">en.wikipedia.org/wiki/Trie</a>),
|
70
|
+
also called digital tree and sometimes radix tree or prefix tree (as they
|
71
|
+
can be searched by prefixes), is an ordered tree data structure that is
|
72
|
+
used to store a dynamic set or associative array where the keys are usually
|
73
|
+
strings. Unlike a binary search tree, no node in the tree stores the key
|
74
|
+
associated with that node; instead, its position in the tree defines the
|
75
|
+
key with which it is associated. All the descendants of a node have a
|
76
|
+
common prefix of the string associated with that node, and the root is
|
77
|
+
associated with the empty string. Values are normally not associated with
|
78
|
+
every node, only with leaves and some inner nodes that correspond to keys
|
79
|
+
of interest. For the space-optimized presentation of prefix tree, see
|
80
|
+
compact prefix tree.</p>
|
81
|
+
|
82
|
+
<p>[The following is from: <a
|
83
|
+
href="http://cr.yp.to/critbit.html">cr.yp.to/critbit.html</a>]</p>
|
84
|
+
|
85
|
+
<p>A crit-bit tree supports the following operations (and more!) at high
|
86
|
+
speed:</p>
|
87
|
+
<ul><li>
|
88
|
+
<p>See whether a string x is in the tree.</p>
|
89
|
+
</li><li>
|
90
|
+
<p>Add x to the tree.</p>
|
91
|
+
</li><li>
|
92
|
+
<p>Remove x from the tree.</p>
|
93
|
+
</li><li>
|
94
|
+
<p>Find the lexicographically smallest string in the tree larger than x, if
|
95
|
+
there is one.</p>
|
96
|
+
</li><li>
|
97
|
+
<p>Find all suffixes of x in the tree, i.e., all strings in the tree that have
|
98
|
+
x as a prefix. Of course, this can take a long time if there are many such
|
99
|
+
strings, but each string is found quickly.</p>
|
100
|
+
</li></ul>
|
101
|
+
|
102
|
+
<p>A crit-bit tree can be used as a high-speed associative array. For example,
|
103
|
+
an array mapping 54 to 1, 19 to 2, 99 to 3, 85 to 4, and 88 to 5 can be
|
104
|
+
stored as a crit-bit tree containing 54=1, 19=2, 99=3, 85=4, and 88=5. The
|
105
|
+
smallest string in the crit-bit tree larger than 85= is 85=4.</p>
|
106
|
+
|
107
|
+
<p>The standard strategy for many years has been to store searchable data sets
|
108
|
+
as hash tables, in applications that need exact searches but not
|
109
|
+
lexicographic searches; or as heaps, in applications that need to search
|
110
|
+
for the minimum; or as AVL trees, red-black trees, etc. in applications
|
111
|
+
that do not fit the restrictions of hash tables and heaps.</p>
|
112
|
+
|
113
|
+
<p>In Python, for example, the built-in “dict” data type is a hash table. Hash
|
114
|
+
tables don't provide fast access to the smallest entry, so there's
|
115
|
+
also a standard “heapq” library providing heaps. Heaps don't provide
|
116
|
+
fast lookups of other entries, so there are various add-on libraries
|
117
|
+
providing AVL trees and so on. A programmer who's happy creating a
|
118
|
+
“dict” will simply do so, but then another programmer who wants fancier
|
119
|
+
operations on the resulting database has to do an expensive conversion of
|
120
|
+
the “dict” to a fancier data structure.</p>
|
121
|
+
|
122
|
+
<p>I (D. J. Bernstein) have become convinced that this strategy should change.
|
123
|
+
The revised strategy is much simpler: there should be one fundamental
|
124
|
+
set-storage type, namely a crit-bit tree. Here's how a crit-bit tree
|
125
|
+
stacks up against the competition:</p>
|
126
|
+
|
127
|
+
<p>A hash table supports insertion, deletion, and exact searches. A crit-bit
|
128
|
+
tree supports insertion, deletion, exact searches, and ordered operations
|
129
|
+
such as finding the minimum. Another advantage is that a crit-bit tree
|
130
|
+
guarantees good performance: it doesn't have any tricky slowdowns for
|
131
|
+
unusual (or malicious) data.</p>
|
132
|
+
|
133
|
+
<p>A heap supports insertion, deletion, and finding the minimum. A crit-bit
|
134
|
+
tree supports insertion, deletion, finding the minimum, and exact searches,
|
135
|
+
and general suffix searches.</p>
|
136
|
+
|
137
|
+
<p>General-purpose comparison-based structures such as AVL trees and B-trees
|
138
|
+
support exactly the same operations as a crit-bit tree. However, crit-bit
|
139
|
+
trees are faster and simpler, especially for variable-length strings.
|
140
|
+
B-trees advertise a memory layout that's friendly to your disk, but
|
141
|
+
with less effort one can use a similar “clustering” organization for nodes
|
142
|
+
in a crit-bit tree.</p>
|
143
|
+
|
144
|
+
<p>If you're designing a programming language, imagine how much happier
|
145
|
+
your programmers will be if your basic built-in data type allows not just
|
146
|
+
looking up x, but also enumerating the strings after x in sorted order. You
|
147
|
+
can't do this with hash tables. You could do it with an AVL tree, but
|
148
|
+
your operations will be simpler and faster if you use a crit-bit tree.</p>
|
149
|
+
|
150
|
+
<h1 id="label-Critbit+Interface">Critbit Interface</h1>
|
151
|
+
|
152
|
+
<p>This version of Critbit implements a very similar interface as the Hash
|
153
|
+
interface with minor modifications when it makes sense to do so. Besides
|
154
|
+
implementing the Hash interface it also provides features for searching for
|
155
|
+
keys that have a common prefix that are not possible with hashes.</p>
|
156
|
+
|
157
|
+
<p>Here is an example of using Critbit:</p>
|
158
|
+
|
159
|
+
<pre class="code ruby"><code class="ruby"> <span class='id identifier rubyid_crit'>crit</span> <span class='op'>=</span> <span class='const'>Critbit</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
160
|
+
|
161
|
+
<span class='comment'># crit is space efficient and stores prefixes only once and can be used to
|
162
|
+
</span> <span class='comment'># find only strings that match a certain prefix
|
163
|
+
</span> <span class='id identifier rubyid_items'>items</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>u</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>un</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unh</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>uni</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unj</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unim</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unin</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unio</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
164
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>uninc</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unind</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unine</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>uninde</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindf</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
165
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindew</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindex</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unindey</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>a</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>z</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span>
|
166
|
+
|
167
|
+
<span class='comment'># add items to the container
|
168
|
+
</span> <span class='id identifier rubyid_items'>items</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_item'>item</span><span class='op'>|</span>
|
169
|
+
<span class='id identifier rubyid_crit'>crit</span><span class='lbracket'>[</span><span class='id identifier rubyid_item'>item</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_item'>item</span>
|
170
|
+
<span class='kw'>end</span>
|
171
|
+
|
172
|
+
<span class='comment'># Does each for all elements in the critbit
|
173
|
+
</span> <span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[</span><span class='tstring_end'>"</span></span>
|
174
|
+
<span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
|
175
|
+
<span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>, </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_value'>value</span><span class='embexpr_end'>}</span><span class='tstring_content'>] </span><span class='tstring_end'>"</span></span>
|
176
|
+
<span class='kw'>end</span>
|
177
|
+
<span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>]</span><span class='tstring_end'>"</span></span>
|
178
|
+
</code></pre>
|
179
|
+
|
180
|
+
<p>Prints:</p>
|
181
|
+
|
182
|
+
<pre class="code ruby"><code class="ruby"> [[a, a] [u, u] [un, un] [unh, unh] [uni, uni] [unim, unim] [unin, unin] [uninc, uninc]
|
183
|
+
[unind, unind] [unindd, unindd] [uninde, uninde] [unindew, unindew] [unindex, unindex]
|
184
|
+
[unindey, unindey] [unindf, unindf] [unine, unine] [unio, unio] [unj, unj] [z, z] ].</code></pre>
|
185
|
+
|
186
|
+
<p>Observe that all elements are printed in sorted order, this is because
|
187
|
+
critbit is naturally sorted. This is one of the benefits of critbit over
|
188
|
+
hashes.</p>
|
189
|
+
|
190
|
+
<p>Critbits also allow for doing prefix traversal. In the next code example
|
191
|
+
the critbit is traversed by only selecting strings that have “unin” as
|
192
|
+
prefix, by passing the prefix as argument to 'each':</p>
|
193
|
+
|
194
|
+
<pre class="code ruby"><code class="ruby"> # Does each for all elements in the critbit
|
195
|
+
print "["
|
196
|
+
crit.each("unin") do |key, value|
|
197
|
+
print "[#{key}, #{value}] "
|
198
|
+
end
|
199
|
+
print "]"
|
200
|
+
|
201
|
+
[[unin, unin] [uninc, uninc] [unind, unind] [unindd, unindd] [uninde, uninde]
|
202
|
+
[unindew, unindew] [unindex, unindex] [unindey, unindey] [unindf, unindf]
|
203
|
+
[unine, unine] ].
|
204
|
+
</code></pre>
|
205
|
+
|
206
|
+
<p>A critbit prefix can also be set by using method 'prefix=':</p>
|
207
|
+
|
208
|
+
<pre class="code ruby"><code class="ruby"> <span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_prefix'>prefix</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>unin</span><span class='tstring_end'>"</span></span>
|
209
|
+
|
210
|
+
<span class='comment'># Does each for all elements in the critbit
|
211
|
+
</span> <span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[</span><span class='tstring_end'>"</span></span>
|
212
|
+
<span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
|
213
|
+
<span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>, </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_value'>value</span><span class='embexpr_end'>}</span><span class='tstring_content'>] </span><span class='tstring_end'>"</span></span>
|
214
|
+
<span class='kw'>end</span>
|
215
|
+
<span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>]</span><span class='tstring_end'>"</span></span>
|
216
|
+
</code></pre>
|
217
|
+
|
218
|
+
<h1 id="label-Critbit+installation+and+download%3A">Critbit installation and download:</h1>
|
219
|
+
<ul><li>
|
220
|
+
<p>Install Jruby</p>
|
221
|
+
</li><li>
|
222
|
+
<p>jruby –S gem install critbit</p>
|
223
|
+
</li></ul>
|
224
|
+
|
225
|
+
<h1 id="label-Critbit+Homepages%3A">Critbit Homepages:</h1>
|
226
|
+
<ul><li>
|
227
|
+
<p><a href="http://rubygems.org/gems/critbit">rubygems.org/gems/critbit</a></p>
|
228
|
+
</li><li>
|
229
|
+
<p><a
|
230
|
+
href="https://github.com/rbotafogo/critbit/wiki">github.com/rbotafogo/critbit/wiki</a></p>
|
231
|
+
</li></ul>
|
232
|
+
|
233
|
+
<h1 id="label-Contributors%3A">Contributors:</h1>
|
234
|
+
|
235
|
+
<p>Contributors are welcome.</p>
|
236
|
+
|
237
|
+
<h1 id="label-Critbit+History%3A">Critbit History:</h1>
|
238
|
+
<ul><li>
|
239
|
+
<p>05/04/2013: Version 0.5.0 – Initial release.</p>
|
240
|
+
</li></ul>
|
241
|
+
</div></div>
|
242
|
+
|
243
|
+
<div id="footer">
|
244
|
+
Generated on Wed Jul 22 14:04:01 2015 by
|
245
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
246
|
+
0.8.7.6 (ruby-2.2.2).
|
247
|
+
</div>
|
248
|
+
|
249
|
+
</body>
|
250
|
+
</html>
|