prime_miller_rabin 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a088800b7a87805ac6556b7252b6e32d426bf4b0
4
- data.tar.gz: 68f614d2830b4874ba6d01b6d8084f0ec9c5e9f7
3
+ metadata.gz: 3e71f504ac581df53a4de144d38753737de8ee32
4
+ data.tar.gz: 8a0341da7bfc0d88b5c37f51cb5bac7d2db7989b
5
5
  SHA512:
6
- metadata.gz: 94a350177a2c3eac2912fb77dd331c9db6f340d4d93eb5d0f728dfd272e1cdfd7b65f28427b9e201749cf7d2bbf71fa017ca3b78c4d767fdafc068d583c0a018
7
- data.tar.gz: 1f497645dc17fb3e1651dc99c09ee1f417c421ad56a81e9be6795688fbfdcad746cff22512a873cf0fd127ae8c9ea20427cc009594481b0d68ffc02f3d04e83b
6
+ metadata.gz: e819edba359c4e40db5e8277430a5ee4ebc1f68b59690bdd98ad89f55813f7ddfaeef2a3c12d5fdcf7608b65ac15d1186ade0df8823dca76bbce3b7a8e1aea14
7
+ data.tar.gz: 01754969f833ebf1dac2cc3935551f7536b26997141ae028c0021fe318baaecf79161474d91dbcbcea220ae55d79482ee129abe9c678895a7e337490badeeb5e
@@ -1,15 +1,57 @@
1
+ require 'backports' if RUBY_VERSION < '1.9'
1
2
  require 'prime'
2
3
  require "prime_miller_rabin/version"
3
4
 
4
5
  class Prime::MillerRabin < Prime::PseudoPrimeGenerator
5
6
 
6
7
  def self.speed_intercept
7
- Prime.send(:prepend, Prime::MillerRabin::PrimeIntercept)
8
+ if RUBY_VERSION >= "2.0"
9
+ Prime.send(:prepend, Prime::MillerRabin::PrimeIntercept)
10
+ else
11
+ Prime.class_eval <<-INTERCEPT_EVAL, __FILE__, __LINE__ + 1
12
+ def prime_with_intercept?(value, *args)
13
+ args.first.instance_of?(Prime::MillerRabin) ? args.first.prime?(value) : prime_without_intercept?(value, *args)
14
+ end
15
+
16
+ alias_method "prime_without_intercept?", "prime?"
17
+ alias_method "prime?", "prime_with_intercept?"
18
+ INTERCEPT_EVAL
19
+ end
8
20
  end
9
21
 
10
22
  def self.make_default
11
- Prime.send(:prepend, Prime::MillerRabin::Default::Prime, Prime::MillerRabin::PrimeIntercept)
12
- Integer.send(:prepend, Prime::MillerRabin::Default::Integer)
23
+ if RUBY_VERSION >= "2.0"
24
+ Prime.send(:prepend, Prime::MillerRabin::Default::Prime, Prime::MillerRabin::PrimeIntercept)
25
+ Integer.send(:prepend, Prime::MillerRabin::Default::Integer)
26
+ else
27
+ Prime.class_eval <<-PRIME_DEFAULT_EVAL, __FILE__, __LINE__ + 1
28
+ # Change the default generator used to be MillerRabin
29
+ def prime_with_mr_default?(value, generator = ::Prime::MillerRabin.new)
30
+ generator.instance_of?(Prime::MillerRabin) ? generator.prime?(value) : prime_without_mr_default?(value, generator)
31
+ end
32
+
33
+ def prime_division_with_mr_default?(value, generator = ::Prime::MillerRabin.new)
34
+ prime_division_without_mr_default?(value, generator)
35
+ end
36
+
37
+ alias_method "prime_without_mr_default?", "prime?"
38
+ alias_method "prime?", "prime_with_mr_default?"
39
+
40
+ alias_method "prime_division_without_mr_default?", "prime_division"
41
+ alias_method "prime_division", "prime_division_with_mr_default?"
42
+ PRIME_DEFAULT_EVAL
43
+
44
+ Integer.class_eval <<-INTEGER_DEFAULT_EVAL, __FILE__, __LINE__ + 1
45
+
46
+ def prime_division_with_mr_default(generator = ::Prime::MillerRabin.new)
47
+ prime_division_without_mr_default(generator)
48
+ end
49
+
50
+ alias_method "prime_division_with_mr_default?", "prime_division"
51
+ alias_method "prime_division", "prime_division_with_mr_default?"
52
+ INTEGER_DEFAULT_EVAL
53
+
54
+ end
13
55
  end
14
56
 
15
57
  def succ()
@@ -1,5 +1,6 @@
1
+ require 'backports' if RUBY_VERSION < '1.9'
1
2
  require 'prime'
2
3
 
3
4
  class Prime::MillerRabin < Prime::PseudoPrimeGenerator
4
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
5
6
  end
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "backports" # Wish this could be conditional. It is only used for ruby 1.8 for as long as I support it.
21
22
  spec.add_development_dependency "bundler", "~> 1.3"
22
23
  spec.add_development_dependency "rake"
23
24
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prime_miller_rabin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Hall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-04 00:00:00.000000000 Z
11
+ date: 2013-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: backports
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement