just_all_the_same 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: 91fe3c9dce17247fdcd6fce8de3703cfa01c9d3a3b47c24cc9a8a35f38726a72
4
+ data.tar.gz: bf27b979085faddb71da2c495103e0fc0af170b163b84950b4d5fb64ef7a1876
5
+ SHA512:
6
+ metadata.gz: 736b7c375193e3401e14e6d557ffae92e1a8f55f894da9cf36f9a8cc8e896d33964024305bbe25f63ce9373d8cdb499abcc5fb483b87bd9a18ac7a81172f6c47
7
+ data.tar.gz: 8c593d1b501c75f854850ea8e871694674b9b87450c337d5cf169970d019ea1e161a5ab027d584bacb8077e1907217850e9767d8c46dc3fa5ff22fad8eda6963
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
14
+
15
+ # rspec failure tracking
16
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in just_all_the_same.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ just_all_the_same (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rake-compiler (1.0.7)
12
+ rake
13
+ rspec (3.8.0)
14
+ rspec-core (~> 3.8.0)
15
+ rspec-expectations (~> 3.8.0)
16
+ rspec-mocks (~> 3.8.0)
17
+ rspec-core (3.8.0)
18
+ rspec-support (~> 3.8.0)
19
+ rspec-expectations (3.8.2)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-mocks (3.8.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-support (3.8.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 2.0)
32
+ just_all_the_same!
33
+ rake (~> 10.0)
34
+ rake-compiler
35
+ rspec (~> 3.0)
36
+
37
+ BUNDLED WITH
38
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 uproaddw
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,115 @@
1
+ # JustAllTheSame
2
+
3
+ ## ***YOU CAN RUN QUICKLY """Array#all?(nil)"""***
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'just_all_the_same', github: "uproad/just_all_the_same"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install specific_install
20
+ $ gem install specific_install git@github.com:uproad/just_all_the_same.git master
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'just_all_the_same'
26
+
27
+ ary = [nil, nil, nil]
28
+
29
+ ary.all_nil? #=> true
30
+ # same ary.all?(nil)
31
+ ```
32
+
33
+ ## Algorithm (gem is written by Clang)
34
+
35
+ 1. A long size array.
36
+
37
+ ```ruby
38
+ ary = [nil]*10000
39
+ ```
40
+
41
+ 2. Check first item is nil? in Clang.
42
+
43
+ ```ruby
44
+ return false unless ary[0].nil?
45
+ ```
46
+
47
+ 3. Split array to half and half.
48
+
49
+ IMPORTANT!
50
+
51
+ ```ruby
52
+ forward_ary = ary[0...ary.size/2]
53
+ backward_ary = ary[ary.size/2..ary.size/2*2] # If size is odd, to under even.
54
+ ```
55
+
56
+ 4. If odd, check last item is nil.
57
+
58
+ ```ruby
59
+ return false unless ary.size.odd? && ary[-1].nil?
60
+ ```
61
+
62
+ 5. Check same forward_ary and backward_ary with C function 'memcmp'.
63
+
64
+ IMPORTANT!!!
65
+
66
+ ```ruby
67
+ return false if memcmp(forward_ary.ptr, backward_ary.ptr, forward_ary.size)
68
+ ```
69
+
70
+ 6. Split forward_ary to half and half.
71
+
72
+ ```ruby
73
+ ary = forward_ary
74
+ forward_ary = ary[0...ary.size/2]
75
+ backward_ary = ary[ary.size/2..ary.size/2*2] # If size is odd, to under even.
76
+ ```
77
+
78
+ 7. Loop to 4
79
+
80
+ ## Algorithm written by data
81
+ ```
82
+ [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
83
+ split
84
+
85
+ [nil, nil, nil, nil, nil] [nil, nil, nil, nil, nil]
86
+ memcmp
87
+
88
+
89
+ [nil, nil, nil, nil, nil]
90
+ split
91
+
92
+ [nil, nil] [nil, nil] [nil]
93
+ memcmp nil?
94
+
95
+
96
+ [nil, nil]
97
+ split
98
+
99
+ [nil] [nil]
100
+ memcmp
101
+ ```
102
+
103
+ ## Development
104
+
105
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
106
+
107
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
108
+
109
+ ## Contributing
110
+
111
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/just_all_the_same.
112
+
113
+ ## License
114
+
115
+ 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,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "rake/extensiontask"
7
+
8
+ task :build => :compile
9
+
10
+ Rake::ExtensionTask.new("just_all_the_same") do |ext|
11
+ ext.lib_dir = "lib/just_all_the_same"
12
+ end
13
+
14
+ task :default => [:clobber, :compile, :spec]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "just_all_the_same"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile("just_all_the_same/just_all_the_same")
@@ -0,0 +1,68 @@
1
+ #include "just_all_the_same.h"
2
+
3
+ VALUE rb_mJustAllTheSame;
4
+ #define SWITCH_TO_LINER 300
5
+
6
+ static VALUE
7
+ all_same_p(VALUE ary, VALUE target)
8
+ {
9
+ long size = RARRAY_LEN(ary);
10
+
11
+ if (size == 0) return Qtrue;
12
+
13
+ VALUE *forward_p = RARRAY_PTR(ary);
14
+
15
+ if (forward_p[0] != target) return Qfalse;
16
+
17
+ VALUE *backward_p;
18
+
19
+ long s = size; // size of foward_ary + backward_aray
20
+ long v = size / 2; // splitting index
21
+
22
+ /* split algorithm */
23
+ while (v >= SWITCH_TO_LINER / 2)
24
+ {
25
+ backward_p = forward_p + v;
26
+
27
+ /* check last of array nil? if size is not odd? */
28
+ if (s%2 && forward_p[s-1] != target) return Qfalse;
29
+
30
+ /* check quick same back and fowerd */
31
+ if (memcmp(forward_p, backward_p, sizeof(VALUE) * v)) return Qfalse;
32
+
33
+ s = v;
34
+ v /= 2;
35
+ }
36
+
37
+ /* liner algorithm */
38
+ for (long i = 1; i < s; i++) if (forward_p[i] != target) return Qfalse;
39
+
40
+ return Qtrue;
41
+ }
42
+
43
+ static VALUE
44
+ all_nil_p(VALUE ary)
45
+ {
46
+ return all_same_p(ary, Qnil);
47
+ }
48
+
49
+ static VALUE
50
+ all_true_p(VALUE ary)
51
+ {
52
+ return all_same_p(ary, Qtrue);
53
+ }
54
+
55
+ static VALUE
56
+ all_false_p(VALUE ary)
57
+ {
58
+ return all_same_p(ary, Qfalse);
59
+ }
60
+
61
+ void
62
+ Init_just_all_the_same(void)
63
+ {
64
+ rb_define_method(rb_cArray, "all_nil?" , all_nil_p , 0);
65
+ rb_define_method(rb_cArray, "all_true?" , all_true_p , 0);
66
+ rb_define_method(rb_cArray, "all_false?" , all_false_p , 0);
67
+ rb_define_method(rb_cArray, "all_same?" , all_same_p , 1);
68
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef JUST_ALL_THE_SAME_H
2
+ #define JUST_ALL_THE_SAME_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* JUST_ALL_THE_SAME_H */
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "just_all_the_same/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "just_all_the_same"
8
+ spec.version = JustAllTheSame::VERSION
9
+ spec.authors = ["uproad krowd"]
10
+ spec.email = ["7349115+uproad@users.noreply.github.com"]
11
+
12
+ spec.summary = "You get Array#all?([An Immediate Value]) quickly."
13
+ spec.description = "use Allay's methods => [all_nil?, all_true?, all_false?, all_sym?(:sym), all_same?([a Fixnum])]"
14
+ spec.homepage = "https://github.com/uproad/just_all_the_same"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/uproad/just_all_the_same"
22
+ spec.metadata["changelog_uri"] = "https://github.com/uproad/just_all_the_same"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+ spec.extensions = ["ext/just_all_the_same/extconf.rb"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 2.0"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rake-compiler"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ end
@@ -0,0 +1,3 @@
1
+ module JustAllTheSame
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "just_all_the_same/version"
2
+ require "just_all_the_same/just_all_the_same"
3
+
4
+ module JustAllTheSame
5
+ # no ruby code.
6
+ # only C lang.
7
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: just_all_the_same
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - uproad krowd
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: use Allay's methods => [all_nil?, all_true?, all_false?, all_sym?(:sym),
70
+ all_same?([a Fixnum])]
71
+ email:
72
+ - 7349115+uproad@users.noreply.github.com
73
+ executables: []
74
+ extensions:
75
+ - ext/just_all_the_same/extconf.rb
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - ext/just_all_the_same/extconf.rb
88
+ - ext/just_all_the_same/just_all_the_same.c
89
+ - ext/just_all_the_same/just_all_the_same.h
90
+ - just_all_the_same.gemspec
91
+ - lib/just_all_the_same.rb
92
+ - lib/just_all_the_same/version.rb
93
+ homepage: https://github.com/uproad/just_all_the_same
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ homepage_uri: https://github.com/uproad/just_all_the_same
98
+ source_code_uri: https://github.com/uproad/just_all_the_same
99
+ changelog_uri: https://github.com/uproad/just_all_the_same
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.0.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: You get Array#all?([An Immediate Value]) quickly.
119
+ test_files: []