popcount 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # Object files
20
+ *.o
21
+
22
+ # Libraries
23
+ *.lib
24
+
25
+ # Shared objects (inc. Windows DLLs)
26
+ *.dll
27
+ *.so
28
+ *.bundle
29
+
30
+ # Executables
31
+ *.exe
32
+ *.out
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in popcount.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "rspec", ">= 2.10.0"
8
+ gem "simplecov", ">= 0.6.4"
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 itochan
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.
@@ -0,0 +1,29 @@
1
+ # PopCount
2
+
3
+ This is library PopCount on Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'popcount'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install popcount
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "mkmf"
2
+ create_makefile("popcount")
@@ -0,0 +1,45 @@
1
+ #include <ruby.h>
2
+
3
+ VALUE initialize_m(VALUE, VALUE);
4
+ VALUE count_m(VALUE);
5
+ VALUE count_cpu_m(VALUE);
6
+
7
+ void Init_popcount(void) {
8
+ VALUE cPopCount = rb_define_class("PopCount", rb_cObject);
9
+ rb_define_private_method(cPopCount, "initialize", initialize_m, 1);
10
+ rb_define_method(cPopCount, "count", count_m, 0);
11
+ rb_define_method(cPopCount, "count_cpu", count_cpu_m, 0);
12
+ }
13
+
14
+ VALUE initialize_m(VALUE self, VALUE value) {
15
+ rb_ivar_set(self, rb_intern("@value"), value);
16
+ }
17
+
18
+ VALUE count_m(VALUE self) {
19
+ VALUE value = rb_ivar_get(self, rb_intern("@value"));
20
+ int count = 0;
21
+ int i;
22
+ unsigned char *p;
23
+ static const char array[256] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
24
+
25
+ p = RSTRING_PTR(value);
26
+ for (i = 0; i < RSTRING_LEN(value); i++) {
27
+ count += array[*p++];
28
+ }
29
+
30
+ return INT2FIX(count);
31
+ }
32
+
33
+ VALUE count_cpu_m(VALUE self) {
34
+ VALUE value = rb_ivar_get(self, rb_intern("@value"));
35
+ int count = 0;
36
+ int i;
37
+ long long *p;
38
+
39
+ p = (long long *)RSTRING_PTR(value);
40
+ for (i = 0; i < RSTRING_LEN(value); i += sizeof(long long)) {
41
+ count += __builtin_popcountll(*p++);
42
+ }
43
+
44
+ return INT2FIX(count);
45
+ }
@@ -0,0 +1,5 @@
1
+ require "popcount/version"
2
+ require File.join(File.dirname(__FILE__), "..", "ext", "popcount")
3
+
4
+ class PopCount
5
+ end
@@ -0,0 +1,3 @@
1
+ class PopCount
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/popcount/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["itochan"]
6
+ gem.email = ["itochan315@gmail.com"]
7
+ gem.description = %q{This is library PopCount on Ruby.}
8
+ gem.summary = %q{PopCount on Ruby.}
9
+ gem.homepage = "https://github.com/itochan/popcount"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "popcount"
15
+ gem.require_paths = ["lib"]
16
+ gem.extensions = ["ext/extconf.rb"]
17
+ gem.version = PopCount::VERSION
18
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe PopCount do
4
+ it "string popcount" do
5
+ pc = PopCount.new("Ruby")
6
+ pc.count.should eq 16
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'simplecov'
5
+ require 'popcount'
6
+
7
+ # This file was generated by the `rspec --init` command. Conventionally, all
8
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
9
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
10
+ # loaded once.
11
+ #
12
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
13
+ RSpec.configure do |config|
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run :focus
17
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: popcount
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - itochan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: This is library PopCount on Ruby.
15
+ email:
16
+ - itochan315@gmail.com
17
+ executables: []
18
+ extensions:
19
+ - ext/extconf.rb
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - .rspec
24
+ - Gemfile
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - ext/extconf.rb
29
+ - ext/popcount.c
30
+ - lib/popcount.rb
31
+ - lib/popcount/version.rb
32
+ - popcount.gemspec
33
+ - spec/popcount_spec.rb
34
+ - spec/spec_helper.rb
35
+ homepage: https://github.com/itochan/popcount
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: PopCount on Ruby.
59
+ test_files:
60
+ - spec/popcount_spec.rb
61
+ - spec/spec_helper.rb