class Segno::HashVec
Constants
- VALID_SERIALIZE_PATTERN
Attributes
vec[RW]
Public Class Methods
dump(hash_vec)
click to toggle source
# File lib/segno/hash_vec.rb, line 27 def self.dump hash_vec [hash_vec.b, hash_vec.k, hash_vec.to_s].join('.') end
load(string)
click to toggle source
# File lib/segno/hash_vec.rb, line 31 def self.load string if key = string.match(VALID_SERIALIZE_PATTERN) b = key['b'].to_i k = key['k'].to_i hash = key['hash'] vec = sprintf("%0#{b*k}d", hash.to_i(16).to_s(2)).scan(/.{1,#{b}}/) new vec end end
new(vec)
click to toggle source
# File lib/segno/hash_vec.rb, line 6 def initialize vec @vec = vec end
Public Instance Methods
b()
click to toggle source
# File lib/segno/hash_vec.rb, line 14 def b @vec.first.size end
jaccard(hash_vec)
click to toggle source
# File lib/segno/hash_vec.rb, line 22 def jaccard hash_vec n = [self.vec, hash_vec.vec].transpose.map{|v| v[0]==v[1]}.select{|x| x}.size (2 ** self.b * Rational(n,k) - 1) / (2 ** self.b - 1) end
k()
click to toggle source
# File lib/segno/hash_vec.rb, line 18 def k @vec.size end
to_s()
click to toggle source
# File lib/segno/hash_vec.rb, line 10 def to_s @vec.join.to_i(2).to_s(16) end