Skip to content

Commit

Permalink
32-bit version of minhash just in case someone cares
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhodges committed May 8, 2009
1 parent ef05eb5 commit e358795
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/minhash.rb
Expand Up @@ -14,4 +14,13 @@ def self.minhash(history, seed)
end
val
end

def self.minhash32(history, seed)
val = Infinity
Array(history).each do |item|
n = MurmurHash.murmur_hash(item, seed)
val = n if n < val
end
val
end
end
11 changes: 11 additions & 0 deletions test/test_minhash.rb
Expand Up @@ -13,4 +13,15 @@ def test_minhash_works
m = MinHash.minhash(["baz", "bar", "foo"], 23)
assert_equal 1157430835185436796, m
end

def test_minhash32_works
m = MinHash.minhash32(["foo", "bar", "baz"], 23)
assert_equal 568256043, m

m = MinHash.minhash32(["bar", "foo", "baz"], 23)
assert_equal 568256043, m

m = MinHash.minhash32(["baz", "bar", "foo"], 23)
assert_equal 568256043, m
end
end

0 comments on commit e358795

Please sign in to comment.