Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhodges committed May 4, 2009
0 parents commit 2c656ad
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .autotest
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- ruby -*-

require 'autotest/restart'

# Autotest.add_hook :initialize do |at|
# at.extra_files << "../some/external/dependency.rb"
#
# at.libs << ":../some/external"
#
# at.add_exception 'vendor'
#
# at.add_mapping(/dependency.rb/) do |f, _|
# at.files_matching(/test_.*rb$/)
# end
#
# %w(TestA TestB).each do |klass|
# at.extra_class_map[klass] = "test/test_misc.rb"
# end
# end

# Autotest.add_hook :run_command do |at|
# system "rake build"
# end
6 changes: 6 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== 1.0.0 / 2009-05-03

* 1 major enhancement

* Birthday!

6 changes: 6 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
History.txt
Manifest.txt
README.txt
Rakefile
lib/minhash.rb
test/test_minhash.rb
48 changes: 48 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
= minhash

* FIX (url)

== DESCRIPTION:

FIX (describe your package)

== FEATURES/PROBLEMS:

* FIX (list of features or problems)

== SYNOPSIS:

FIX (code sample of usage)

== REQUIREMENTS:

* FIX (list of requirements)

== INSTALL:

* FIX (sudo gem install, anything else)

== LICENSE:

(The MIT License)

Copyright (c) 2009 FIX

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 16 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- ruby -*-

require 'rubygems'
require 'hoe'
begin
require './lib/minhash.rb'
rescue LoadError
end

Hoe.new('minhash', MinHash::VERSION || '0.0.0') do |p|
# p.rubyforge_name = 'minhash' # if different than lowercase project name
p.developer('Jeff Hodges', 'jeff@somethingsimilar.com')
p.extra_deps << ['murmur_hash', '1.0.1']
end

# vim: syntax=Ruby
15 changes: 15 additions & 0 deletions lib/minhash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module MinHash
VERSION = '0.9.9'
# We use murmur_hash64 because we really do need 2**64 -1 items and
# I'm assuming all the machines it will be deployed on are
# little-endian.
Infinity = 1.0 / 0.0
def self.minhash(history, seed)
val = Infinity
Array(history).each do |item|
n = MurmurHash.murmur_hash64(item, seed)
val = n if n < val
end
val
end
end
15 changes: 15 additions & 0 deletions test/test_minhash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "test/unit"
require "minhash"

class TestMinHash < Test::Unit::TestCase
def test_minhash_works
m = MinHash.minhash(["foo", "bar", "baz"], 23)
assert_equal 1157430835185436796, m

m = MinHash.minhash(["bar", "foo", "baz"], 23)
assert_equal 1157430835185436796, m

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

0 comments on commit 2c656ad

Please sign in to comment.