drip 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -2
- data/drip.gemspec +1 -1
- data/drip.txt +1068 -190
- data/lib/drip.rb +146 -9
- data/lib/drip/version.rb +1 -1
- data/lib/my_drip.rb +4 -0
- data/sample/copocopo.rb +1 -1
- data/sample/demo4book/crawl.rb +56 -0
- data/sample/demo4book/demo_ui.rb +71 -0
- data/sample/demo4book/demo_ui_webrick.rb +69 -0
- data/sample/demo4book/index.rb +96 -0
- data/sample/demo4book/query2.rb +47 -0
- data/sample/demo4book/query2_test.rb +18 -0
- data/test/basic.rb +131 -0
- metadata +21 -5
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rbtree'
|
2
|
+
require 'nkf'
|
3
|
+
|
4
|
+
class Query2
|
5
|
+
def initialize
|
6
|
+
@tree = RBTree.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def push(word, fname, lineno)
|
10
|
+
@tree[[word, fname, lineno]] = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def fwd(w1, fname, lineno)
|
14
|
+
k, v = @tree.lower_bound([w1, fname, lineno])
|
15
|
+
return nil unless k
|
16
|
+
return nil unless k[0] == w1
|
17
|
+
k[1..2]
|
18
|
+
end
|
19
|
+
|
20
|
+
def query2(w1, w2)
|
21
|
+
f1 = fwd(w1, '', 0)
|
22
|
+
f2 = fwd(w2, '', 0)
|
23
|
+
while f1 && f2
|
24
|
+
cmp = f1 <=> f2
|
25
|
+
if cmp > 0
|
26
|
+
f2 = fwd(w2, *f1)
|
27
|
+
elsif cmp < 0
|
28
|
+
f1 = fwd(w1, *f2)
|
29
|
+
else
|
30
|
+
yield(f1)
|
31
|
+
f1 = fwd(w1, f1[0], f1[1] + 1)
|
32
|
+
f2 = fwd(w2, f2[0], f2[1] + 1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if __FILE__ == $0
|
39
|
+
q2 = Query2.new
|
40
|
+
while line = ARGF.gets
|
41
|
+
NKF.nkf('-w', line).scan(/\w+/) do |word|
|
42
|
+
q2.push(word, ARGF.filename, ARGF.lineno)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
q2.query2('def', 'initialize') {|x| p x}
|
46
|
+
end
|
47
|
+
|
data/test/basic.rb
CHANGED
@@ -119,6 +119,11 @@ class TestDrip < Test::Unit::TestCase
|
|
119
119
|
assert_raise(RuntimeError) {@drip.write_at(Time.at(6), 8)}
|
120
120
|
assert_equal(@drip.write_after(Time.at(5), 8), 6000001)
|
121
121
|
end
|
122
|
+
|
123
|
+
def test_duplicate_tags
|
124
|
+
oid = @drip.write('dup', 'hello', 'hello', 'hello')
|
125
|
+
assert_equal(@drip[oid], ['dup', 'hello'])
|
126
|
+
end
|
122
127
|
end
|
123
128
|
|
124
129
|
class TestDripUsingStorage < TestDrip
|
@@ -153,4 +158,130 @@ class TestDripUsingStorage < TestDrip
|
|
153
158
|
ary = drip.read(ary[2][0], 3)
|
154
159
|
assert_equal(ary.size, 2)
|
155
160
|
end
|
161
|
+
|
162
|
+
def ignore_test_huge
|
163
|
+
str = File.read(__FILE__)
|
164
|
+
|
165
|
+
10.times do
|
166
|
+
1000.times do |n|
|
167
|
+
@drip.write(str, "n=#{n}")
|
168
|
+
end
|
169
|
+
@drip = Drip.new('test_db')
|
170
|
+
end
|
171
|
+
|
172
|
+
assert_equal(10000, @drip.read(0, 12000, 10000).size)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
class TestImmutableDrip < Test::Unit::TestCase
|
177
|
+
def test_bsearch
|
178
|
+
im = Drip::ImmutableDrip.new
|
179
|
+
|
180
|
+
assert_equal(0, im.lower_boundary([], 'c'))
|
181
|
+
assert_equal(0, im.upper_boundary([], 'c'))
|
182
|
+
|
183
|
+
ary = %w(a b c c c d e f).collect {|x| [x]}
|
184
|
+
|
185
|
+
assert_equal(0, im.lower_boundary(ary, ''))
|
186
|
+
assert_equal(0, im.lower_boundary(ary, 'a'))
|
187
|
+
assert_equal(1, im.lower_boundary(ary, 'b'))
|
188
|
+
assert_equal(2, im.lower_boundary(ary, 'c'))
|
189
|
+
assert_equal(5, im.lower_boundary(ary, 'd'))
|
190
|
+
assert_equal(6, im.lower_boundary(ary, 'e'))
|
191
|
+
assert_equal(7, im.lower_boundary(ary, 'f'))
|
192
|
+
assert_equal(8, im.lower_boundary(ary, 'g'))
|
193
|
+
|
194
|
+
assert_equal(0, im.upper_boundary(ary, ''))
|
195
|
+
assert_equal(1, im.upper_boundary(ary, 'a'))
|
196
|
+
assert_equal(2, im.upper_boundary(ary, 'b'))
|
197
|
+
assert_equal(5, im.upper_boundary(ary, 'c'))
|
198
|
+
assert_equal(6, im.upper_boundary(ary, 'd'))
|
199
|
+
assert_equal(7, im.upper_boundary(ary, 'e'))
|
200
|
+
assert_equal(8, im.upper_boundary(ary, 'f'))
|
201
|
+
assert_equal(8, im.upper_boundary(ary, 'g'))
|
202
|
+
end
|
203
|
+
|
204
|
+
def add_to_gen(gen, key, value, *tag)
|
205
|
+
gen.add(key, [value, *tag], *tag)
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_fetch_and_read_wo_tag
|
209
|
+
gen = Drip::ImmutableDrip::Generator.new
|
210
|
+
add_to_gen(gen, 21, 'a')
|
211
|
+
add_to_gen(gen, 99, 'd', 'tag')
|
212
|
+
add_to_gen(gen, 39, 'b')
|
213
|
+
add_to_gen(gen, 60, 'c', 'tag')
|
214
|
+
|
215
|
+
im = gen.generate
|
216
|
+
|
217
|
+
assert_equal(nil, im.fetch(20))
|
218
|
+
assert_equal(['a'], im.fetch(21))
|
219
|
+
assert_equal(nil, im.fetch(23))
|
220
|
+
assert_equal(['b'], im.fetch(39))
|
221
|
+
assert_equal(['d', 'tag'], im.fetch(99))
|
222
|
+
assert_equal(nil, im.fetch(990))
|
223
|
+
|
224
|
+
assert_equal([[21, 'a']], im.read(0))
|
225
|
+
assert_equal([[39, 'b']], im.read(21))
|
226
|
+
assert_equal([[60, 'c', 'tag']], im.read(39))
|
227
|
+
assert_equal([[99, 'd', 'tag']], im.read(60))
|
228
|
+
assert_equal([], im.read(99))
|
229
|
+
|
230
|
+
assert_equal([[21, 'a'], [39, 'b']], im.read(0, 2))
|
231
|
+
assert_equal([[60, 'c', 'tag'], [99, 'd', 'tag']], im.read(39, 10))
|
232
|
+
|
233
|
+
assert_equal([[99, 'd', 'tag']], im.head)
|
234
|
+
assert_equal([[60, 'c', 'tag'], [99, 'd', 'tag']], im.head(2))
|
235
|
+
assert_equal([[21, 'a'], [39, 'b'], [60, 'c', 'tag'], [99, 'd', 'tag']],
|
236
|
+
im.head(10))
|
237
|
+
|
238
|
+
assert_equal([99, 'd', 'tag'], im.older(nil))
|
239
|
+
assert_equal([60, 'c', 'tag'], im.older(99))
|
240
|
+
assert_equal([39, 'b'], im.older(60))
|
241
|
+
assert_equal([21, 'a'], im.older(39))
|
242
|
+
assert_equal(nil, im.older(21))
|
243
|
+
|
244
|
+
assert_equal([21, 'a'], im.newer(0))
|
245
|
+
assert_equal([39, 'b'], im.newer(21))
|
246
|
+
assert_equal([60, 'c', 'tag'], im.newer(39))
|
247
|
+
assert_equal([99, 'd', 'tag'], im.newer(60))
|
248
|
+
assert_equal(nil, im.newer(99))
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_read_w_tag
|
252
|
+
gen = Drip::ImmutableDrip::Generator.new
|
253
|
+
add_to_gen(gen, 21, 'a')
|
254
|
+
add_to_gen(gen, 39, 'b', 'b', 'tag')
|
255
|
+
add_to_gen(gen, 60, 'c', 'c', 'tag')
|
256
|
+
add_to_gen(gen, 99, 'd', 'tag', 'd')
|
257
|
+
add_to_gen(gen, 159, 'e', 'tag2', 'e')
|
258
|
+
im = gen.generate
|
259
|
+
|
260
|
+
assert_equal([[99, 'd', 'tag', 'd']], im.head(1, 'tag'))
|
261
|
+
assert_equal([[99, 'd', 'tag', 'd']], im.head(1, 'd'))
|
262
|
+
assert_equal([[60, 'c', 'c', 'tag'], [99, 'd', 'tag', 'd']],
|
263
|
+
im.head(2, 'tag'))
|
264
|
+
|
265
|
+
assert_equal([[159, 'e', 'tag2', 'e']], im.read_tag(1, 'tag2'))
|
266
|
+
assert_equal([[99, 'd', 'tag', 'd']], im.read_tag(60, 'tag', 3))
|
267
|
+
assert_equal([[60, 'c', 'c', 'tag'], [99, 'd', 'tag', 'd']],
|
268
|
+
im.read_tag(39, 'tag', 3))
|
269
|
+
assert_equal([[39, 'b', 'b', 'tag'],
|
270
|
+
[60, 'c', 'c', 'tag'],
|
271
|
+
[99, 'd', 'tag', 'd']],
|
272
|
+
im.read_tag(21, 'tag', 5))
|
273
|
+
assert_equal([[39, 'b', 'b', 'tag'],
|
274
|
+
[60, 'c', 'c', 'tag']],
|
275
|
+
im.read_tag(21, 'tag', 2))
|
276
|
+
assert_equal([[39, 'b', 'b', 'tag'],
|
277
|
+
[60, 'c', 'c', 'tag']],
|
278
|
+
im.read_tag(38, 'tag', 2))
|
279
|
+
|
280
|
+
assert_equal([99, 'd', 'tag', 'd'], im.older(nil, 'tag'))
|
281
|
+
assert_equal([60, 'c', 'c', 'tag'], im.older(99, 'tag'))
|
282
|
+
assert_equal(nil, im.older(21), 'tag')
|
283
|
+
|
284
|
+
assert_equal([60, 'c', 'c', 'tag'], im.newer(39, 'tag'))
|
285
|
+
assert_equal(nil, im.newer(99, 'tag'))
|
286
|
+
end
|
156
287
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: drip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Masatoshi Seki
|
@@ -10,9 +10,19 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
dependencies:
|
15
|
-
|
13
|
+
date: 2011-11-16 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rbtree
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
16
26
|
description: ""
|
17
27
|
email:
|
18
28
|
executables: []
|
@@ -33,6 +43,12 @@ files:
|
|
33
43
|
- lib/drip/version.rb
|
34
44
|
- lib/my_drip.rb
|
35
45
|
- sample/copocopo.rb
|
46
|
+
- sample/demo4book/crawl.rb
|
47
|
+
- sample/demo4book/demo_ui.rb
|
48
|
+
- sample/demo4book/demo_ui_webrick.rb
|
49
|
+
- sample/demo4book/index.rb
|
50
|
+
- sample/demo4book/query2.rb
|
51
|
+
- sample/demo4book/query2_test.rb
|
36
52
|
- sample/drip_tw.rb
|
37
53
|
- sample/gca.rb
|
38
54
|
- sample/hello_tw.rb
|
@@ -63,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
79
|
requirements: []
|
64
80
|
|
65
81
|
rubyforge_project: drip
|
66
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.10
|
67
83
|
signing_key:
|
68
84
|
specification_version: 3
|
69
85
|
summary: Simple RD-Stream for Rinda::TupleSpace lovers.
|