radix_tree 1.1.0.dev → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +6 -0
- data/lib/radix_tree.rb +19 -20
- metadata +11 -5
data/README
CHANGED
data/lib/radix_tree.rb
CHANGED
@@ -90,11 +90,11 @@ class RadixTree
|
|
90
90
|
collect { |k, v| v }
|
91
91
|
end
|
92
92
|
|
93
|
-
def store(key, value)
|
93
|
+
def store(key, head, value)
|
94
94
|
if same_key?(key)
|
95
95
|
@value = value
|
96
96
|
else
|
97
|
-
pos =
|
97
|
+
pos = head_match_size(key, head)
|
98
98
|
if pos == @index
|
99
99
|
push(key, value)
|
100
100
|
else
|
@@ -108,31 +108,30 @@ class RadixTree
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
def retrieve(key)
|
111
|
+
def retrieve(key, head)
|
112
112
|
if same_key?(key)
|
113
113
|
@value
|
114
|
-
elsif !@children
|
115
|
-
UNDEFINED
|
116
114
|
else
|
117
|
-
|
118
|
-
|
119
|
-
child
|
120
|
-
|
121
|
-
|
115
|
+
if @children
|
116
|
+
pos = head_match_size(key, head)
|
117
|
+
if child = find_child(key[pos])
|
118
|
+
return child.retrieve(key, @index)
|
119
|
+
end
|
122
120
|
end
|
121
|
+
UNDEFINED
|
123
122
|
end
|
124
123
|
end
|
125
124
|
|
126
|
-
def delete(key)
|
125
|
+
def delete(key, head)
|
127
126
|
if same_key?(key)
|
128
127
|
value, @value = @value, UNDEFINED
|
129
128
|
value
|
130
129
|
elsif !@children
|
131
130
|
nil
|
132
131
|
else
|
133
|
-
pos =
|
132
|
+
pos = head_match_size(key, head)
|
134
133
|
if child = find_child(key[pos])
|
135
|
-
value = child.delete(key)
|
134
|
+
value = child.delete(key, @index)
|
136
135
|
if value and child.undefined?
|
137
136
|
reap(child)
|
138
137
|
end
|
@@ -172,7 +171,7 @@ class RadixTree
|
|
172
171
|
|
173
172
|
def push(key, value)
|
174
173
|
if @children && child = find_child(key[@index])
|
175
|
-
child.store(key, value)
|
174
|
+
child.store(key, @index, value)
|
176
175
|
else
|
177
176
|
add_child(Node.new(key, key.size, value))
|
178
177
|
end
|
@@ -194,8 +193,8 @@ class RadixTree
|
|
194
193
|
end
|
195
194
|
end
|
196
195
|
|
197
|
-
def
|
198
|
-
|
196
|
+
def head_match_size(check, head)
|
197
|
+
head.upto(@index) do |idx|
|
199
198
|
if check[idx] != @key[idx]
|
200
199
|
return idx
|
201
200
|
end
|
@@ -290,17 +289,17 @@ class RadixTree
|
|
290
289
|
end
|
291
290
|
|
292
291
|
def []=(key, value)
|
293
|
-
@root.store(key.to_s, value)
|
292
|
+
@root.store(key.to_s, 0, value)
|
294
293
|
end
|
295
294
|
alias store []=
|
296
295
|
|
297
296
|
def key?(key)
|
298
|
-
@root.retrieve(key.to_s) != Node::UNDEFINED
|
297
|
+
@root.retrieve(key.to_s, 0) != Node::UNDEFINED
|
299
298
|
end
|
300
299
|
alias has_key? key?
|
301
300
|
|
302
301
|
def [](key)
|
303
|
-
value = @root.retrieve(key.to_s)
|
302
|
+
value = @root.retrieve(key.to_s, 0)
|
304
303
|
if value == Node::UNDEFINED
|
305
304
|
if @default != DEFAULT
|
306
305
|
@default
|
@@ -315,7 +314,7 @@ class RadixTree
|
|
315
314
|
end
|
316
315
|
|
317
316
|
def delete(key)
|
318
|
-
@root.delete(key.to_s)
|
317
|
+
@root.delete(key.to_s, 0)
|
319
318
|
end
|
320
319
|
|
321
320
|
def dump_tree(io = '')
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radix_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Hiroshi Nakamura
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: nahi@ruby-lang.org
|
@@ -33,12 +33,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
33
|
- - ! '>='
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0'
|
36
|
+
segments:
|
37
|
+
- 0
|
38
|
+
hash: 2336052632168712106
|
36
39
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
40
|
none: false
|
38
41
|
requirements:
|
39
|
-
- - ! '
|
42
|
+
- - ! '>='
|
40
43
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
44
|
+
version: '0'
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
hash: 2336052632168712106
|
42
48
|
requirements: []
|
43
49
|
rubyforge_project:
|
44
50
|
rubygems_version: 1.8.11
|