cantor 1.2.0 → 1.2.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 +7 -0
- data/README.md +33 -28
- data/Rakefile +51 -19
- data/lib/cantor/abstract_set.rb +6 -0
- data/spec/examples/absolute_set.example +10 -0
- data/spec/spec_helper.rb +7 -0
- metadata +29 -49
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f2ab8b5af0424ab082216ef9e4ec988da7c84e93
|
4
|
+
data.tar.gz: 71333c6b2507f87e1a4b187d695310b9bc5235df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b2d169ae393cfe992e11af13090e67776e6972fddaa03be65895a0e071f64bb43a675232b9baee164b67d5d0850638eea279250b4da0ddf2ba8b521b875a43d
|
7
|
+
data.tar.gz: 966b373844833f456891db9d30598da2c556b0489fbb203cfa1251ac61b4aa6ab2767a1dfb4cb485176b0c2283b179ba76d0827feb9898cbb0e50d31a89f8685
|
data/README.md
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
# Cantor
|
1
|
+
# Cantor [](http://travis-ci.org/kputnam/cantor)
|
2
2
|
|
3
3
|
Fast implementation of finite and complement sets in Ruby
|
4
4
|
|
5
5
|
## Constructors
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
7
|
+
##### `Cantor.empty`
|
8
|
+
Finite set that contains no elements
|
9
|
+
|
10
|
+
##### `Cantor.build(enum)`
|
11
|
+
Finite set containing each element in `enum`, whose domain of discourse
|
12
|
+
is unrestricted
|
13
|
+
|
14
|
+
##### `Cantor.absolute(enum, universe)`
|
15
|
+
Finite set containing each element in `enum`, whose domain of discourse
|
16
|
+
is `universe`
|
17
|
+
|
18
|
+
##### `Cantor.universal`
|
19
|
+
Infinite set containing every value in the universe
|
20
|
+
|
21
|
+
##### `Cantor.complement(enum)`
|
22
|
+
Set containing every value except those in `enum`. Finite when `enum` is
|
23
|
+
infinite. Infinite when `enum` is finite
|
24
24
|
|
25
25
|
## Operations
|
26
26
|
|
@@ -56,13 +56,13 @@ Fast implementation of finite and complement sets in Ruby
|
|
56
56
|
## Performance
|
57
57
|
|
58
58
|
Sets with a finite domain of discourse are represented using a bit string of
|
59
|
-
2<sup
|
59
|
+
2<sup>U</sup> bits, where U is the size of the domain. This provides nearly
|
60
60
|
O(1) constant-time implementation using bitwise operations for all of the above
|
61
61
|
set operations.
|
62
62
|
|
63
63
|
The bit string is represented as an Integer, but as the domain grows larger
|
64
64
|
than `0.size * 8 - 2` items, the type is automatically expanded to a Bignum.
|
65
|
-
Bitwise operations on Bignums are O(
|
65
|
+
Bitwise operations on Bignums are O(U), which is still be significantly
|
66
66
|
faster than using the default Set library.
|
67
67
|
|
68
68
|
Sets with an unrestricted domain of discourse are implemented using a Hash.
|
@@ -75,23 +75,28 @@ These benchmarks aren't intended to be useful. While they indicate the
|
|
75
75
|
worst-case performance for Cantor, they probably don't show the worst
|
76
76
|
case for the standard Set library.
|
77
77
|
|
78
|
+
Note "Relative" indicates Cantor sets with an infinite domain of discourse.
|
79
|
+
This includes `Cantor.build`, `Cantor.universal`, and `Cantor.complement`.
|
80
|
+
"Absolute" sets are Cantor sets with a finite domain of discourse, built
|
81
|
+
from `Cantor.absolute`.
|
82
|
+
|
78
83
|
<table>
|
79
84
|
<tbody>
|
80
85
|
<tr>
|
81
|
-
<td><img title="intersection" src="/
|
82
|
-
<td><img title="difference" src="/
|
86
|
+
<td><img title="intersection" src="/benchmark/intersection.png"/></td>
|
87
|
+
<td><img title="difference" src="/benchmark/difference.png"/></td>
|
83
88
|
</tr>
|
84
89
|
<tr>
|
85
|
-
<td><img title="union" src="/
|
86
|
-
<td><img title="symmetric difference" src="/
|
90
|
+
<td><img title="union" src="/benchmark/union.png"/></td>
|
91
|
+
<td><img title="symmetric difference" src="/benchmark/sdifference.png"/></td>
|
87
92
|
</tr>
|
88
93
|
<tr>
|
89
|
-
<td><img title="subset" src="/
|
90
|
-
<td><img title="superset" src="/
|
94
|
+
<td><img title="subset" src="/benchmark/subset.png"/></td>
|
95
|
+
<td><img title="superset" src="/benchmark/superset.png"/></td>
|
91
96
|
</tr>
|
92
97
|
<tr>
|
93
|
-
<td><img title="equality" src="/
|
94
|
-
<td><img title="membership" src="/
|
98
|
+
<td><img title="equality" src="/benchmark/equality.png"/></td>
|
99
|
+
<td><img title="membership" src="/benchmark/membership.png"/></td>
|
95
100
|
</tr>
|
96
101
|
</tbody>
|
97
102
|
</table>
|
data/Rakefile
CHANGED
@@ -3,15 +3,17 @@ abspath = Pathname.new(File.dirname(__FILE__)).expand_path
|
|
3
3
|
relpath = abspath.relative_path_from(Pathname.pwd)
|
4
4
|
|
5
5
|
begin
|
6
|
-
|
7
|
-
|
6
|
+
# require "rubygems"
|
7
|
+
# require "bundler/setup"
|
8
8
|
rescue LoadError
|
9
9
|
warn "couldn't load bundler:"
|
10
10
|
warn " #{$!}"
|
11
11
|
end
|
12
12
|
|
13
|
+
task :default => :spec
|
14
|
+
|
13
15
|
task :console do
|
14
|
-
exec
|
16
|
+
exec(*%w(irb -I lib -r cantor))
|
15
17
|
end
|
16
18
|
|
17
19
|
begin
|
@@ -23,16 +25,28 @@ begin
|
|
23
25
|
t.rspec_opts = %w(--color --format p)
|
24
26
|
t.rspec_opts << "-I#{abspath}/spec"
|
25
27
|
end
|
26
|
-
rescue LoadError
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
rescue LoadError => first
|
29
|
+
begin
|
30
|
+
require "spec/rake/spectask"
|
31
|
+
Spec::Rake::SpecTask.new do |t|
|
32
|
+
t.pattern = "#{relpath}/spec/examples/**/*.example"
|
33
|
+
t.spec_opts << "--color"
|
34
|
+
t.spec_opts << "--format p"
|
35
|
+
t.libs << "#{abspath}/spec"
|
36
|
+
end
|
37
|
+
rescue LoadError => second
|
38
|
+
task :spec do
|
39
|
+
warn "couldn't load rspec version 1 or 2:"
|
40
|
+
warn " #{first}"
|
41
|
+
warn " #{second}"
|
42
|
+
exit 1
|
43
|
+
end
|
31
44
|
end
|
32
45
|
end
|
33
46
|
|
34
47
|
begin
|
35
48
|
require "rcov"
|
49
|
+
|
36
50
|
begin
|
37
51
|
require "rspec/core/rake_task"
|
38
52
|
RSpec::Core::RakeTask.new(:rcov) do |t|
|
@@ -45,19 +59,39 @@ begin
|
|
45
59
|
t.rspec_opts = %w(--color --format p)
|
46
60
|
t.rspec_opts << "-I#{abspath}/spec"
|
47
61
|
end
|
48
|
-
rescue LoadError
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
62
|
+
rescue LoadError => first
|
63
|
+
begin
|
64
|
+
require "spec/rake/spectask"
|
65
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
66
|
+
t.rcov = true
|
67
|
+
t.rcov_opts = %w(--exclude spec/,gems/)
|
68
|
+
|
69
|
+
t.pattern = "#{relpath}/spec/examples/**/*.example"
|
70
|
+
t.spec_opts << "--color"
|
71
|
+
t.spec_opts << "--format=p"
|
72
|
+
t.libs << "#{abspath}/spec"
|
73
|
+
end
|
74
|
+
rescue LoadError => second
|
75
|
+
task :rcov do
|
76
|
+
warn "couldn't load rspec version 1 or 2:"
|
77
|
+
warn " #{first}"
|
78
|
+
warn " #{second}"
|
79
|
+
exit 1
|
80
|
+
end
|
53
81
|
end
|
54
82
|
end
|
55
|
-
rescue LoadError
|
83
|
+
rescue LoadError => e
|
56
84
|
task :rcov do
|
57
85
|
warn "couldn't load rcov:"
|
58
|
-
warn " #{
|
86
|
+
warn " #{e}"
|
59
87
|
exit 1
|
60
88
|
end
|
89
|
+
end if RUBY_VERSION <= "1.9"
|
90
|
+
|
91
|
+
if RUBY_VERSION >= "1.9"
|
92
|
+
# spec/spec_helper.rb will load SimpleCov
|
93
|
+
task :rcov => :spec do
|
94
|
+
end
|
61
95
|
end
|
62
96
|
|
63
97
|
begin
|
@@ -70,12 +104,10 @@ begin
|
|
70
104
|
rm_rf "#{relpath}/doc/generated"
|
71
105
|
mkdir_p "#{relpath}/doc/generated/images"
|
72
106
|
end
|
73
|
-
rescue LoadError
|
107
|
+
rescue LoadError => e
|
74
108
|
task :yard do
|
75
109
|
warn "couldn't load yard:"
|
76
|
-
warn " #{
|
110
|
+
warn " #{e}"
|
77
111
|
exit 1
|
78
112
|
end
|
79
113
|
end
|
80
|
-
|
81
|
-
task :default => :spec
|
data/lib/cantor/abstract_set.rb
CHANGED
@@ -193,6 +193,16 @@ describe Cantor::AbsoluteSet do
|
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
|
+
describe "#present?" do
|
197
|
+
specify "∅.present? is false" do
|
198
|
+
null.should_not be_present
|
199
|
+
end
|
200
|
+
|
201
|
+
specify "{x}.present? is true" do
|
202
|
+
single.should be_present
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
196
206
|
describe "#size" do
|
197
207
|
specify "∅.size == 0" do
|
198
208
|
null.size == 0
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,13 @@ rescue LoadError
|
|
8
8
|
require "rspec"
|
9
9
|
end
|
10
10
|
|
11
|
+
begin
|
12
|
+
require "simplecov"
|
13
|
+
SimpleCov.start
|
14
|
+
rescue LoadError
|
15
|
+
warn $!
|
16
|
+
end if RUBY_VERSION >= "1.9"
|
17
|
+
|
11
18
|
# Require supporting files with custom matchers and macros
|
12
19
|
Pathname.new(File.dirname(__FILE__)).tap do |specdir|
|
13
20
|
Dir["#{specdir}/support/**/*.rb"].each do |file|
|
metadata
CHANGED
@@ -1,81 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cantor
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 1.2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.1
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Kyle Putnam
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2012-04-12 00:00:00 Z
|
11
|
+
date: 2014-08-13 00:00:00.000000000 Z
|
19
12
|
dependencies: []
|
20
|
-
|
21
13
|
description: Fast implementation of finite and complement sets in Ruby
|
22
14
|
email: putnam.kyle@gmail.com
|
23
15
|
executables: []
|
24
|
-
|
25
16
|
extensions: []
|
26
|
-
|
27
17
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
files:
|
18
|
+
files:
|
30
19
|
- README.md
|
31
20
|
- Rakefile
|
32
|
-
- lib/cantor
|
21
|
+
- lib/cantor.rb
|
33
22
|
- lib/cantor/absolute_set.rb
|
34
|
-
- lib/cantor/universal_set.rb
|
35
|
-
- lib/cantor/relative_complement.rb
|
36
23
|
- lib/cantor/abstract_set.rb
|
37
24
|
- lib/cantor/null_set.rb
|
38
|
-
- lib/cantor.rb
|
39
|
-
-
|
25
|
+
- lib/cantor/relative_complement.rb
|
26
|
+
- lib/cantor/relative_set.rb
|
27
|
+
- lib/cantor/universal_set.rb
|
28
|
+
- spec/examples/absolute_set.example
|
40
29
|
- spec/examples/null_set.example
|
41
|
-
- spec/examples/universal_set.example
|
42
30
|
- spec/examples/relative_set.example
|
43
|
-
- spec/examples/
|
31
|
+
- spec/examples/universal_set.example
|
32
|
+
- spec/spec_helper.rb
|
44
33
|
homepage: https://github.com/kputnam/cantor
|
45
34
|
licenses: []
|
46
|
-
|
35
|
+
metadata: {}
|
47
36
|
post_install_message:
|
48
37
|
rdoc_options: []
|
49
|
-
|
50
|
-
require_paths:
|
38
|
+
require_paths:
|
51
39
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
-
|
54
|
-
requirements:
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
55
42
|
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
version: "0"
|
61
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
|
-
requirements:
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
64
47
|
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
|
67
|
-
segments:
|
68
|
-
- 0
|
69
|
-
version: "0"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
70
50
|
requirements: []
|
71
|
-
|
72
51
|
rubyforge_project:
|
73
|
-
rubygems_version:
|
52
|
+
rubygems_version: 2.2.2
|
74
53
|
signing_key:
|
75
|
-
specification_version:
|
54
|
+
specification_version: 4
|
76
55
|
summary: Fast implementation of finite and complement sets in Ruby
|
77
|
-
test_files:
|
56
|
+
test_files:
|
57
|
+
- spec/examples/absolute_set.example
|
78
58
|
- spec/examples/null_set.example
|
79
|
-
- spec/examples/universal_set.example
|
80
59
|
- spec/examples/relative_set.example
|
81
|
-
- spec/examples/
|
60
|
+
- spec/examples/universal_set.example
|
61
|
+
has_rdoc: false
|