Skip to content

Commit

Permalink
use fnv gem
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedouglas committed Jul 16, 2011
1 parent e63546c commit a9723e4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -11,7 +11,7 @@ begin
gem.homepage = "http://github.com/jamesgolick/lexical_uuid"
gem.authors = ["James Golick"]
gem.add_development_dependency "rspec", ">= 1.2.9"
gem.add_dependency "RubyInline", "=3.8.4"
gem.add_dependency "fnv"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
Expand Down
22 changes: 2 additions & 20 deletions lib/lexical_uuid.rb
@@ -1,24 +1,6 @@
require "rubygems"
require "socket"
require "inline"

class String
inline :C do |builder|
builder.c <<-__END__
static long fnv1a() {
long hash = 0xcbf29ce484222325;
long i = 0;
for(i = 0; i < RSTRING_LEN(self); i++) {
hash ^= RSTRING_PTR(self)[i];
hash *= 0x100000001b3;
}
return hash;
}
__END__
end
end
require "fnv"

# Borrowed from the SimpleUUID gem
class Time
Expand All @@ -41,7 +23,7 @@ def worker_id
def create_worker_id
fqdn = Socket.gethostbyname(Socket.gethostname).first
pid = Process.pid
"#{fqdn}-#{pid}".fnv1a
FNV.new.fnv1a_64("#{fqdn}-#{pid}")
end
end

Expand Down

0 comments on commit a9723e4

Please sign in to comment.