fibc 0.1.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
+ SHA256:
3
+ metadata.gz: 4874726b6222563964757300ed36049fed8f3df9768fd99ddc70b1353ca3f78c
4
+ data.tar.gz: 6f6d1322f52c7a11d67dc19f2403ec5e8c08aaac4677b3ba34e6fe80755a1934
5
+ SHA512:
6
+ metadata.gz: 62e94f5b6ccbce09ade50db890c85b7cbfcc98ff8afc6cf92840bb896e2f8b3dbdc50811e5a59a71c04393fa1872557c9fca6fa04970751b8823c3de0b40d8dc
7
+ data.tar.gz: 14da9340d0f2b5fdf67424f4436e9af70b5b49a23b18aa76c2e5351abb62d17fa1ca326e36dae0287019767e490a356555747238b7981177bd6fc389e2667e20
data/.gitignore ADDED
@@ -0,0 +1,14 @@
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
+ fibc.sublime-workspace
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in fibc.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rake-compiler"
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fibc (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (13.0.3)
10
+ rake-compiler (1.1.1)
11
+ rake
12
+
13
+ PLATFORMS
14
+ x86_64-darwin-19
15
+
16
+ DEPENDENCIES
17
+ fibc!
18
+ rake (~> 13.0)
19
+ rake-compiler
20
+
21
+ BUNDLED WITH
22
+ 2.2.13
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Fibc
2
+
3
+ Returns the n-th integer value in the Fibonacci Sequence, see discuss at [ruby-china](https://ruby-china.org/topics/40862).
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'fibc'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install fibc
21
+
22
+ ## Usage
23
+
24
+ Run the irb
25
+
26
+ ```ruby
27
+ require 'fibc'
28
+ measure
29
+ Fibc.fib_pure(4) # processing time: 0.000034s
30
+ Fibc.fib(4) # processing time: 0.000030s
31
+ Fibc.fib_pure(40) # processing time: 15.568888s
32
+ Fibc.fib(40) # processing time: 0.511246s
33
+ ```
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ 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).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Eric-Guo/fibc.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/extensiontask"
5
+
6
+ task build: :compile
7
+
8
+ Rake::ExtensionTask.new("fibc") do |ext|
9
+ ext.lib_dir = "lib/fibc"
10
+ end
11
+
12
+ task default: %i[clobber compile]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "fibc"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ create_makefile("fibc/fibc")
data/ext/fibc/fibc.c ADDED
@@ -0,0 +1,27 @@
1
+ #include "fibc.h"
2
+
3
+ VALUE rb_mFibc;
4
+
5
+ long fibc(long n) {
6
+ if (n == 0 || n == 1)
7
+ return n;
8
+
9
+ return fibc(n-1) + fibc(n-2);
10
+ }
11
+
12
+ VALUE rb_fibc(VALUE self, VALUE r_num) {
13
+ Check_Type(r_num, T_FIXNUM);
14
+
15
+ long num = FIX2LONG(r_num);
16
+
17
+ long res = fibc(num);
18
+
19
+ return LONG2FIX(res);
20
+ }
21
+
22
+ void Init_fibc(void)
23
+ {
24
+ rb_mFibc = rb_define_module("Fibc");
25
+
26
+ rb_define_singleton_method(rb_mFibc, "fib", rb_fibc, 1);
27
+ }
data/ext/fibc/fibc.h ADDED
@@ -0,0 +1,6 @@
1
+ #ifndef FIBC_H
2
+ #define FIBC_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* FIBC_H */
data/fibc.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/fibc/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fibc"
7
+ spec.version = Fibc::VERSION
8
+ spec.authors = ["Eric-Guo"]
9
+ spec.email = ["eric.guocz@gmail.com"]
10
+
11
+ spec.summary = "Returns the n-th integer value in the Fibonacci Sequence."
12
+ spec.description = "Returns the n-th integer value in the Fibonacci Sequence."
13
+ spec.homepage = "https://github.com/Eric-Guo/fibc.git"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/Eric-Guo/fibc"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ spec.extensions = ["ext/fibc/extconf.rb"]
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ # spec.add_dependency "example-gem", "~> 1.0"
31
+
32
+ # For more information and examples about making a new gem, checkout our
33
+ # guide at: https://bundler.io/guides/creating_gem.html
34
+ end
@@ -0,0 +1,16 @@
1
+ {
2
+ "folders":
3
+ [
4
+ {
5
+ "path": ".",
6
+ "folder_exclude_patterns": [".bundle","log","tmp"],
7
+ "file_exclude_patterns": ["*.sublime-workspace",".byebug_history",".DS_Store"]
8
+ }
9
+ ],
10
+ "settings":
11
+ {
12
+ "translate_tabs_to_spaces": true,
13
+ "trim_trailing_white_space_on_save": true,
14
+ "tab_size": 2
15
+ }
16
+ }
data/lib/fibc.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "fibc/version"
4
+ require_relative "fibc/fibc"
5
+
6
+ module Fibc
7
+ def self.fib_pure(n)
8
+ return n if n == 0 || n == 1
9
+ fib_pure(n-1) + fib_pure(n-2)
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fibc
4
+ VERSION = "0.1.1"
5
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fibc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric-Guo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Returns the n-th integer value in the Fibonacci Sequence.
14
+ email:
15
+ - eric.guocz@gmail.com
16
+ executables: []
17
+ extensions:
18
+ - ext/fibc/extconf.rb
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - ext/fibc/extconf.rb
29
+ - ext/fibc/fibc.c
30
+ - ext/fibc/fibc.h
31
+ - fibc.gemspec
32
+ - fibc.sublime-project
33
+ - lib/fibc.rb
34
+ - lib/fibc/version.rb
35
+ homepage: https://github.com/Eric-Guo/fibc.git
36
+ licenses: []
37
+ metadata:
38
+ homepage_uri: https://github.com/Eric-Guo/fibc.git
39
+ source_code_uri: https://github.com/Eric-Guo/fibc
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.6.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.2.13
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Returns the n-th integer value in the Fibonacci Sequence.
59
+ test_files: []