hash_digest 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +2 -0
- data/CHANGELOG +7 -0
- data/README.markdown +45 -10
- data/Rakefile +5 -0
- data/hash_digest.gemspec +5 -1
- data/lib/hash_digest.rb +18 -3
- data/lib/hash_digest/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTY4NDk1MDA3Yjc5ODZhNzI3ZmRkNjEzN2U4YjAxNzg4ZTFlNGEzMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGViMWNlNTE5NjA5M2VjMzg1YjBhM2IxNmY2N2U2ZjY1NTRhYmViZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDk2YzFjZjg3MmYwM2U0OTdkMjc5YjA3MjRiZTZiZDI0ZTYwZDYxNzVkZDdm
|
10
|
+
ZDgyOTA1YTk3ZjM5MzMzMDQ2YTU2ZTk4YmU3MTJiZjY0YzNlNGVlZjVhMDY3
|
11
|
+
ZTc5NWY4NTJlMGM2MGU5ZDY2NGVmYzMzM2I2OTk0OWZlMDg0OTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2NhYzQ4M2VmZWI0Yzg5NDg5ZDJhNTNkZGRjNTgwMmQ5NzliYzE5YmNiY2Uz
|
14
|
+
ZGQ3M2U3NWU5MGNlNDZlZmM2ODMyOWVjOTUxOWQwOTE2MjExMGViZmNjNTAw
|
15
|
+
YmY4Y2Q0M2JiNmEwMTQ1OTNiYTExOGI0YWM1ZmUwYmQ4OWQwYzM=
|
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -1,25 +1,62 @@
|
|
1
1
|
# HashDigest
|
2
2
|
|
3
|
-
Generates
|
3
|
+
Generates non-cryptographic digests of Hashes (and Arrays) indifferent to key type (string or symbol) and ordering.
|
4
4
|
|
5
|
-
|
5
|
+
Extracted from [`RemoteTable`](https://github.com/seamusabshere/remote_table).
|
6
6
|
|
7
|
-
|
7
|
+
## Note plz
|
8
|
+
|
9
|
+
1. You should use `HashDigest.digest2` for new applications. `hexdigest` is legacy.
|
10
|
+
2. `digest2`, unlike its predecessor, is CASE SENSITIVE.
|
8
11
|
|
9
12
|
## Example
|
10
13
|
|
11
14
|
### Indifferent to key type
|
12
15
|
|
13
|
-
HashDigest.
|
14
|
-
|
16
|
+
>> HashDigest.digest2(:a => 1)
|
17
|
+
=> "1s05qdo"
|
18
|
+
>> HashDigest.digest2('a' => 1)
|
19
|
+
=> "1s05qdo"
|
15
20
|
|
16
21
|
### Indifferent to key order
|
17
22
|
|
18
|
-
HashDigest.
|
19
|
-
|
23
|
+
>> HashDigest.digest2(:a => 1, 'b' => 2)
|
24
|
+
=> "fkqncr"
|
25
|
+
>> HashDigest.digest2(:b => 2, 'a' => 1)
|
26
|
+
=> "fkqncr"
|
27
|
+
|
28
|
+
## Speed
|
29
|
+
|
30
|
+
If you're **not** on JRuby, having [`EscapeUtils`](https://github.com/brianmario/escape_utils) in your `Gemfile` will make things much faster.
|
31
|
+
|
32
|
+
### With EscapeUtils (MRI, doesn't work on JRuby)
|
33
|
+
|
34
|
+
HashDigest.digest2 2492 i/100ms
|
35
|
+
HashDigest.hexdigest 2276 i/100ms
|
36
|
+
|
37
|
+
### With stdlib's CGI (JRuby)
|
38
|
+
|
39
|
+
HashDigest.digest2 645 i/100ms
|
40
|
+
HashDigest.hexdigest 213 i/100ms
|
41
|
+
|
42
|
+
### With stdlib's CGI (MRI)
|
43
|
+
|
44
|
+
HashDigest.digest2 531 i/100ms
|
45
|
+
HashDigest.hexdigest 513 i/100ms
|
20
46
|
|
21
47
|
## Algorithm
|
22
48
|
|
49
|
+
### digest2 (current)
|
50
|
+
|
51
|
+
1. Represent the hash as a URL querystring
|
52
|
+
2. Sort by key
|
53
|
+
3. [MurmurHash3](http://en.wikipedia.org/wiki/MurmurHash)
|
54
|
+
4. Convert to base 36 to save space
|
55
|
+
|
56
|
+
Note: non-cryptographic and variable length. CASE SENSITIVE.
|
57
|
+
|
58
|
+
### hexdigest (deprecated)
|
59
|
+
|
23
60
|
Basically represent the hash as a URL querystring, ordered by key, and MD5 that.
|
24
61
|
|
25
62
|
1. Stringify keys
|
@@ -31,10 +68,8 @@ To digest an array, just pretend it's a hash with keys like 1, 2, 3, etc.
|
|
31
68
|
|
32
69
|
## Potential issues
|
33
70
|
|
34
|
-
* Uses MD5 (not cryptographically awesome)
|
35
|
-
* Uses ActiveSupport's <tt>#to_query</tt> method to create a digestible string like "foo=bar&baz=bam" (slow)
|
36
71
|
* Meant for flat hashes, e.g. { :a => 1, :b => 2 } and not { :x => { :y => :z } }
|
37
72
|
|
38
73
|
## Copyright
|
39
74
|
|
40
|
-
Copyright
|
75
|
+
Copyright 2013 Seamus Abshere
|
data/Rakefile
CHANGED
data/hash_digest.gemspec
CHANGED
@@ -19,10 +19,14 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_runtime_dependency 'murmurhash3'
|
22
|
-
s.add_runtime_dependency 'escape_utils'
|
23
22
|
|
24
23
|
s.add_development_dependency 'minitest'
|
25
24
|
s.add_development_dependency 'rake'
|
26
25
|
s.add_development_dependency 'activesupport'
|
27
26
|
s.add_development_dependency 'benchmark-ips'
|
27
|
+
s.add_development_dependency 'yard'
|
28
|
+
|
29
|
+
if ENV['TEST_ESCAPE_UTILS'] == 'true'
|
30
|
+
s.add_development_dependency 'escape_utils'
|
31
|
+
end
|
28
32
|
end
|
data/lib/hash_digest.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
require 'murmurhash3'
|
3
|
-
|
3
|
+
# see below for requiring either cgi (on JRuby) or escape_utils (if available)
|
4
4
|
|
5
5
|
require "hash_digest/version"
|
6
6
|
|
@@ -38,6 +38,22 @@ module HashDigest
|
|
38
38
|
def self.hexdigest(obj)
|
39
39
|
::Digest::MD5.hexdigest as_digest1(obj)
|
40
40
|
end
|
41
|
+
|
42
|
+
# CGI escaping engine
|
43
|
+
|
44
|
+
if RUBY_PLATFORM == 'java'
|
45
|
+
require 'cgi'
|
46
|
+
def self.escape_url(str); ::CGI.escape(str) end
|
47
|
+
else
|
48
|
+
begin
|
49
|
+
# MUCH faster than stdlib's cgi
|
50
|
+
require 'escape_utils'
|
51
|
+
def self.escape_url(str); ::EscapeUtils.escape_url(str) end
|
52
|
+
rescue LoadError
|
53
|
+
require 'cgi'
|
54
|
+
def self.escape_url(str); ::CGI.escape(str) end
|
55
|
+
end
|
56
|
+
end
|
41
57
|
end
|
42
58
|
|
43
59
|
# EVERYTHING BELOW IS COPIED FROM ACTIVESUPPORT 4.0.2
|
@@ -70,7 +86,6 @@ end
|
|
70
86
|
|
71
87
|
class Object
|
72
88
|
def to_hash_digest_query(key)
|
73
|
-
|
74
|
-
"#{::EscapeUtils.escape_url(key.to_hash_digest_param)}=#{::EscapeUtils.escape_url(to_hash_digest_param)}"
|
89
|
+
"#{::HashDigest.escape_url(key.to_hash_digest_param)}=#{::HashDigest.escape_url(to_hash_digest_param)}"
|
75
90
|
end
|
76
91
|
end
|
data/lib/hash_digest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_digest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seamus Abshere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: murmurhash3
|
@@ -25,13 +25,13 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ! '>='
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: benchmark-ips
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ! '>='
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: yard
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ! '>='
|