Escolar Documentos
Profissional Documentos
Cultura Documentos
Structures in Ruby
Tyler McMullen
• Speed
• Memory
• Clarity
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
NO MATCH
0 1 2 3 4 5 6 7
MATCH
0 1 2 3 4 5 6 7
FALSE MATCH
File Server
Y exists? N
200 404
Friday, February 19, 2010
Request
Bloom Filter
File Server
Y exists? N
200 404
Friday, February 19, 2010
Bloom Filter
y
4
z 1
? y
4
z 1
? y
4
z 1
≥3 y
4
z 1
1 2 3 4 5
pasta pastor taser shave light
1 2 3 4 5
pasta pastor taser shave light
1 2 3 4 5
pasta pastor taser shave light
1 2 3 4 5
pasta pastor taser shave light
pasta pastor
pasta pastor
1 2 3 4 5
pasta pastor taser shave light
1 2 3 4 5
pasta pastor taser shave light
1 2 3 4 5
pasta pastor taser shave light
1 2 3 4 5
pasta pastor taser shave light
1 2 3 4 5
pasta pastor taser shave light
4 11
2 6 9 13
1 3 5 4 8 10 12 14
4 11
2 6 9 13
1 3 5 4 8 10 12 14
4 9
2 6 8 11
10 13
1 3 5 4
12 14
7 10 13
4
12 14
2 6
1 3 5 4
H R
I A
N P
A H R
R I A
N P
U A H R
R R I A
P N P
U A H R
R R I A
P N P
U A H R
R R I A
P N P
U A H R
R R I A
P N P
U A H R
R R I A
P N P
U A H R
R R I A
P N P
Success!
Friday, February 19, 2010
Trie
query: “bumpkin”
B T
U A H R
R R I A
P N P
U A H R
R R I A
P N P
U A H R
R R I A
P N P
U A H R
R R I A
P N P
Fail!
Friday, February 19, 2010
Trie
Example: Autocompleter
def query(word)
return @trie.children(word)
end
end
def call(env)
request = Rack::Request.new(env)
return [200,
{ ‘content-‐type’ => ‘application/json’ },
@trie.children(word).to_json]
end
end