cartesian 0.6.0 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +13 -35
- data/Rakefile +19 -3
- data/{lib → etc}/recursive.rb +0 -0
- data/index.html +7 -0
- data/lib/cartesian.rb +1 -1
- data/script/txt2html +4 -2
- data/website/doc/Array.html +172 -0
- data/website/doc/Cartesian.html +638 -0
- data/website/doc/CartesianIterator.html +672 -0
- data/website/doc/Enumerable.html +158 -0
- data/website/doc/GridSearch.html +292 -0
- data/website/doc/Iterable.html +306 -0
- data/website/doc/README_rdoc.html +220 -0
- data/website/doc/created.rid +4 -4
- data/website/doc/lib/cartesian_iterator_rb.html +52 -0
- data/website/doc/lib/cartesian_rb.html +56 -0
- data/website/doc/lib/grid_search_rb.html +52 -0
- data/website/doc/rdoc.css +706 -0
- data/website/index.html +3 -3
- data/website/template.html.erb +1 -1
- metadata +15 -37
- data/website/doc/classes/Array.html +0 -128
- data/website/doc/classes/Cartesian.html +0 -398
- data/website/doc/classes/Cartesian.src/M000020.html +0 -18
- data/website/doc/classes/Cartesian.src/M000021.html +0 -18
- data/website/doc/classes/Cartesian.src/M000022.html +0 -18
- data/website/doc/classes/Cartesian.src/M000023.html +0 -23
- data/website/doc/classes/Cartesian.src/M000026.html +0 -23
- data/website/doc/classes/Cartesian.src/M000027.html +0 -30
- data/website/doc/classes/CartesianIterator.html +0 -326
- data/website/doc/classes/CartesianIterator.src/M000001.html +0 -21
- data/website/doc/classes/CartesianIterator.src/M000002.html +0 -18
- data/website/doc/classes/CartesianIterator.src/M000003.html +0 -21
- data/website/doc/classes/CartesianIterator.src/M000005.html +0 -20
- data/website/doc/classes/CartesianIterator.src/M000008.html +0 -20
- data/website/doc/classes/CartesianIterator.src/M000009.html +0 -19
- data/website/doc/classes/CartesianIterator.src/M000012.html +0 -19
- data/website/doc/classes/CartesianIterator.src/M000013.html +0 -39
- data/website/doc/classes/Enumerable.html +0 -112
- data/website/doc/classes/GridSearch.html +0 -160
- data/website/doc/classes/GridSearch.src/M000014.html +0 -18
- data/website/doc/classes/GridSearch.src/M000015.html +0 -18
- data/website/doc/classes/Iterable.html +0 -176
- data/website/doc/classes/Iterable.src/M000016.html +0 -19
- data/website/doc/classes/Iterable.src/M000017.html +0 -19
- data/website/doc/classes/Iterable.src/M000018.html +0 -18
- data/website/doc/classes/Iterable.src/M000019.html +0 -18
- data/website/doc/classes/Range.html +0 -118
- data/website/doc/files/cartesian_iterator_rb.html +0 -101
- data/website/doc/files/cartesian_rb.html +0 -108
- data/website/doc/files/grid_search_rb.html +0 -101
- data/website/doc/fr_class_index.html +0 -33
- data/website/doc/fr_file_index.html +0 -29
- data/website/doc/fr_method_index.html +0 -54
- data/website/doc/rdoc-style.css +0 -208
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -6,12 +6,13 @@ Rakefile
|
|
6
6
|
Wishlist.txt
|
7
7
|
config/hoe.rb
|
8
8
|
config/requirements.rb
|
9
|
+
etc/recursive.rb
|
10
|
+
index.html
|
9
11
|
lib/cartesian.rb
|
10
12
|
lib/cartesian/grid_search.rb
|
11
13
|
lib/cartesian/version.rb
|
12
14
|
lib/cartesian_iterator.rb
|
13
15
|
lib/grid_search.rb
|
14
|
-
lib/recursive.rb
|
15
16
|
script/console
|
16
17
|
script/destroy
|
17
18
|
script/generate
|
@@ -24,42 +25,19 @@ test/test_extensions.rb
|
|
24
25
|
test/test_grid_search.rb
|
25
26
|
test/test_helper.rb
|
26
27
|
test/test_suite.rb
|
27
|
-
website/doc/
|
28
|
-
website/doc/
|
29
|
-
website/doc/
|
30
|
-
website/doc/
|
31
|
-
website/doc/
|
32
|
-
website/doc/
|
33
|
-
website/doc/
|
34
|
-
website/doc/classes/Cartesian.src/M000027.html
|
35
|
-
website/doc/classes/CartesianIterator.html
|
36
|
-
website/doc/classes/CartesianIterator.src/M000001.html
|
37
|
-
website/doc/classes/CartesianIterator.src/M000002.html
|
38
|
-
website/doc/classes/CartesianIterator.src/M000003.html
|
39
|
-
website/doc/classes/CartesianIterator.src/M000005.html
|
40
|
-
website/doc/classes/CartesianIterator.src/M000008.html
|
41
|
-
website/doc/classes/CartesianIterator.src/M000009.html
|
42
|
-
website/doc/classes/CartesianIterator.src/M000012.html
|
43
|
-
website/doc/classes/CartesianIterator.src/M000013.html
|
44
|
-
website/doc/classes/Enumerable.html
|
45
|
-
website/doc/classes/GridSearch.html
|
46
|
-
website/doc/classes/GridSearch.src/M000014.html
|
47
|
-
website/doc/classes/GridSearch.src/M000015.html
|
48
|
-
website/doc/classes/Iterable.html
|
49
|
-
website/doc/classes/Iterable.src/M000016.html
|
50
|
-
website/doc/classes/Iterable.src/M000017.html
|
51
|
-
website/doc/classes/Iterable.src/M000018.html
|
52
|
-
website/doc/classes/Iterable.src/M000019.html
|
53
|
-
website/doc/classes/Range.html
|
28
|
+
website/doc/Array.html
|
29
|
+
website/doc/Cartesian.html
|
30
|
+
website/doc/CartesianIterator.html
|
31
|
+
website/doc/Enumerable.html
|
32
|
+
website/doc/GridSearch.html
|
33
|
+
website/doc/Iterable.html
|
34
|
+
website/doc/README_rdoc.html
|
54
35
|
website/doc/created.rid
|
55
|
-
website/doc/files/cartesian_iterator_rb.html
|
56
|
-
website/doc/files/cartesian_rb.html
|
57
|
-
website/doc/files/grid_search_rb.html
|
58
|
-
website/doc/fr_class_index.html
|
59
|
-
website/doc/fr_file_index.html
|
60
|
-
website/doc/fr_method_index.html
|
61
36
|
website/doc/index.html
|
62
|
-
website/doc/
|
37
|
+
website/doc/lib/cartesian_iterator_rb.html
|
38
|
+
website/doc/lib/cartesian_rb.html
|
39
|
+
website/doc/lib/grid_search_rb.html
|
40
|
+
website/doc/rdoc.css
|
63
41
|
website/index.html
|
64
42
|
website/index.txt
|
65
43
|
website/javascripts/rounded_corners_lite.inc.js
|
data/Rakefile
CHANGED
@@ -25,10 +25,26 @@ Dir['tasks/**/*.rake'].each { |t| load t }
|
|
25
25
|
# remove_task :default
|
26
26
|
# task :default => [:spec, :features]
|
27
27
|
|
28
|
-
task :
|
28
|
+
task :chdir do
|
29
29
|
Dir.chdir File.dirname(File.expand_path(__FILE__))
|
30
|
-
|
30
|
+
end
|
31
|
+
|
32
|
+
task :render_docs => [:chdir] do
|
33
|
+
system %q{ rm -rf doc/ }
|
31
34
|
system %q{ rdoc README.rdoc lib/*.rb }
|
32
|
-
|
35
|
+
end
|
36
|
+
|
37
|
+
task :render_website => [:chdir, :render_docs] do |t|
|
38
|
+
system %q{ script/txt2html website/index.txt website/template.html.erb > website/index.html }
|
39
|
+
system %q{ rm -rf website/doc; cp -R doc website }
|
40
|
+
end
|
41
|
+
|
42
|
+
task :pre_release => [:manifest, :render_website] do
|
43
|
+
unless `git diff Manifest.txt`.empty?
|
44
|
+
puts
|
45
|
+
puts " Manifest.txt was re-generated and there were changes."
|
46
|
+
puts " Use 'git diff Manifest.txt' to inspect them."
|
47
|
+
puts
|
48
|
+
end
|
33
49
|
end
|
34
50
|
|
data/{lib → etc}/recursive.rb
RENAMED
File without changes
|
data/index.html
ADDED
data/lib/cartesian.rb
CHANGED
@@ -39,7 +39,7 @@ module Cartesian
|
|
39
39
|
# Unfortunately, as of now, the version data must be replicated in ../cartesian.rb,
|
40
40
|
# due to a mix of newgem versions, each requiring a different one. Not DRY :P
|
41
41
|
#
|
42
|
-
VERSION = "0.6.
|
42
|
+
VERSION = "0.6.2"
|
43
43
|
|
44
44
|
# Produces the cartesian product of self and other.
|
45
45
|
# The result is an array of pairs (i.e. two-element arrays).
|
data/script/txt2html
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
GEM_NAME = 'cartesian' # what ppl will type to install your gem
|
4
|
-
|
4
|
+
GITHUB_PROJECT = 'cartesian'
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
7
|
begin
|
@@ -18,11 +18,13 @@ require 'erb'
|
|
18
18
|
require File.dirname(File.expand_path(__FILE__)) + "/../lib/#{GEM_NAME}.rb"
|
19
19
|
|
20
20
|
version = Cartesian::VERSION
|
21
|
-
download = "http://
|
21
|
+
download = "http://github.com/adrianomitre/#{GITHUB_PROJECT}"
|
22
22
|
|
23
|
+
=begin
|
23
24
|
def rubyforge_project_id
|
24
25
|
RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
|
25
26
|
end
|
27
|
+
=end
|
26
28
|
|
27
29
|
class Fixnum
|
28
30
|
def ordinal
|
@@ -0,0 +1,172 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
7
|
+
|
8
|
+
<title>Class: Array</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
|
11
|
+
|
12
|
+
<script src="./js/jquery.js" type="text/javascript"
|
13
|
+
charset="utf-8"></script>
|
14
|
+
<script src="./js/thickbox-compressed.js" type="text/javascript"
|
15
|
+
charset="utf-8"></script>
|
16
|
+
<script src="./js/quicksearch.js" type="text/javascript"
|
17
|
+
charset="utf-8"></script>
|
18
|
+
<script src="./js/darkfish.js" type="text/javascript"
|
19
|
+
charset="utf-8"></script>
|
20
|
+
|
21
|
+
</head>
|
22
|
+
<body class="class">
|
23
|
+
|
24
|
+
<div id="metadata">
|
25
|
+
<div id="home-metadata">
|
26
|
+
<div id="home-section" class="section">
|
27
|
+
<h3 class="section-header">
|
28
|
+
<a href="./index.html">Home</a>
|
29
|
+
<a href="./index.html#classes">Classes</a>
|
30
|
+
<a href="./index.html#methods">Methods</a>
|
31
|
+
</h3>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="file-metadata">
|
36
|
+
<div id="file-list-section" class="section">
|
37
|
+
<h3 class="section-header">In Files</h3>
|
38
|
+
<div class="section-body">
|
39
|
+
<ul>
|
40
|
+
|
41
|
+
<li><a href="./lib/cartesian_iterator_rb.html?TB_iframe=true&height=550&width=785"
|
42
|
+
class="thickbox" title="lib/cartesian_iterator.rb">lib/cartesian_iterator.rb</a></li>
|
43
|
+
|
44
|
+
<li><a href="./lib/grid_search_rb.html?TB_iframe=true&height=550&width=785"
|
45
|
+
class="thickbox" title="lib/grid_search.rb">lib/grid_search.rb</a></li>
|
46
|
+
|
47
|
+
</ul>
|
48
|
+
</div>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
|
52
|
+
</div>
|
53
|
+
|
54
|
+
<div id="class-metadata">
|
55
|
+
|
56
|
+
<!-- Parent Class -->
|
57
|
+
|
58
|
+
<div id="parent-class-section" class="section">
|
59
|
+
<h3 class="section-header">Parent</h3>
|
60
|
+
|
61
|
+
<p class="link">Object</p>
|
62
|
+
|
63
|
+
</div>
|
64
|
+
|
65
|
+
|
66
|
+
<!-- Namespace Contents -->
|
67
|
+
|
68
|
+
|
69
|
+
<!-- Method Quickref -->
|
70
|
+
|
71
|
+
|
72
|
+
<!-- Included Modules -->
|
73
|
+
|
74
|
+
<div id="includes-section" class="section">
|
75
|
+
<h3 class="section-header">Included Modules</h3>
|
76
|
+
<ul class="link-list">
|
77
|
+
|
78
|
+
|
79
|
+
<li><a class="include" href="Iterable.html">Iterable</a></li>
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
<li><a class="include" href="GridSearch.html">GridSearch</a></li>
|
84
|
+
|
85
|
+
|
86
|
+
</ul>
|
87
|
+
</div>
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
<div id="project-metadata">
|
92
|
+
|
93
|
+
|
94
|
+
<div id="fileindex-section" class="section project-section">
|
95
|
+
<h3 class="section-header">Files</h3>
|
96
|
+
<ul>
|
97
|
+
|
98
|
+
<li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
|
99
|
+
|
100
|
+
</ul>
|
101
|
+
</div>
|
102
|
+
|
103
|
+
|
104
|
+
<div id="classindex-section" class="section project-section">
|
105
|
+
<h3 class="section-header">Class Index
|
106
|
+
<span class="search-toggle"><img src="./images/find.png"
|
107
|
+
height="16" width="16" alt="[+]"
|
108
|
+
title="show/hide quicksearch" /></span></h3>
|
109
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
110
|
+
<fieldset>
|
111
|
+
<legend>Quicksearch</legend>
|
112
|
+
<input type="text" name="quicksearch" value=""
|
113
|
+
class="quicksearch-field" />
|
114
|
+
</fieldset>
|
115
|
+
</form>
|
116
|
+
|
117
|
+
<ul class="link-list">
|
118
|
+
|
119
|
+
<li><a href="./Array.html">Array</a></li>
|
120
|
+
|
121
|
+
<li><a href="./Cartesian.html">Cartesian</a></li>
|
122
|
+
|
123
|
+
<li><a href="./CartesianIterator.html">CartesianIterator</a></li>
|
124
|
+
|
125
|
+
<li><a href="./Enumerable.html">Enumerable</a></li>
|
126
|
+
|
127
|
+
<li><a href="./GridSearch.html">GridSearch</a></li>
|
128
|
+
|
129
|
+
<li><a href="./Iterable.html">Iterable</a></li>
|
130
|
+
|
131
|
+
</ul>
|
132
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
133
|
+
</div>
|
134
|
+
|
135
|
+
|
136
|
+
</div>
|
137
|
+
</div>
|
138
|
+
|
139
|
+
<div id="documentation">
|
140
|
+
<h1 class="class">Array</h1>
|
141
|
+
|
142
|
+
<div id="description">
|
143
|
+
|
144
|
+
</div>
|
145
|
+
|
146
|
+
<!-- Constants -->
|
147
|
+
|
148
|
+
|
149
|
+
<!-- Attributes -->
|
150
|
+
|
151
|
+
|
152
|
+
<!-- Methods -->
|
153
|
+
|
154
|
+
|
155
|
+
</div>
|
156
|
+
|
157
|
+
|
158
|
+
<div id="rdoc-debugging-section-dump" class="debugging-section">
|
159
|
+
|
160
|
+
<p>Disabled; run with --debug to generate this.</p>
|
161
|
+
|
162
|
+
</div>
|
163
|
+
|
164
|
+
<div id="validator-badges">
|
165
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
166
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
167
|
+
Rdoc Generator</a> 1.1.6</small>.</p>
|
168
|
+
</div>
|
169
|
+
|
170
|
+
</body>
|
171
|
+
</html>
|
172
|
+
|
@@ -0,0 +1,638 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
7
|
+
|
8
|
+
<title>Module: Cartesian</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
|
11
|
+
|
12
|
+
<script src="./js/jquery.js" type="text/javascript"
|
13
|
+
charset="utf-8"></script>
|
14
|
+
<script src="./js/thickbox-compressed.js" type="text/javascript"
|
15
|
+
charset="utf-8"></script>
|
16
|
+
<script src="./js/quicksearch.js" type="text/javascript"
|
17
|
+
charset="utf-8"></script>
|
18
|
+
<script src="./js/darkfish.js" type="text/javascript"
|
19
|
+
charset="utf-8"></script>
|
20
|
+
|
21
|
+
</head>
|
22
|
+
<body class="module">
|
23
|
+
|
24
|
+
<div id="metadata">
|
25
|
+
<div id="home-metadata">
|
26
|
+
<div id="home-section" class="section">
|
27
|
+
<h3 class="section-header">
|
28
|
+
<a href="./index.html">Home</a>
|
29
|
+
<a href="./index.html#classes">Classes</a>
|
30
|
+
<a href="./index.html#methods">Methods</a>
|
31
|
+
</h3>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="file-metadata">
|
36
|
+
<div id="file-list-section" class="section">
|
37
|
+
<h3 class="section-header">In Files</h3>
|
38
|
+
<div class="section-body">
|
39
|
+
<ul>
|
40
|
+
|
41
|
+
<li><a href="./lib/cartesian_rb.html?TB_iframe=true&height=550&width=785"
|
42
|
+
class="thickbox" title="lib/cartesian.rb">lib/cartesian.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div id="class-metadata">
|
52
|
+
|
53
|
+
<!-- Parent Class -->
|
54
|
+
|
55
|
+
|
56
|
+
<!-- Namespace Contents -->
|
57
|
+
|
58
|
+
|
59
|
+
<!-- Method Quickref -->
|
60
|
+
|
61
|
+
<div id="method-list-section" class="section">
|
62
|
+
<h3 class="section-header">Methods</h3>
|
63
|
+
<ul class="link-list">
|
64
|
+
|
65
|
+
<li><a href="#method-c-joined_product">::joined_product</a></li>
|
66
|
+
|
67
|
+
<li><a href="#method-c-product">::product</a></li>
|
68
|
+
|
69
|
+
<li><a href="#method-i-%2A%2A">#**</a></li>
|
70
|
+
|
71
|
+
<li><a href="#method-i-cartesian">#cartesian</a></li>
|
72
|
+
|
73
|
+
<li><a href="#method-i-joined_cartesian">#joined_cartesian</a></li>
|
74
|
+
|
75
|
+
<li><a href="#method-i-left_product">#left_product</a></li>
|
76
|
+
|
77
|
+
<li><a href="#method-i-power%21">#power!</a></li>
|
78
|
+
|
79
|
+
<li><a href="#method-i-right_product">#right_product</a></li>
|
80
|
+
|
81
|
+
<li><a href="#method-i-x">#x</a></li>
|
82
|
+
|
83
|
+
</ul>
|
84
|
+
</div>
|
85
|
+
|
86
|
+
|
87
|
+
<!-- Included Modules -->
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
<div id="project-metadata">
|
92
|
+
|
93
|
+
|
94
|
+
<div id="fileindex-section" class="section project-section">
|
95
|
+
<h3 class="section-header">Files</h3>
|
96
|
+
<ul>
|
97
|
+
|
98
|
+
<li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
|
99
|
+
|
100
|
+
</ul>
|
101
|
+
</div>
|
102
|
+
|
103
|
+
|
104
|
+
<div id="classindex-section" class="section project-section">
|
105
|
+
<h3 class="section-header">Class Index
|
106
|
+
<span class="search-toggle"><img src="./images/find.png"
|
107
|
+
height="16" width="16" alt="[+]"
|
108
|
+
title="show/hide quicksearch" /></span></h3>
|
109
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
110
|
+
<fieldset>
|
111
|
+
<legend>Quicksearch</legend>
|
112
|
+
<input type="text" name="quicksearch" value=""
|
113
|
+
class="quicksearch-field" />
|
114
|
+
</fieldset>
|
115
|
+
</form>
|
116
|
+
|
117
|
+
<ul class="link-list">
|
118
|
+
|
119
|
+
<li><a href="./Array.html">Array</a></li>
|
120
|
+
|
121
|
+
<li><a href="./Cartesian.html">Cartesian</a></li>
|
122
|
+
|
123
|
+
<li><a href="./CartesianIterator.html">CartesianIterator</a></li>
|
124
|
+
|
125
|
+
<li><a href="./Enumerable.html">Enumerable</a></li>
|
126
|
+
|
127
|
+
<li><a href="./GridSearch.html">GridSearch</a></li>
|
128
|
+
|
129
|
+
<li><a href="./Iterable.html">Iterable</a></li>
|
130
|
+
|
131
|
+
</ul>
|
132
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
133
|
+
</div>
|
134
|
+
|
135
|
+
|
136
|
+
</div>
|
137
|
+
</div>
|
138
|
+
|
139
|
+
<div id="documentation">
|
140
|
+
<h1 class="module">Cartesian</h1>
|
141
|
+
|
142
|
+
<div id="description">
|
143
|
+
<p>
|
144
|
+
The <a href="Cartesian.html">Cartesian</a> module provide methods for the
|
145
|
+
calculation of the cartesian producted between two enumerable objects.
|
146
|
+
</p>
|
147
|
+
<p>
|
148
|
+
It can also be easily mixed in into any enumerable class, i.e. any class
|
149
|
+
with <a href="Enumerable.html">Enumerable</a> module mixed in. Notice that
|
150
|
+
the names of the methods for mixin are different.
|
151
|
+
</p>
|
152
|
+
<p>
|
153
|
+
Module:
|
154
|
+
</p>
|
155
|
+
<pre>
|
156
|
+
Cartesian::product(foo, bar)
|
157
|
+
</pre>
|
158
|
+
<p>
|
159
|
+
Mixin:
|
160
|
+
</p>
|
161
|
+
<pre>
|
162
|
+
foo.cartesian( bar )
|
163
|
+
</pre>
|
164
|
+
<p>
|
165
|
+
The module is automatically mixed in <a href="Array.html">Array</a> class.
|
166
|
+
</p>
|
167
|
+
<h2>Author</h2>
|
168
|
+
<p>
|
169
|
+
Adriano MITRE <adriano.mitre@gmail.com>
|
170
|
+
</p>
|
171
|
+
<h2>Example</h2>
|
172
|
+
<p>
|
173
|
+
as module
|
174
|
+
</p>
|
175
|
+
<pre>
|
176
|
+
require 'cartesian'
|
177
|
+
foo = [1, 2]
|
178
|
+
bar = ["a", "b"]
|
179
|
+
Cartesian::product(foo, bar) #=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
|
180
|
+
</pre>
|
181
|
+
<p>
|
182
|
+
as mixin
|
183
|
+
</p>
|
184
|
+
<pre>
|
185
|
+
require 'cartesian'
|
186
|
+
foo = [1, 2]
|
187
|
+
bar = ["a", "b"]
|
188
|
+
foo.cartesian(bar) #=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]</pre>
|
189
|
+
|
190
|
+
</div>
|
191
|
+
|
192
|
+
<!-- Constants -->
|
193
|
+
|
194
|
+
<div id="constants-list" class="section">
|
195
|
+
<h3 class="section-header">Constants</h3>
|
196
|
+
<dl>
|
197
|
+
|
198
|
+
<dt><a name="VERSION">VERSION</a></dt>
|
199
|
+
|
200
|
+
<dd class="description"><p>
|
201
|
+
Unfortunately, as of now, the version data must be replicated in
|
202
|
+
../cartesian.rb, due to a mix of newgem versions, each requiring a
|
203
|
+
different one. Not DRY :P
|
204
|
+
</p></dd>
|
205
|
+
|
206
|
+
|
207
|
+
</dl>
|
208
|
+
</div>
|
209
|
+
|
210
|
+
|
211
|
+
<!-- Attributes -->
|
212
|
+
|
213
|
+
|
214
|
+
<!-- Methods -->
|
215
|
+
|
216
|
+
<div id="public-class-method-details" class="method-section section">
|
217
|
+
<h3 class="section-header">Public Class Methods</h3>
|
218
|
+
|
219
|
+
|
220
|
+
<div id="joined-product-method" class="method-detail ">
|
221
|
+
<a name="method-c-joined_product"></a>
|
222
|
+
|
223
|
+
<div class="method-heading">
|
224
|
+
|
225
|
+
<span class="method-name">joined_product</span><span
|
226
|
+
class="method-args">(first, second)</span>
|
227
|
+
<span class="method-click-advice">click to toggle source</span>
|
228
|
+
|
229
|
+
</div>
|
230
|
+
|
231
|
+
<div class="method-description">
|
232
|
+
|
233
|
+
<p>
|
234
|
+
Behaves as product, except for the elements are joined.
|
235
|
+
</p>
|
236
|
+
<pre>
|
237
|
+
Cartesian::joined_cartesian( [1,2], %w(A B) ) #=> ["1A", "1B", "2A", "2B"]
|
238
|
+
</pre>
|
239
|
+
<p>
|
240
|
+
or, if mixed in into <a href="Array.html">Array</a>,
|
241
|
+
</p>
|
242
|
+
<pre>
|
243
|
+
[1,2].joined_cartesian %w(A B) #=> ["1A", "1B", "2A", "2B"]</pre>
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
<div class="method-source-code"
|
248
|
+
id="joined-product-source">
|
249
|
+
<pre>
|
250
|
+
<span class="ruby-comment cmt"># File lib/cartesian.rb, line 65</span>
|
251
|
+
65: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Cartesian</span>.<span class="ruby-identifier">joined_product</span>(<span class="ruby-identifier">first</span>, <span class="ruby-identifier">second</span>)
|
252
|
+
66: <span class="ruby-identifier">product</span>(<span class="ruby-identifier">first</span>, <span class="ruby-identifier">second</span>).<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">pair</span><span class="ruby-operator">|</span> <span class="ruby-identifier">pair</span>.<span class="ruby-identifier">join</span> }
|
253
|
+
67: <span class="ruby-keyword kw">end</span></pre>
|
254
|
+
</div>
|
255
|
+
|
256
|
+
</div>
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
</div>
|
262
|
+
|
263
|
+
|
264
|
+
<div id="product-method" class="method-detail ">
|
265
|
+
<a name="method-c-product"></a>
|
266
|
+
|
267
|
+
<div class="method-heading">
|
268
|
+
|
269
|
+
<span class="method-name">product</span><span
|
270
|
+
class="method-args">(first, second)</span>
|
271
|
+
<span class="method-click-advice">click to toggle source</span>
|
272
|
+
|
273
|
+
</div>
|
274
|
+
|
275
|
+
<div class="method-description">
|
276
|
+
|
277
|
+
<p>
|
278
|
+
Produces the cartesian product of self and other. The result is an array of
|
279
|
+
pairs (i.e. two-element arrays).
|
280
|
+
</p>
|
281
|
+
<pre>
|
282
|
+
Cartesian::product( [1,2], %w(A B) ) #=> [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
|
283
|
+
</pre>
|
284
|
+
<p>
|
285
|
+
or, if mixed in into <a href="Array.html">Array</a>,
|
286
|
+
</p>
|
287
|
+
<pre>
|
288
|
+
[1,2].cartesian %w(A B) #=> [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]</pre>
|
289
|
+
|
290
|
+
|
291
|
+
|
292
|
+
<div class="method-source-code"
|
293
|
+
id="product-source">
|
294
|
+
<pre>
|
295
|
+
<span class="ruby-comment cmt"># File lib/cartesian.rb, line 53</span>
|
296
|
+
53: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Cartesian</span>.<span class="ruby-identifier">product</span>(<span class="ruby-identifier">first</span>, <span class="ruby-identifier">second</span>)
|
297
|
+
54: <span class="ruby-identifier">first</span>.<span class="ruby-identifier">x</span>(<span class="ruby-identifier">second</span>).<span class="ruby-identifier">to_a</span>
|
298
|
+
55: <span class="ruby-keyword kw">end</span></pre>
|
299
|
+
</div>
|
300
|
+
|
301
|
+
</div>
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
</div>
|
307
|
+
|
308
|
+
|
309
|
+
</div>
|
310
|
+
|
311
|
+
<div id="public-instance-method-details" class="method-section section">
|
312
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
313
|
+
|
314
|
+
|
315
|
+
<div id="--method" class="method-detail ">
|
316
|
+
<a name="method-i-%2A%2A"></a>
|
317
|
+
|
318
|
+
<div class="method-heading">
|
319
|
+
|
320
|
+
<span class="method-name">**</span><span
|
321
|
+
class="method-args">(fixnum)</span>
|
322
|
+
<span class="method-click-advice">click to toggle source</span>
|
323
|
+
|
324
|
+
</div>
|
325
|
+
|
326
|
+
<div class="method-description">
|
327
|
+
|
328
|
+
<p>
|
329
|
+
Concise way of iterating multi-dimensionally over the same array or range.
|
330
|
+
</p>
|
331
|
+
<p>
|
332
|
+
For instance,
|
333
|
+
</p>
|
334
|
+
<pre>
|
335
|
+
for x,y,z in [0,1]**3
|
336
|
+
puts [x, y, z].join(',')
|
337
|
+
end
|
338
|
+
</pre>
|
339
|
+
<p>
|
340
|
+
produces the following output
|
341
|
+
</p>
|
342
|
+
<pre>
|
343
|
+
0,0,0
|
344
|
+
0,0,1
|
345
|
+
0,1,0
|
346
|
+
0,1,1
|
347
|
+
1,0,0
|
348
|
+
1,0,1
|
349
|
+
1,1,0
|
350
|
+
1,1,1
|
351
|
+
</pre>
|
352
|
+
<p>
|
353
|
+
It also works with Range objects.
|
354
|
+
</p>
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
<div class="method-source-code"
|
359
|
+
id="--source">
|
360
|
+
<pre>
|
361
|
+
<span class="ruby-comment cmt"># File lib/cartesian.rb, line 143</span>
|
362
|
+
143: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">**</span>(<span class="ruby-identifier">fixnum</span>)
|
363
|
+
144: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fixnum</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>
|
364
|
+
145: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"negative power"</span>
|
365
|
+
146: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">fixnum</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
366
|
+
147: <span class="ruby-keyword kw">return</span> []
|
367
|
+
148: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">fixnum</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
|
368
|
+
149: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
|
369
|
+
150: <span class="ruby-keyword kw">else</span>
|
370
|
+
151: <span class="ruby-identifier">iter</span> = <span class="ruby-constant">CartesianIterator</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-keyword kw">self</span>)
|
371
|
+
152: (<span class="ruby-identifier">fixnum</span><span class="ruby-operator">-</span><span class="ruby-value">2</span>).<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span>
|
372
|
+
153: <span class="ruby-identifier">iter</span>.<span class="ruby-identifier">product!</span>(<span class="ruby-keyword kw">self</span>)
|
373
|
+
154: <span class="ruby-keyword kw">end</span>
|
374
|
+
155: <span class="ruby-identifier">iter</span>
|
375
|
+
156: <span class="ruby-keyword kw">end</span>
|
376
|
+
157: <span class="ruby-keyword kw">end</span></pre>
|
377
|
+
</div>
|
378
|
+
|
379
|
+
</div>
|
380
|
+
|
381
|
+
|
382
|
+
<div class="aliases">
|
383
|
+
Also aliased as: <a href="Cartesian.html#method-i-power%21">power!</a>
|
384
|
+
</div>
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
</div>
|
389
|
+
|
390
|
+
|
391
|
+
<div id="cartesian-method" class="method-detail method-alias">
|
392
|
+
<a name="method-i-cartesian"></a>
|
393
|
+
|
394
|
+
<div class="method-heading">
|
395
|
+
|
396
|
+
<span class="method-name">cartesian</span><span
|
397
|
+
class="method-args">(other)</span>
|
398
|
+
<span class="method-click-advice">click to toggle source</span>
|
399
|
+
|
400
|
+
</div>
|
401
|
+
|
402
|
+
<div class="method-description">
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
</div>
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
<div class="aliases">
|
414
|
+
Alias for: <a href="Cartesian.html#method-i-x">x</a>
|
415
|
+
</div>
|
416
|
+
|
417
|
+
</div>
|
418
|
+
|
419
|
+
|
420
|
+
<div id="joined-cartesian-method" class="method-detail ">
|
421
|
+
<a name="method-i-joined_cartesian"></a>
|
422
|
+
|
423
|
+
<div class="method-heading">
|
424
|
+
|
425
|
+
<span class="method-name">joined_cartesian</span><span
|
426
|
+
class="method-args">(other)</span>
|
427
|
+
<span class="method-click-advice">click to toggle source</span>
|
428
|
+
|
429
|
+
</div>
|
430
|
+
|
431
|
+
<div class="method-description">
|
432
|
+
|
433
|
+
<p>
|
434
|
+
Cartesian.joined_product for mixin.
|
435
|
+
</p>
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
<div class="method-source-code"
|
440
|
+
id="joined-cartesian-source">
|
441
|
+
<pre>
|
442
|
+
<span class="ruby-comment cmt"># File lib/cartesian.rb, line 71</span>
|
443
|
+
71: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">joined_cartesian</span>(<span class="ruby-identifier">other</span>)
|
444
|
+
72: <span class="ruby-constant">Cartesian</span>.<span class="ruby-identifier">joined_product</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">other</span>)
|
445
|
+
73: <span class="ruby-keyword kw">end</span></pre>
|
446
|
+
</div>
|
447
|
+
|
448
|
+
</div>
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
</div>
|
454
|
+
|
455
|
+
|
456
|
+
<div id="left-product-method" class="method-detail ">
|
457
|
+
<a name="method-i-left_product"></a>
|
458
|
+
|
459
|
+
<div class="method-heading">
|
460
|
+
|
461
|
+
<span class="method-name">left_product</span><span
|
462
|
+
class="method-args">(other)</span>
|
463
|
+
<span class="method-click-advice">click to toggle source</span>
|
464
|
+
|
465
|
+
</div>
|
466
|
+
|
467
|
+
<div class="method-description">
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
<div class="method-source-code"
|
474
|
+
id="left-product-source">
|
475
|
+
<pre>
|
476
|
+
<span class="ruby-comment cmt"># File lib/cartesian.rb, line 112</span>
|
477
|
+
112: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">left_product</span>(<span class="ruby-identifier">other</span>)
|
478
|
+
113: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">other</span>
|
479
|
+
114: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">CartesianIterator</span>
|
480
|
+
115: <span class="ruby-identifier">other</span>.<span class="ruby-identifier">right_product</span>(<span class="ruby-keyword kw">self</span>)
|
481
|
+
116: <span class="ruby-keyword kw">else</span>
|
482
|
+
117: <span class="ruby-constant">CartesianIterator</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">other</span>, <span class="ruby-keyword kw">self</span>)
|
483
|
+
118: <span class="ruby-keyword kw">end</span>
|
484
|
+
119: <span class="ruby-keyword kw">end</span></pre>
|
485
|
+
</div>
|
486
|
+
|
487
|
+
</div>
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
</div>
|
493
|
+
|
494
|
+
|
495
|
+
<div id="power--method" class="method-detail method-alias">
|
496
|
+
<a name="method-i-power%21"></a>
|
497
|
+
|
498
|
+
<div class="method-heading">
|
499
|
+
|
500
|
+
<span class="method-name">power!</span><span
|
501
|
+
class="method-args">(fixnum)</span>
|
502
|
+
<span class="method-click-advice">click to toggle source</span>
|
503
|
+
|
504
|
+
</div>
|
505
|
+
|
506
|
+
<div class="method-description">
|
507
|
+
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
|
512
|
+
</div>
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
<div class="aliases">
|
518
|
+
Alias for: <a href="Cartesian.html#method-i-%2A%2A">**</a>
|
519
|
+
</div>
|
520
|
+
|
521
|
+
</div>
|
522
|
+
|
523
|
+
|
524
|
+
<div id="right-product-method" class="method-detail method-alias">
|
525
|
+
<a name="method-i-right_product"></a>
|
526
|
+
|
527
|
+
<div class="method-heading">
|
528
|
+
|
529
|
+
<span class="method-name">right_product</span><span
|
530
|
+
class="method-args">(other)</span>
|
531
|
+
<span class="method-click-advice">click to toggle source</span>
|
532
|
+
|
533
|
+
</div>
|
534
|
+
|
535
|
+
<div class="method-description">
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
</div>
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
|
546
|
+
<div class="aliases">
|
547
|
+
Alias for: <a href="Cartesian.html#method-i-x">x</a>
|
548
|
+
</div>
|
549
|
+
|
550
|
+
</div>
|
551
|
+
|
552
|
+
|
553
|
+
<div id="x-method" class="method-detail ">
|
554
|
+
<a name="method-i-x"></a>
|
555
|
+
|
556
|
+
<div class="method-heading">
|
557
|
+
|
558
|
+
<span class="method-name">x</span><span
|
559
|
+
class="method-args">(other)</span>
|
560
|
+
<span class="method-click-advice">click to toggle source</span>
|
561
|
+
|
562
|
+
</div>
|
563
|
+
|
564
|
+
<div class="method-description">
|
565
|
+
|
566
|
+
<p>
|
567
|
+
Convenient way of iterating over the elements. Preferable when the
|
568
|
+
cartesian product array is not needed, for the consumption of memory is
|
569
|
+
fixed and very small, in contrast with the exponential memory requirements
|
570
|
+
of the conventional approach.
|
571
|
+
</p>
|
572
|
+
<pre>
|
573
|
+
for row, col in (1..10).x(1..30)
|
574
|
+
Matrix[row, col] = row**2 + col**3
|
575
|
+
end
|
576
|
+
</pre>
|
577
|
+
<p>
|
578
|
+
Of course, calls can be chained as in
|
579
|
+
</p>
|
580
|
+
<pre>
|
581
|
+
for x, y, z in (1..10).x(1..10).x(1..10)
|
582
|
+
# ... do something ...
|
583
|
+
end
|
584
|
+
</pre>
|
585
|
+
<p>
|
586
|
+
Beware that both <tt>self</tt> and <tt>other</tt> must implement
|
587
|
+
<tt>to_a</tt>, i.e., be convertible to array.
|
588
|
+
</p>
|
589
|
+
|
590
|
+
|
591
|
+
|
592
|
+
<div class="method-source-code"
|
593
|
+
id="x-source">
|
594
|
+
<pre>
|
595
|
+
<span class="ruby-comment cmt"># File lib/cartesian.rb, line 101</span>
|
596
|
+
101: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">x</span>(<span class="ruby-identifier">other</span>)
|
597
|
+
102: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">other</span>
|
598
|
+
103: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">CartesianIterator</span>
|
599
|
+
104: <span class="ruby-identifier">other</span>.<span class="ruby-identifier">left_product</span>(<span class="ruby-keyword kw">self</span>)
|
600
|
+
105: <span class="ruby-keyword kw">else</span>
|
601
|
+
106: <span class="ruby-constant">CartesianIterator</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">other</span>)
|
602
|
+
107: <span class="ruby-keyword kw">end</span>
|
603
|
+
108: <span class="ruby-keyword kw">end</span></pre>
|
604
|
+
</div>
|
605
|
+
|
606
|
+
</div>
|
607
|
+
|
608
|
+
|
609
|
+
<div class="aliases">
|
610
|
+
Also aliased as: <a href="Cartesian.html#method-i-cartesian">cartesian</a>, <a href="Cartesian.html#method-i-right_product">right_product</a>
|
611
|
+
</div>
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
</div>
|
616
|
+
|
617
|
+
|
618
|
+
</div>
|
619
|
+
|
620
|
+
|
621
|
+
</div>
|
622
|
+
|
623
|
+
|
624
|
+
<div id="rdoc-debugging-section-dump" class="debugging-section">
|
625
|
+
|
626
|
+
<p>Disabled; run with --debug to generate this.</p>
|
627
|
+
|
628
|
+
</div>
|
629
|
+
|
630
|
+
<div id="validator-badges">
|
631
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
632
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
633
|
+
Rdoc Generator</a> 1.1.6</small>.</p>
|
634
|
+
</div>
|
635
|
+
|
636
|
+
</body>
|
637
|
+
</html>
|
638
|
+
|