gelatin 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dcd7c5c1f3a4c208becadf439bfa5dd40e590ce
4
- data.tar.gz: d3101d363020db7e05d35c4c3427851cc22e9eef
3
+ metadata.gz: 7ce5cbffcc8ac6cd5b86c28405849522c915b5af
4
+ data.tar.gz: 3d1c4897851b9ce3d3df8f904215e720e1246fd6
5
5
  SHA512:
6
- metadata.gz: 69a8096919e9035cd8133ecc60a15c8f777b0bf16342a1017bcd99e755826e05baa99d99d6a8a421b639b84e70c185e93edf339def7f93c312f2374eb54a5408
7
- data.tar.gz: 521b8c6645b5b78bdc581cd11b0e1948f4d9e6cc08e566975cfff998411da24d937df6e12acec3067d0c75b0d7ba598966ee76fcda70e6ee73818d6f66fd5ee6
6
+ metadata.gz: b2e1738195fcb627297c77042a94c391f2e02bb7705ca685c3b9690f135a3af0afb574b190d694866a3851384dcca68e543011e4770af9bc939836c29f7cd2d0
7
+ data.tar.gz: 99ca1d50e6cc77c03c94c6e199231f5e70a956d7665afc2943ed3336949e23171ac4594dcd38ce8b3bff9a8f8463b597fa1a294c287c77b79a5f8511a2b91ef2
data/README.md CHANGED
@@ -58,7 +58,7 @@ sh = Gelatin::Ring.new
58
58
  (1...254).each do |i|
59
59
  sh.add Gelatin::Node.new("192.168.0.#{i}")
60
60
  end
61
- puts sh.get("localhost".unpack('q*').first) # returns the server for this key
61
+ puts sh.get(::Zlib::crc32("s3.amazon.com")) # returns the server for this key
62
62
  ```
63
63
 
64
64
  You might use the same hasher to hash long strings like file paths, but you need to split the string into 64bit chunks.
@@ -71,7 +71,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
71
71
 
72
72
  ## Contributing
73
73
 
74
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gelatin.
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eduardordm/gelatin.
75
75
 
76
76
 
77
77
  ## License
@@ -1,7 +1,9 @@
1
- require "gelatin/version"
2
- require "gelatin/hashable"
3
- require "gelatin/node"
4
- require "gelatin/ring"
1
+ require 'gelatin/version'
2
+ require 'gelatin/node'
3
+ require 'gelatin/ring'
5
4
 
5
+ require 'zlib'
6
+
7
+ # Gelatin: Jump Consistent Hash Rubygem
6
8
  module Gelatin
7
9
  end
@@ -23,7 +23,7 @@ module Gelatin
23
23
  # If the object can fit in a uint64, you could use the object
24
24
  # itself as the key.
25
25
  def get(key)
26
- @nodes[hash(key, @nodes.size)]
26
+ @nodes[hash(Zlib::crc32(key), @nodes.size)]
27
27
  end
28
28
  end
29
29
  end
@@ -1,3 +1,4 @@
1
+ # Gelatin: Jump Consistent Hash Rubygem
1
2
  module Gelatin
2
- VERSION = "0.1.0"
3
+ VERSION = '1.0.0'
3
4
  end
@@ -6,7 +6,7 @@ class RingTest < Minitest::Test
6
6
  (1...254).each do |i|
7
7
  sh.add Gelatin::Node.new("192.168.0.#{i}")
8
8
  end
9
- refute_nil sh.get(Item.new.key)
10
- assert valid_v4? sh.get(Item.new.key).addr
9
+ refute_nil sh.get("s3.amazon.com")
10
+ assert valid_v4? sh.get("s3.amazon.com").addr
11
11
  end
12
12
  end
@@ -1,15 +1,20 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class BenchRing < Minitest::Benchmark
4
+
5
+ def self.bench_range
6
+ [1,1000,10000,100000,1000000,10000000]
7
+ end
8
+
4
9
  def bench_ring_google_numbers
5
10
  ring = Gelatin::Ring.new
6
11
 
7
- assert_performance_constant 0.1800000 do
8
- ring.add(Gelatin::Node.new("192.168.0.1"))
12
+ assert_performance_constant 0.99 do |n|
13
+ (1..n).each { ring.add(Gelatin::Node.new("192.168.0.1")) }
9
14
  end
10
15
 
11
- assert_performance_constant 0.10000 do
12
- (1..100000).each { ring.get(Item.new.key) }
16
+ assert_performance_constant 0.99 do |n|
17
+ (1..n).each { ring.get("s3.amazon.com") }
13
18
  end
14
19
  end
15
20
  end
@@ -6,12 +6,6 @@ require "minitest/benchmark"
6
6
 
7
7
  require 'securerandom'
8
8
 
9
- class Item
10
- include Gelatin::Hashable
11
- def to_s
12
- ::SecureRandom.base64
13
- end
14
- end
15
9
 
16
10
  def valid_v4?(addr)
17
11
  if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ addr
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gelatin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Mourão
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-23 00:00:00.000000000 Z
11
+ date: 2015-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -101,7 +101,6 @@ files:
101
101
  - ext/jch/jch.c
102
102
  - gelatin.gemspec
103
103
  - lib/gelatin.rb
104
- - lib/gelatin/hashable.rb
105
104
  - lib/gelatin/node.rb
106
105
  - lib/gelatin/ring.rb
107
106
  - lib/gelatin/version.rb
@@ -1,7 +0,0 @@
1
- module Gelatin
2
- module Hashable
3
- def key
4
- self.to_s.unpack('q*').first
5
- end
6
- end
7
- end