rambling-trie 0.6.0 → 0.6.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/lib/rambling/trie/branches.rb +38 -28
- data/lib/rambling/trie/version.rb +1 -1
- data/reports/performance +28 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcea070921c804471c9ddc8d4bbd60bbc700f071
|
4
|
+
data.tar.gz: cff59d6c2a69c99c91993860a0fabf8a20e9f719
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0dfdfdf111e29f29730595480ff88a9d056a405b8ef6f0427101c209560c755ab160bb52a59ddd932284dd2dae1b201a43c1c392fac90c7d2406bdb293178e0
|
7
|
+
data.tar.gz: 5efd160643a5a2e165b5b159b6887636bf6a5573acdd20156d55511139e62ad085a92f30049ae30035fddd483593d9b0c360d670a2034939391537b8e65dd9df
|
data/.gitignore
CHANGED
@@ -11,18 +11,8 @@ module Rambling
|
|
11
11
|
raise InvalidOperation, 'Cannot add branch to compressed trie' if compressed?
|
12
12
|
if word.empty?
|
13
13
|
self.terminal = true
|
14
|
-
return
|
15
|
-
end
|
16
|
-
|
17
|
-
first_letter = word.slice(0).to_sym
|
18
|
-
|
19
|
-
if children_tree.has_key? first_letter
|
20
|
-
word.slice! 0
|
21
|
-
child = children_tree[first_letter]
|
22
|
-
child << word
|
23
|
-
child
|
24
14
|
else
|
25
|
-
|
15
|
+
add_to_children_tree word
|
26
16
|
end
|
27
17
|
end
|
28
18
|
|
@@ -39,24 +29,36 @@ module Rambling
|
|
39
29
|
end
|
40
30
|
|
41
31
|
def word_when_uncompressed?(chars)
|
42
|
-
|
32
|
+
if chars.empty?
|
33
|
+
terminal?
|
34
|
+
else
|
35
|
+
fulfills_uncompressed_condition? :word_when_uncompressed?, chars
|
36
|
+
end
|
43
37
|
end
|
44
38
|
|
45
39
|
def word_when_compressed?(chars)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
first_letter << chars.slice!(0)
|
51
|
-
key = first_letter.to_sym
|
52
|
-
return children_tree[key].word_when_compressed?(chars) if children_tree.has_key? key
|
40
|
+
if chars.empty?
|
41
|
+
terminal?
|
42
|
+
else
|
43
|
+
compressed_trie_has_word? chars
|
53
44
|
end
|
54
|
-
|
55
|
-
false
|
56
45
|
end
|
57
46
|
|
58
47
|
private
|
59
48
|
|
49
|
+
def add_to_children_tree(word)
|
50
|
+
first_letter = word.slice(0).to_sym
|
51
|
+
|
52
|
+
if children_tree.has_key? first_letter
|
53
|
+
word.slice! 0
|
54
|
+
child = children_tree[first_letter]
|
55
|
+
child << word
|
56
|
+
child
|
57
|
+
else
|
58
|
+
children_tree[first_letter] = Node.new word, self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
60
62
|
def compressed_trie_has_partial_word?(chars)
|
61
63
|
current_length = 0
|
62
64
|
current_key, current_key_string = current_key chars.slice!(0)
|
@@ -68,6 +70,19 @@ module Rambling
|
|
68
70
|
return children_tree[current_key].partial_word_when_compressed?(chars)
|
69
71
|
end
|
70
72
|
end while current_key_string[current_length] == chars.slice!(0)
|
73
|
+
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
77
|
+
def compressed_trie_has_word?(chars)
|
78
|
+
current_key_string = ''
|
79
|
+
|
80
|
+
while !chars.empty?
|
81
|
+
current_key_string << chars.slice!(0)
|
82
|
+
current_key = current_key_string.to_sym
|
83
|
+
return children_tree[current_key].word_when_compressed?(chars) if children_tree.has_key? current_key
|
84
|
+
end
|
85
|
+
|
71
86
|
false
|
72
87
|
end
|
73
88
|
|
@@ -87,13 +102,8 @@ module Rambling
|
|
87
102
|
end
|
88
103
|
|
89
104
|
def fulfills_uncompressed_condition?(method, chars)
|
90
|
-
|
91
|
-
|
92
|
-
first_letter_sym = first_letter.to_sym
|
93
|
-
return children_tree[first_letter_sym].send(method, chars) if children_tree.has_key? first_letter_sym
|
94
|
-
end
|
95
|
-
|
96
|
-
false
|
105
|
+
first_letter_sym = chars.slice!(0).to_sym
|
106
|
+
children_tree.has_key?(first_letter_sym) && children_tree[first_letter_sym].send(method, chars)
|
97
107
|
end
|
98
108
|
end
|
99
109
|
end
|
data/reports/performance
CHANGED
@@ -356,3 +356,31 @@ help - true 6.250000 0.010000 6.260000 ( 6.257020)
|
|
356
356
|
beautiful - true 7.980000 0.010000 7.990000 ( 7.990850)
|
357
357
|
impressionism - true 9.940000 0.010000 9.950000 ( 9.952037)
|
358
358
|
anthropological - true 10.290000 0.010000 10.300000 ( 10.297771)
|
359
|
+
|
360
|
+
Report for rambling-trie version 0.6.1
|
361
|
+
==> Uncompressed
|
362
|
+
`word?`:
|
363
|
+
hi - true 0.580000 0.000000 0.580000 ( 0.588389)
|
364
|
+
help - true 1.160000 0.010000 1.170000 ( 1.161375)
|
365
|
+
beautiful - true 1.760000 0.000000 1.760000 ( 1.752428)
|
366
|
+
impressionism - true 2.220000 0.000000 2.220000 ( 2.229483)
|
367
|
+
anthropological - true 2.470000 0.000000 2.470000 ( 2.466127)
|
368
|
+
`partial_word?`:
|
369
|
+
hi - true 0.710000 0.000000 0.710000 ( 0.710477)
|
370
|
+
help - true 1.230000 0.000000 1.230000 ( 1.227881)
|
371
|
+
beautiful - true 1.780000 0.000000 1.780000 ( 1.786920)
|
372
|
+
impressionism - true 2.240000 0.000000 2.240000 ( 2.233523)
|
373
|
+
anthropological - true 2.450000 0.000000 2.450000 ( 2.456224)
|
374
|
+
==> Compressed
|
375
|
+
`word?`:
|
376
|
+
hi - true 0.770000 0.000000 0.770000 ( 0.769701)
|
377
|
+
help - true 1.330000 0.010000 1.340000 ( 1.337057)
|
378
|
+
beautiful - true 1.950000 0.000000 1.950000 ( 1.944460)
|
379
|
+
impressionism - true 2.470000 0.000000 2.470000 ( 2.478133)
|
380
|
+
anthropological - true 2.840000 0.000000 2.840000 ( 2.842881)
|
381
|
+
`partial_word?`:
|
382
|
+
hi - true 3.180000 0.010000 3.190000 ( 3.181099)
|
383
|
+
help - true 6.200000 0.010000 6.210000 ( 6.213987)
|
384
|
+
beautiful - true 7.880000 0.020000 7.900000 ( 7.898417)
|
385
|
+
impressionism - true 9.940000 0.010000 9.950000 ( 9.948031)
|
386
|
+
anthropological - true 10.080000 0.020000 10.100000 ( 10.103292)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rambling-trie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar Gonzalez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.0.
|
147
|
+
rubygems_version: 2.0.3
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: A custom implementation of the trie data structure.
|