Index and Query (#54)

Hi,

looking at all those long subscriptions.. couldn't resist to make my own. probably not as complete/fast as those, but small and neat looking :smiley:

should be pretty much self explenators. it's using bignums for the index bitmaps.

have a nice day,
Kash

路路路

-----------
docs = {
聽聽:doc1 => "The quick brown fox",
聽聽:doc2 => "Jumped over the brown dog",
聽聽:doc3 => "Cut him to the quick"
}

# building word list
lst = docs.map {|k,v| v.split(/[^\w']+/) }.flatten.uniq

# building index
index = docs.inject(Hash.new(0)) do |hash, (k, v)|
聽聽lst.each { |x| hash[k] |= 2**lst.index(x) if v.index(x) }
聽聽hash
end

# query the string
q = ARGV[0] || "Cut"

res = index.map { |k,v| k if (v & 2**lst.index(q)) > 0 }.compact
p res

______________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193