hashfunctions 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,45 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # aptana
18
+ .project
19
+
20
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
21
+ #
22
+ # * Create a file at ~/.gitignore
23
+ # * Include files you want ignored
24
+ # * Run: git config --global core.excludesfile ~/.gitignore
25
+ #
26
+ # After doing this, these files will be ignored in all your git projects,
27
+ # saving you from having to 'pollute' every project you touch with them
28
+ #
29
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
30
+ #
31
+ # For MacOS:
32
+ #
33
+ #.DS_Store
34
+ #
35
+ # For TextMate
36
+ #*.tmproj
37
+ #tmtags
38
+ #
39
+ # For emacs:
40
+ #*~
41
+ #\#*
42
+ #.\#*
43
+ #
44
+ # For vim:
45
+ #*.swp
data/LICENSE.txt ADDED
@@ -0,0 +1,234 @@
1
+ THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON
2
+ PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION
3
+ OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4
+
5
+ 1. DEFINITIONS
6
+
7
+ "Contribution" means:
8
+
9
+ a) in the case of the initial Contributor, the initial code and
10
+ documentation distributed under this Agreement, and
11
+
12
+ b) in the case of each subsequent Contributor:
13
+
14
+ i) changes to the Program, and
15
+
16
+ ii) additions to the Program;
17
+
18
+ where such changes and/or additions to the Program originate from
19
+ and are distributed by that particular Contributor. A Contribution
20
+ 'originates' from a Contributor if it was added to the Program by
21
+ such Contributor itself or anyone acting on such Contributor's
22
+ behalf. Contributions do not include additions to the Program which:
23
+ (i) are separate modules of software distributed in conjunction with
24
+ the Program under their own license agreement, and (ii) are not
25
+ derivative works of the Program.
26
+
27
+ "Contributor" means any person or entity that distributes the Program.
28
+
29
+ "Licensed Patents " mean patent claims licensable by a Contributor
30
+ which are necessarily infringed by the use or sale of its
31
+ Contribution alone or when combined with the Program.
32
+
33
+ "Program" means the Contributions distributed in accordance with
34
+ this Agreement.
35
+
36
+ "Recipient" means anyone who receives the Program under this
37
+ Agreement, including all Contributors.
38
+
39
+ 2. GRANT OF RIGHTS
40
+
41
+ a) Subject to the terms of this Agreement, each Contributor hereby
42
+ grants Recipient a non-exclusive, worldwide, royalty-free copyright
43
+ license to reproduce, prepare derivative works of, publicly display,
44
+ publicly perform, distribute and sublicense the Contribution of such
45
+ Contributor, if any, and such derivative works, in source code and
46
+ object code form.
47
+
48
+ b) Subject to the terms of this Agreement, each Contributor hereby
49
+ grants Recipient a non-exclusive, worldwide, royalty-free patent
50
+ license under Licensed Patents to make, use, sell, offer to sell,
51
+ import and otherwise transfer the Contribution of such Contributor,
52
+ if any, in source code and object code form. This patent license
53
+ shall apply to the combination of the Contribution and the Program
54
+ if, at the time the Contribution is added by the Contributor, such
55
+ addition of the Contribution causes such combination to be covered
56
+ by the Licensed Patents. The patent license shall not apply to any
57
+ other combinations which include the Contribution. No hardware per
58
+ se is licensed hereunder.
59
+
60
+ c) Recipient understands that although each Contributor grants the
61
+ licenses to its Contributions set forth herein, no assurances are
62
+ provided by any Contributor that the Program does not infringe the
63
+ patent or other intellectual property rights of any other entity.
64
+ Each Contributor disclaims any liability to Recipient for claims
65
+ brought by any other entity based on infringement of intellectual
66
+ property rights or otherwise. As a condition to exercising the
67
+ rights and licenses granted hereunder, each Recipient hereby assumes
68
+ sole responsibility to secure any other intellectual property rights
69
+ needed, if any. For example, if a third party patent license is
70
+ required to allow Recipient to distribute the Program, it is
71
+ Recipient's responsibility to acquire that license before
72
+ distributing the Program.
73
+
74
+ d) Each Contributor represents that to its knowledge it has
75
+ sufficient copyright rights in its Contribution, if any, to grant
76
+ the copyright license set forth in this Agreement.
77
+
78
+ 3. REQUIREMENTS
79
+
80
+ A Contributor may choose to distribute the Program in object code
81
+ form under its own license agreement, provided that:
82
+
83
+ a) it complies with the terms and conditions of this Agreement; and
84
+
85
+ b) its license agreement:
86
+
87
+ i) effectively disclaims on behalf of all Contributors all
88
+ warranties and conditions, express and implied, including warranties
89
+ or conditions of title and non-infringement, and implied warranties
90
+ or conditions of merchantability and fitness for a particular purpose;
91
+
92
+ ii) effectively excludes on behalf of all Contributors all liability
93
+ for damages, including direct, indirect, special, incidental and
94
+ consequential damages, such as lost profits;
95
+
96
+ iii) states that any provisions which differ from this Agreement are
97
+ offered by that Contributor alone and not by any other party; and
98
+
99
+ iv) states that source code for the Program is available from such
100
+ Contributor, and informs licensees how to obtain it in a reasonable
101
+ manner on or through a medium customarily used for software exchange.
102
+
103
+ When the Program is made available in source code form:
104
+
105
+ a) it must be made available under this Agreement; and
106
+
107
+ b) a copy of this Agreement must be included with each copy of the
108
+ Program.
109
+
110
+ Contributors may not remove or alter any copyright notices contained
111
+ within the Program.
112
+
113
+ Each Contributor must identify itself as the originator of its
114
+ Contribution, if any, in a manner that reasonably allows subsequent
115
+ Recipients to identify the originator of the Contribution.
116
+
117
+ 4. COMMERCIAL DISTRIBUTION
118
+
119
+ Commercial distributors of software may accept certain
120
+ responsibilities with respect to end users, business partners and
121
+ the like. While this license is intended to facilitate the
122
+ commercial use of the Program, the Contributor who includes the
123
+ Program in a commercial product offering should do so in a manner
124
+ which does not create potential liability for other Contributors.
125
+ Therefore, if a Contributor includes the Program in a commercial
126
+ product offering, such Contributor ("Commercial Contributor") hereby
127
+ agrees to defend and indemnify every other Contributor ("Indemnified
128
+ Contributor") against any losses, damages and costs (collectively
129
+ "Losses") arising from claims, lawsuits and other legal actions
130
+ brought by a third party against the Indemnified Contributor to the
131
+ extent caused by the acts or omissions of such Commercial
132
+ Contributor in connection with its distribution of the Program in a
133
+ commercial product offering. The obligations in this section do not
134
+ apply to any claims or Losses relating to any actual or alleged
135
+ intellectual property infringement. In order to qualify, an
136
+ Indemnified Contributor must: a) promptly notify the Commercial
137
+ Contributor in writing of such claim, and b) allow the Commercial
138
+ Contributor to control, and cooperate with the Commercial
139
+ Contributor in, the defense and any related settlement negotiations.
140
+ The Indemnified Contributor may participate in any such claim at its
141
+ own expense.
142
+
143
+ For example, a Contributor might include the Program in a commercial
144
+ product offering, Product X. That Contributor is then a Commercial
145
+ Contributor. If that Commercial Contributor then makes performance
146
+ claims, or offers warranties related to Product X, those performance
147
+ claims and warranties are such Commercial Contributor's
148
+ responsibility alone. Under this section, the Commercial Contributor
149
+ would have to defend claims against the other Contributors related
150
+ to those performance claims and warranties, and if a court requires
151
+ any other Contributor to pay any damages as a result, the Commercial
152
+ Contributor must pay those damages.
153
+
154
+ 5. NO WARRANTY
155
+
156
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
157
+ PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
158
+ ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
159
+ ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
160
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient
161
+ is solely responsible for determining the appropriateness of using
162
+ and distributing the Program and assumes all risks associated with
163
+ its exercise of rights under this Agreement, including but not
164
+ limited to the risks and costs of program errors, compliance with
165
+ applicable laws, damage to or loss of data, programs or equipment,
166
+ and unavailability or interruption of operations.
167
+
168
+ 6. DISCLAIMER OF LIABILITY
169
+
170
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
171
+ NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT,
172
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
173
+ (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON
174
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
175
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
176
+ THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS
177
+ GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
178
+
179
+ 7. GENERAL
180
+
181
+ If any provision of this Agreement is invalid or unenforceable under
182
+ applicable law, it shall not affect the validity or enforceability
183
+ of the remainder of the terms of this Agreement, and without further
184
+ action by the parties hereto, such provision shall be reformed to
185
+ the minimum extent necessary to make such provision valid and
186
+ enforceable.
187
+
188
+ If Recipient institutes patent litigation against a Contributor with
189
+ respect to a patent applicable to software (including a cross-claim
190
+ or counterclaim in a lawsuit), then any patent licenses granted by
191
+ that Contributor to such Recipient under this Agreement shall
192
+ terminate as of the date such litigation is filed. In addition, if
193
+ Recipient institutes patent litigation against any entity (including
194
+ a cross-claim or counterclaim in a lawsuit) alleging that the
195
+ Program itself (excluding combinations of the Program with other
196
+ software or hardware) infringes such Recipient's patent(s), then
197
+ such Recipient's rights granted under Section 2(b) shall terminate
198
+ as of the date such litigation is filed.
199
+
200
+ All Recipient's rights under this Agreement shall terminate if it
201
+ fails to comply with any of the material terms or conditions of this
202
+ Agreement and does not cure such failure in a reasonable period of
203
+ time after becoming aware of such noncompliance. If all Recipient's
204
+ rights under this Agreement terminate, Recipient agrees to cease use
205
+ and distribution of the Program as soon as reasonably practicable.
206
+ However, Recipient's obligations under this Agreement and any
207
+ licenses granted by Recipient relating to the Program shall continue
208
+ and survive.
209
+
210
+ Everyone is permitted to copy and distribute copies of this
211
+ Agreement, but in order to avoid inconsistency the Agreement is
212
+ copyrighted and may only be modified in the following manner. The
213
+ Agreement Steward reserves the right to publish new versions
214
+ (including revisions) of this Agreement from time to time. No one
215
+ other than the Agreement Steward has the right to modify this
216
+ Agreement. IBM is the initial Agreement Steward. IBM may assign the
217
+ responsibility to serve as the Agreement Steward to a suitable
218
+ separate entity. Each new version of the Agreement will be given a
219
+ distinguishing version number. The Program (including Contributions)
220
+ may always be distributed subject to the version of the Agreement
221
+ under which it was received. In addition, after a new version of the
222
+ Agreement is published, Contributor may elect to distribute the
223
+ Program (including its Contributions) under the new version. Except
224
+ as expressly stated in Sections 2(a) and 2(b) above, Recipient
225
+ receives no rights or licenses to the intellectual property of any
226
+ Contributor under this Agreement, whether expressly, by implication,
227
+ estoppel or otherwise. All rights in the Program not expressly
228
+ granted under this Agreement are reserved.
229
+
230
+ This Agreement is governed by the laws of the State of New York and
231
+ the intellectual property laws of the United States of America. No
232
+ party to this Agreement will bring a legal action under this
233
+ Agreement more than one year after the cause of action arose. Each
234
+ party waives its rights to a jury trial in any resulting litigation.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ General Purpose Hash Functions Gem
2
+ ==================================
3
+
4
+ **hashfunctions** is a [Ruby][1] gem which implements
5
+ 11 fast hash functions for general purpose non-cryptographic use
6
+ implemented originally by [Arash Partow][2]. Part of this library is
7
+ the native C [**hashfunctions-extension**][3] extension which is used
8
+ if it's installed as gem.
9
+
10
+ Some example:
11
+
12
+ require "general-hash-functions"
13
+ hash = GeneralHashFunctions::djbhash("some string")
14
+ # will return the 395673328
15
+
16
+ See description of all contained functions at Arash Partow's page:
17
+ http://www.partow.net/programming/hashfunctions/index.html#AvailableHashFunctions
18
+
19
+
20
+ Copyright
21
+ ---------
22
+
23
+ Copyright © 2002 [Arash Partow][2]. Copyright © 2012
24
+ [Martin Kozák][4]. See `LICENSE.txt` for further details.
25
+
26
+ [1]: http://www.ruby-lang.org/en/
27
+ [2]: http://www.partow.net/
28
+ [3]: http://github.com/martinkozak/hashfunctions-extension
29
+ [4]: http://www.martinkozak.net/
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rake/extensiontask'
5
+
6
+ spec = Gem::Specification.new do |s|
7
+ s.name = "hashfunctions"
8
+ s.email = "martinkozak@martinkozak.net"
9
+ s.author = "Martin Kozák"
10
+ s.platform = Gem::Platform::RUBY
11
+ s.summary = "11 fast hash functions for general purpose non-cryptographic use."
12
+ s.description = "11 fast hash functions for general purpose non-cryptographic use implemented originally by Arash Partow. Uses the C extension if appropriate gem is available."
13
+ s.homepage = "http://github.com/martinkozak/hashfunctions"
14
+ s.license = "CPL"
15
+ s.version = "1.0.0"
16
+ s.files = `git ls-files`.split("\n")
17
+ s.add_development_dependency("rake", ">= 0")
18
+ s.add_development_dependency("rake-compiler", ">= 0")
19
+ end
20
+
21
+ Gem::PackageTask.new(spec) do |pkg|
22
+ end
@@ -0,0 +1,127 @@
1
+ #
2
+ #**************************************************************************
3
+ #* *
4
+ #* General Purpose Hash Function Algorithms Library *
5
+ #* *
6
+ #* Author: Arash Partow - 2002 *
7
+ #* URL: http://www.partow.net *
8
+ #* URL: http://www.partow.net/programming/hashfunctions/index.html *
9
+ #* *
10
+ #* Copyright notice: *
11
+ #* Free use of the General Purpose Hash Function Algorithms Library is *
12
+ #* permitted under the guidelines and in accordance with the most current *
13
+ #* version of the Common Public License. *
14
+ #* http://www.opensource.org/licenses/cpl1.0.php *
15
+ #* *
16
+ #**************************************************************************
17
+ #
18
+
19
+ module GeneralHashFunctionsPure
20
+
21
+ def self.rshash( str )
22
+ a = 63689
23
+ b = 378551
24
+ hash = 0
25
+ str.each_byte{ |i|
26
+ hash = (hash * a + i) & 0xffffffff
27
+ a = (a * b) & 0xffffffff
28
+ }
29
+ return hash
30
+ end
31
+
32
+
33
+ def self.jshash( str )
34
+ hash = 1315423911
35
+ str.each_byte{ |i|
36
+ hash ^= ( ( hash << 5 ) + i + ( hash >> 2 ) ) & 0xffffffff
37
+ }
38
+ return hash
39
+ end
40
+
41
+
42
+ def self.elfhash( str )
43
+ hash = 0
44
+ x = 0
45
+ str.each_byte{ |i|
46
+ hash = (hash << 4) + i
47
+ if (x = hash & 0xF0000000) != 0
48
+ hash ^= (x >> 24)
49
+ hash &= ~x
50
+ end
51
+ hash &= 0xffffffff
52
+ }
53
+ return hash
54
+ end
55
+
56
+
57
+ def self.bkdrhash( str )
58
+ seed = 131 # 31 131 1313 13131 131313 etc..
59
+ hash = 0
60
+ str.each_byte{ |i|
61
+ hash = (( hash * seed ) + i) & 0xffffffff
62
+ }
63
+ return hash
64
+ end
65
+
66
+
67
+ def self.sdbmhash( str )
68
+ hash = 0
69
+ str.each_byte{ |i|
70
+ hash = (i + ( hash << 6 ) + ( hash << 16 ) - hash) & 0xffffffff
71
+ }
72
+ return hash
73
+ end
74
+
75
+
76
+ def self.djbhash( str )
77
+ hash = 5381
78
+ str.each_byte{ |i|
79
+ hash = (((hash << 5) + hash) + i) & 0xffffffff
80
+ }
81
+ return hash
82
+ end
83
+
84
+
85
+ def self.dekhash( str )
86
+ hash = str.length
87
+ str.each_byte{ |i|
88
+ hash = (((hash << 5) ^ (hash >> 27)) ^ i) & 0xffffffff
89
+ }
90
+ return hash
91
+ end
92
+
93
+
94
+ def self.bphash( str )
95
+ hash = 0
96
+ str.each_byte{ |i|
97
+ hash = (hash << 7 ^ i) & 0xffffffff
98
+ }
99
+ return hash
100
+ end
101
+
102
+
103
+ def self.fnvhash( str )
104
+ fnv_prime = 0x811C9DC5
105
+ hash = 0
106
+ str.each_byte{ |i|
107
+ hash *= fnv_prime
108
+ hash ^= i
109
+ hash &= 0xffffffff
110
+ }
111
+ return hash
112
+ end
113
+
114
+
115
+ def self.aphash( str )
116
+ raise NotImplementedError::new("Arash Partow's hash is provided by C extension only.")
117
+ end
118
+
119
+ end
120
+
121
+
122
+ begin
123
+ require "general-hash-functions/extension"
124
+ GeneralHashFunctions = GeneralHashFunctionsExt
125
+ rescue LoadError
126
+ GeneralHashFunctions = GeneralHashFunctionsPure
127
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hashfunctions
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Martin Kozák
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &9094440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *9094440
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake-compiler
27
+ requirement: &9091240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *9091240
36
+ description: 11 fast hash functions for general purpose non-cryptographic use implemented
37
+ originally by Arash Partow. Uses the C extension if appropriate gem is available.
38
+ email: martinkozak@martinkozak.net
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - LICENSE.txt
45
+ - README.md
46
+ - Rakefile
47
+ - lib/general-hash-functions.rb
48
+ homepage: http://github.com/martinkozak/hashfunctions
49
+ licenses:
50
+ - CPL
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.15
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: 11 fast hash functions for general purpose non-cryptographic use.
73
+ test_files: []