djb2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5289f212e113d7ce344f3aca42cd112ea8263807fbac52e8ded9cea07cec49ce
4
+ data.tar.gz: d573c00d36bc540125e74a90a9fd959bd7236e5c6dc149db0033a8cac76e27f7
5
+ SHA512:
6
+ metadata.gz: fa8293f3d33a9ba62c7ff2481ce4976cc9ebaa54e7eca2f1da6b0fc81cdc5e78f875c0fa127dfcae2423b3d249e3292e95e8e6ad58eb5e3f67fd8e10dd322253
7
+ data.tar.gz: 92636feeed901c10450892a144070a60eb8208492aabda8f45d0d88519bd9fcbde0a333d560fbd6c1fd9df1ec5692f6391b8a4060d92761702664e32df268a6c
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-11-24
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Shopify
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # DJB2
2
+
3
+ Native djb2 hash implementation
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add djb2
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install djb2
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ require "djb2"
19
+
20
+ DJB2.digest("Some String") # => 13838202372652591140
21
+ ```
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/djb2.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rake/extensiontask"
13
+
14
+ task build: :compile
15
+
16
+ GEMSPEC = Gem::Specification.load("djb2.gemspec")
17
+
18
+ Rake::ExtensionTask.new("djb2", GEMSPEC) do |ext|
19
+ ext.lib_dir = "lib/djb2"
20
+ end
21
+
22
+ task default: %i[clobber compile test]
data/ext/djb2/djb2.c ADDED
@@ -0,0 +1,28 @@
1
+ #include "ruby.h"
2
+
3
+ VALUE rb_mDJB2;
4
+
5
+ uint64_t
6
+ djb_hash_2(const char *string, long length)
7
+ {
8
+ uint64_t hash = 5381;
9
+ long index;
10
+ for (index = 0; index < length; index++) {
11
+ hash = (hash * 33) ^ (unsigned char)string[index];
12
+ }
13
+ return hash;
14
+ }
15
+
16
+ static VALUE
17
+ rb_djb_hash_2(VALUE self, VALUE str)
18
+ {
19
+ Check_Type(str, T_STRING);
20
+ return ULL2NUM(djb_hash_2(RSTRING_PTR(str), RSTRING_LEN(str)));
21
+ }
22
+
23
+ RUBY_FUNC_EXPORTED void
24
+ Init_djb2(void)
25
+ {
26
+ rb_mDJB2 = rb_define_module("DJB2");
27
+ rb_define_singleton_method(rb_mDJB2, "digest", rb_djb_hash_2, 1);
28
+ }
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ # Makes all symbols private by default to avoid unintended conflict
6
+ # with other gems. To explicitly export symbols you can use RUBY_FUNC_EXPORTED
7
+ # selectively, or entirely remove this flag.
8
+ append_cflags("-fvisibility=hidden")
9
+
10
+ create_makefile("djb2/djb2")
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DJB2
4
+ VERSION = "0.1.0"
5
+ end
data/lib/djb2.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "djb2/version"
4
+ require_relative "djb2/djb2"
5
+
6
+ module DJB2
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: djb2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jean Boussier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - jean.boussier@gmail.com
16
+ executables: []
17
+ extensions:
18
+ - ext/djb2/extconf.rb
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - ext/djb2/djb2.c
26
+ - ext/djb2/extconf.rb
27
+ - lib/djb2.rb
28
+ - lib/djb2/version.rb
29
+ homepage: https://github.com/Shopify/djb2
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ bug_tracker_uri: https://github.com/Shopify/djb2/issues
34
+ source_code_uri: https://github.com/Shopify/djb2
35
+ allowed_push_host: https://rubygems.org
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.6.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.4.10
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Native djb2 hash implementation
55
+ test_files: []