fast_bitset 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f257a199fff980744ceef1b86cce05184f0c5989
4
+ data.tar.gz: a29eca895c4d5230939aaa3266c630b55b605b14
5
+ SHA512:
6
+ metadata.gz: 27135de3fc4405d6fb72ce09bc73cae66ca9df436f423d497dca8aba5615cfb5b81a37db1ee9f0bf8b7e3b9540460345940c28c2d96e3dadd28c82c27f0554fd
7
+ data.tar.gz: 025cb57d7be070c63f46eef2740cc992f392643fb80e898151c69e31274fcdcb01cbf3d6ed08c8305f15c7bd926ef86d50f4717781b01617e0e6eae37ffcb419
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ *.bundle
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0
6
+ - 2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fast_bitset.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Darcy Laycock
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # FastBitset
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fast_bitset'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fast_bitset
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/fast_bitset/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/extensiontask"
3
+ require 'rspec/core/rake_task'
4
+
5
+ Rake::ExtensionTask.new("fast_bitset") do |ext|
6
+ ext.lib_dir = "lib/fast_bitset"
7
+ end
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+ task default: [:compile, :spec]
@@ -0,0 +1,2 @@
1
+ require 'mkmf'
2
+ create_makefile 'fast_bitset'
@@ -0,0 +1,45 @@
1
+ #include "ruby.h"
2
+ #include "./fast_bitset.h"
3
+
4
+ VALUE FastBitsetModule = Qnil;
5
+
6
+ VALUE rb_fast_bitset_get_ids(VALUE self, VALUE bitstring) {
7
+ VALUE ids = rb_ary_new();
8
+
9
+ Check_Type(bitstring, T_STRING);
10
+
11
+
12
+ char *ids_input = RSTRING_PTR(bitstring);
13
+ int length = RSTRING_LEN(bitstring);
14
+
15
+ int base = 0;
16
+
17
+ char current;
18
+ int i, j;
19
+
20
+ for(i = 0; i < length; i++) {
21
+ current = ids_input[i];
22
+
23
+
24
+ for(j = 0; j < 8; j++) {
25
+ char bitmask = (1<<(7-j));
26
+ if(bitmask & current) {
27
+ rb_ary_push(ids, INT2NUM(base + j));
28
+ }
29
+ }
30
+
31
+ base += 8;
32
+ }
33
+
34
+ return ids;
35
+ }
36
+
37
+ void rb_init_fast_bitset() {
38
+ rb_define_module_function(FastBitsetModule, "native_bitstring_to_ids", rb_fast_bitset_get_ids, 1);
39
+ }
40
+
41
+ void Init_fast_bitset()
42
+ {
43
+ FastBitsetModule = rb_define_module("FastBitset");
44
+ rb_init_fast_bitset();
45
+ }
@@ -0,0 +1,5 @@
1
+ #include "ruby.h"
2
+
3
+ void rb_init_fast_bitset();
4
+
5
+ VALUE rb_fast_bitset_get_ids(VALUE self, VALUE bitstring);
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fast_bitset/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fast_bitset"
8
+ spec.version = FastBitset::VERSION
9
+ spec.authors = ["Darcy Laycock", "Matt Delves", "Matt Allen"]
10
+ spec.email = ["sutto@sutto.net"]
11
+ spec.summary = %q{Fast Bit String to Ruby Arrays of IDs, using C for magical speediness. Perfect for use with Redis Bit sets}
12
+ spec.homepage = "https://github.com/Sutto/fast_bitset"
13
+ spec.license = "MIT"
14
+
15
+ spec.platform = Gem::Platform::RUBY
16
+ spec.extensions = Dir["ext/**/extconf.rb"]
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+
26
+ spec.add_development_dependency "rake-compiler"
27
+ spec.add_development_dependency "rspec", "~> 2.0"
28
+ end
@@ -0,0 +1,3 @@
1
+ module FastBitset
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ require "fast_bitset/version"
2
+
3
+ module FastBitset
4
+
5
+ def self.pure_bitstring_to_ids(value)
6
+ unless value.is_a?(String)
7
+ raise TypeError.new("wrong argument type #{value.class} (expected String)")
8
+ end
9
+ offset = 0
10
+ ids = []
11
+ return ids if value.nil?
12
+ value.each_byte do |byte|
13
+ 7.downto(0) do |i|
14
+ value = (1<<i)
15
+ ids << offset if (value & byte) == value
16
+ offset += 1
17
+ end
18
+ end
19
+ ids
20
+ end
21
+
22
+ begin
23
+ # Load the native version.
24
+ require 'fast_bitset/fast_bitset'
25
+ class << self
26
+ alias bitstring_to_ids native_bitstring_to_ids
27
+ end
28
+ rescue LoadError
29
+ alias bitstring_to_ids pure_bitstring_to_ids
30
+ end
31
+
32
+ end
@@ -0,0 +1,51 @@
1
+ require 'rspec'
2
+ require 'fast_bitset'
3
+
4
+ describe FastBitset do
5
+
6
+ shared_examples_for 'a bit set implementation' do
7
+
8
+ it 'raises an error with a non string' do
9
+ expect { convert(0) }.to raise_error TypeError
10
+ expect { convert(nil) }.to raise_error TypeError
11
+ end
12
+
13
+ it 'works with empty strings' do
14
+ expect(convert("")).to eq []
15
+ end
16
+
17
+ it 'works with trivial cases' do
18
+ expect(convert(0b11111111.chr)).to eq [0, 1, 2, 3, 4, 5, 6, 7]
19
+ expect(convert(0b00000000.chr)).to eq []
20
+ expect(convert(0b11111110.chr)).to eq [0, 1, 2, 3, 4, 5, 6]
21
+ expect(convert(0b11100000.chr)).to eq [0, 1, 2]
22
+ expect(convert(0b10000001.chr)).to eq [0, 7]
23
+ expect(convert(0b01011011.chr)).to eq [1, 3, 4, 6, 7]
24
+ end
25
+
26
+ it 'works with complex cases' do
27
+ expect(convert("\x0F\x0F")).to eq [4, 5, 6, 7, 12, 13, 14, 15]
28
+ expect(convert("\x00\x00")).to eq []
29
+ expect(convert("\x00\x0F")).to eq (12..15).to_a
30
+ expect(convert("\x00\x01")).to eq [15]
31
+ expect(convert("\xFF\xFF")).to eq (0..15).to_a
32
+ end
33
+
34
+ it 'works with amusing emoji' do
35
+ # Test Data courtesy @mattallen
36
+ expect(convert("💩")).to eq [0, 1, 2, 3, 8, 11, 12, 13, 14, 15, 16, 19, 22, 24, 26, 28, 31]
37
+ end
38
+
39
+ end
40
+
41
+ describe '.native_bitstring_to_ids' do
42
+ def convert(value); FastBitset.native_bitstring_to_ids(value); end
43
+ it_behaves_like 'a bit set implementation'
44
+ end
45
+
46
+ describe '.pure_bitstring_to_ids' do
47
+ def convert(value); FastBitset.pure_bitstring_to_ids(value); end
48
+ it_behaves_like 'a bit set implementation'
49
+ end
50
+
51
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fast_bitset
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Darcy Laycock
8
+ - Matt Delves
9
+ - Matt Allen
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-03-15 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.5'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake-compiler
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '2.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '2.0'
71
+ description:
72
+ email:
73
+ - sutto@sutto.net
74
+ executables: []
75
+ extensions:
76
+ - ext/fast_bitset/extconf.rb
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - ext/fast_bitset/extconf.rb
86
+ - ext/fast_bitset/fast_bitset.c
87
+ - ext/fast_bitset/fast_bitset.h
88
+ - fast_bitset.gemspec
89
+ - lib/fast_bitset.rb
90
+ - lib/fast_bitset/version.rb
91
+ - spec/fast_bitset_spec.rb
92
+ homepage: https://github.com/Sutto/fast_bitset
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Fast Bit String to Ruby Arrays of IDs, using C for magical speediness. Perfect
116
+ for use with Redis Bit sets
117
+ test_files:
118
+ - spec/fast_bitset_spec.rb