Cartesian 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +0,0 @@
1
- class Object
2
-
3
- # Syntax sugar for "is this object among this array?"
4
- #
5
- # 1.among? [1,2,3] #=> true
6
- # 0.among? [4,5] #=> false
7
- #
8
- def among?(ary)
9
- ary.include? self
10
- end
11
-
12
- end
@@ -1,39 +0,0 @@
1
- module GridSearch
2
-
3
- # Finds the argument which maximizes the function given in the block trhu grid-search maximization.
4
- # [-1,0,1,2].argmax {|x| x**2 } #=> 2
5
- #
6
- def argmax(&block)
7
- argbest(:>, &block)
8
- end
9
-
10
- # Finds the argument which minimizes the function given in the block trhu grid-search minimization.
11
- # [-1,0,1,2].argmin {|x| x**2 } #=> 0
12
- #
13
- def argmin(&block)
14
- argbest(:<, &block)
15
- end
16
-
17
- private
18
-
19
- def argbest(cmp)
20
- best_arg, best_val = nil, nil
21
- self.each do |*curr_arg|
22
- curr_val = yield(*curr_arg)
23
- if best_val.nil? || curr_val.send(cmp, best_val)
24
- best_val = curr_val
25
- best_arg = curr_arg
26
- end
27
- end
28
- best_arg
29
- end
30
-
31
- end
32
-
33
- module Enumerable
34
- include GridSearch
35
- end
36
-
37
- class Array
38
- include GridSearch
39
- end
@@ -1,8 +0,0 @@
1
- # Code by Brian Schröäer
2
- # source: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/151857
3
- #
4
- def cartprod(base, *others)
5
- return base.map { |a| [a] } if others.empty?
6
- others = cartprod(*others)
7
- base.inject([]) { | r, a | others.inject(r) { | r, b | r << ([a,*b]) } }
8
- end
@@ -1,26 +0,0 @@
1
- require 'cartesian'
2
- require 'benchmark'
3
-
4
- MULTIPLIER = 3
5
- letras = ("a"*MULTIPLIER.."z"*MULTIPLIER).to_a
6
- numeros = (0..10**1).to_a
7
-
8
- Benchmark.bmbm do |x|
9
- letras_numeros = nil
10
- x.report("product") { letras_numeros = Cartesian.product(letras, numeros) }
11
- x.report("product 2") { for x,y in letras_numeros; end }
12
-
13
- x.report(".x") { letras_numeros = letras.x(numeros) }
14
- x.report(".x 2") { for x,y in letras_numeros; end }
15
- end
16
-
17
- #~ x.report("productZip") { Cartesian.productZip(letras, numeros) }
18
-
19
- #~ def Cartesian.productZip(first, second)
20
- #~ result = []
21
- #~ first.each do |a|
22
- #~ aaa = Array.new(second.size) { a }
23
- #~ result += aaa.zip(second)
24
- #~ end
25
- #~ result
26
- #~ end
@@ -1,308 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
3
- <head>
4
- <title>
5
- /home/adriano/software/ruby/Cartesian/lib/cartesian_iterator.rb - C0 code
6
- coverage information
7
- </title>
8
- <style type='text/css'>
9
- body { background-color: rgb(240, 240, 245); }
10
- </style>
11
- <style type='text/css'>
12
- span.cross-ref-title { font-size: 140%; } span.cross-ref a {
13
- text-decoration: none; } span.cross-ref { background-color:#f3f7fa;
14
- border: 1px dashed #333; margin: 1em; padding: 0.5em; overflow: hidden; }
15
- a.crossref-toggle { text-decoration: none; } span.marked0 {
16
- background-color: rgb(185, 210, 200); display: block; } span.marked1 {
17
- background-color: rgb(190, 215, 205); display: block; } span.inferred0 {
18
- background-color: rgb(175, 200, 200); display: block; } span.inferred1 {
19
- background-color: rgb(180, 205, 205); display: block; } span.uncovered0 {
20
- background-color: rgb(225, 110, 110); display: block; } span.uncovered1 {
21
- background-color: rgb(235, 120, 120); display: block; } span.overview {
22
- border-bottom: 8px solid black; } div.overview { border-bottom: 8px solid
23
- black; } body { font-family: verdana, arial, helvetica; } div.footer {
24
- font-size: 68%; margin-top: 1.5em; } h1, h2, h3, h4, h5, h6 {
25
- margin-bottom: 0.5em; } h5 { margin-top: 0.5em; } .hidden { display: none;
26
- } div.separator { height: 10px; } /* Commented out for better readability,
27
- esp. on IE */ /* table tr td, table tr th { font-size: 68%; } td.value
28
- table tr td { font-size: 11px; } */ table.percent_graph { height: 12px;
29
- border: #808080 1px solid; empty-cells: show; } table.percent_graph
30
- td.covered { height: 10px; background: #00f000; } table.percent_graph
31
- td.uncovered { height: 10px; background: #e00000; } table.percent_graph
32
- td.NA { height: 10px; background: #eaeaea; } table.report {
33
- border-collapse: collapse; width: 100%; } table.report td.heading {
34
- background: #dcecff; border: #d0d0d0 1px solid; font-weight: bold;
35
- text-align: center; } table.report td.heading:hover { background: #c0ffc0;
36
- } table.report td.text { border: #d0d0d0 1px solid; } table.report
37
- td.value, table.report td.lines_total, table.report td.lines_code {
38
- text-align: right; border: #d0d0d0 1px solid; } table.report tr.light {
39
- background-color: rgb(240, 240, 245); } table.report tr.dark {
40
- background-color: rgb(230, 230, 235); }
41
- </style>
42
- <script type='text/javascript'>
43
- // <![CDATA[ function toggleCode( id ) { if ( document.getElementById )
44
- elem = document.getElementById( id ); else if ( document.all ) elem =
45
- eval( "document.all." + id ); else return false; elemStyle = elem.style;
46
- if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else {
47
- elemStyle.display = "none" } return true; } // Make cross-references
48
- hidden by default document.writeln( "<style
49
- type=\"text/css\">span.cross-ref { display: none }</style>" ) // ]]>
50
- </script>
51
- <style type='text/css'>
52
- span.run0 { background-color: rgb(178, 204, 255); display: block; }
53
- span.run1 { background-color: rgb(178, 206, 255); display: block; }
54
- span.run2 { background-color: rgb(178, 209, 255); display: block; }
55
- span.run3 { background-color: rgb(178, 211, 255); display: block; }
56
- span.run4 { background-color: rgb(178, 214, 255); display: block; }
57
- span.run5 { background-color: rgb(178, 218, 255); display: block; }
58
- span.run6 { background-color: rgb(178, 220, 255); display: block; }
59
- span.run7 { background-color: rgb(178, 223, 255); display: block; }
60
- span.run8 { background-color: rgb(178, 225, 255); display: block; }
61
- span.run9 { background-color: rgb(178, 228, 255); display: block; }
62
- span.run10 { background-color: rgb(178, 232, 255); display: block; }
63
- span.run11 { background-color: rgb(178, 234, 255); display: block; }
64
- span.run12 { background-color: rgb(178, 237, 255); display: block; }
65
- span.run13 { background-color: rgb(178, 239, 255); display: block; }
66
- span.run14 { background-color: rgb(178, 242, 255); display: block; }
67
- span.run15 { background-color: rgb(178, 246, 255); display: block; }
68
- span.run16 { background-color: rgb(178, 248, 255); display: block; }
69
- span.run17 { background-color: rgb(178, 251, 255); display: block; }
70
- span.run18 { background-color: rgb(178, 253, 255); display: block; }
71
- span.run19 { background-color: rgb(178, 255, 253); display: block; }
72
- span.run20 { background-color: rgb(178, 255, 249); display: block; }
73
- span.run21 { background-color: rgb(178, 255, 247); display: block; }
74
- span.run22 { background-color: rgb(178, 255, 244); display: block; }
75
- span.run23 { background-color: rgb(178, 255, 242); display: block; }
76
- span.run24 { background-color: rgb(178, 255, 239); display: block; }
77
- span.run25 { background-color: rgb(178, 255, 235); display: block; }
78
- span.run26 { background-color: rgb(178, 255, 233); display: block; }
79
- span.run27 { background-color: rgb(178, 255, 230); display: block; }
80
- span.run28 { background-color: rgb(178, 255, 228); display: block; }
81
- span.run29 { background-color: rgb(178, 255, 225); display: block; }
82
- span.run30 { background-color: rgb(178, 255, 221); display: block; }
83
- span.run31 { background-color: rgb(178, 255, 219); display: block; }
84
- span.run32 { background-color: rgb(178, 255, 216); display: block; }
85
- span.run33 { background-color: rgb(178, 255, 214); display: block; }
86
- span.run34 { background-color: rgb(178, 255, 211); display: block; }
87
- span.run35 { background-color: rgb(178, 255, 207); display: block; }
88
- span.run36 { background-color: rgb(178, 255, 205); display: block; }
89
- span.run37 { background-color: rgb(178, 255, 202); display: block; }
90
- span.run38 { background-color: rgb(178, 255, 200); display: block; }
91
- span.run39 { background-color: rgb(178, 255, 197); display: block; }
92
- span.run40 { background-color: rgb(178, 255, 193); display: block; }
93
- span.run41 { background-color: rgb(178, 255, 191); display: block; }
94
- span.run42 { background-color: rgb(178, 255, 188); display: block; }
95
- span.run43 { background-color: rgb(178, 255, 186); display: block; }
96
- span.run44 { background-color: rgb(178, 255, 183); display: block; }
97
- span.run45 { background-color: rgb(178, 255, 179); display: block; }
98
- span.run46 { background-color: rgb(179, 255, 178); display: block; }
99
- span.run47 { background-color: rgb(182, 255, 178); display: block; }
100
- span.run48 { background-color: rgb(184, 255, 178); display: block; }
101
- span.run49 { background-color: rgb(187, 255, 178); display: block; }
102
- span.run50 { background-color: rgb(191, 255, 178); display: block; }
103
- span.run51 { background-color: rgb(193, 255, 178); display: block; }
104
- span.run52 { background-color: rgb(196, 255, 178); display: block; }
105
- span.run53 { background-color: rgb(198, 255, 178); display: block; }
106
- span.run54 { background-color: rgb(201, 255, 178); display: block; }
107
- span.run55 { background-color: rgb(205, 255, 178); display: block; }
108
- span.run56 { background-color: rgb(207, 255, 178); display: block; }
109
- span.run57 { background-color: rgb(210, 255, 178); display: block; }
110
- span.run58 { background-color: rgb(212, 255, 178); display: block; }
111
- span.run59 { background-color: rgb(215, 255, 178); display: block; }
112
- span.run60 { background-color: rgb(219, 255, 178); display: block; }
113
- span.run61 { background-color: rgb(221, 255, 178); display: block; }
114
- span.run62 { background-color: rgb(224, 255, 178); display: block; }
115
- span.run63 { background-color: rgb(226, 255, 178); display: block; }
116
- span.run64 { background-color: rgb(229, 255, 178); display: block; }
117
- span.run65 { background-color: rgb(233, 255, 178); display: block; }
118
- span.run66 { background-color: rgb(235, 255, 178); display: block; }
119
- span.run67 { background-color: rgb(238, 255, 178); display: block; }
120
- span.run68 { background-color: rgb(240, 255, 178); display: block; }
121
- span.run69 { background-color: rgb(243, 255, 178); display: block; }
122
- span.run70 { background-color: rgb(247, 255, 178); display: block; }
123
- span.run71 { background-color: rgb(249, 255, 178); display: block; }
124
- span.run72 { background-color: rgb(252, 255, 178); display: block; }
125
- span.run73 { background-color: rgb(255, 255, 178); display: block; }
126
- span.run74 { background-color: rgb(255, 252, 178); display: block; }
127
- span.run75 { background-color: rgb(255, 248, 178); display: block; }
128
- span.run76 { background-color: rgb(255, 246, 178); display: block; }
129
- span.run77 { background-color: rgb(255, 243, 178); display: block; }
130
- span.run78 { background-color: rgb(255, 240, 178); display: block; }
131
- span.run79 { background-color: rgb(255, 238, 178); display: block; }
132
- span.run80 { background-color: rgb(255, 234, 178); display: block; }
133
- span.run81 { background-color: rgb(255, 232, 178); display: block; }
134
- span.run82 { background-color: rgb(255, 229, 178); display: block; }
135
- span.run83 { background-color: rgb(255, 226, 178); display: block; }
136
- span.run84 { background-color: rgb(255, 224, 178); display: block; }
137
- span.run85 { background-color: rgb(255, 220, 178); display: block; }
138
- span.run86 { background-color: rgb(255, 218, 178); display: block; }
139
- span.run87 { background-color: rgb(255, 215, 178); display: block; }
140
- span.run88 { background-color: rgb(255, 212, 178); display: block; }
141
- span.run89 { background-color: rgb(255, 210, 178); display: block; }
142
- span.run90 { background-color: rgb(255, 206, 178); display: block; }
143
- span.run91 { background-color: rgb(255, 204, 178); display: block; }
144
- span.run92 { background-color: rgb(255, 201, 178); display: block; }
145
- span.run93 { background-color: rgb(255, 198, 178); display: block; }
146
- span.run94 { background-color: rgb(255, 196, 178); display: block; }
147
- span.run95 { background-color: rgb(255, 192, 178); display: block; }
148
- span.run96 { background-color: rgb(255, 189, 178); display: block; }
149
- span.run97 { background-color: rgb(255, 187, 178); display: block; }
150
- span.run98 { background-color: rgb(255, 184, 178); display: block; }
151
- span.run99 { background-color: rgb(255, 182, 178); display: block; }
152
- span.run100 { background-color: rgb(255, 178, 178); display: block; }
153
- </style>
154
- </head>
155
- <body>
156
- <h3>
157
- C0 code coverage information
158
- </h3>
159
- <p>
160
- Generated on Tue Nov 04 04:48:28 -0200 2008 with
161
- <a href='http://eigenclass.org/hiki/rcov'>
162
- rcov 0.8.1.2
163
- </a>
164
- </p>
165
- <hr />
166
- <pre><span class='marked0'>Code reported as executed by Ruby looks like
167
- this... </span><span class='marked1'>and this: this line is also marked as
168
- covered. </span><span class='inferred0'>Lines considered as run by rcov, but
169
- not reported by Ruby, look like this, </span><span class='inferred1'>and
170
- this: these lines were inferred by rcov (using simple heuristics).
171
- </span><span class='uncovered0'>Finally, here&apos;s a line marked as not
172
- executed. </span></pre>
173
- <table class='report'> <thead> <tr> <td class='heading'> Name </td> <td
174
- class='heading'> Total lines </td> <td class='heading'> Lines of code </td>
175
- <td class='heading'> Total coverage </td> <td class='heading'> Code coverage
176
- </td> </tr> </thead> <tbody> <tr class='light'> <td> <a
177
- href='-home-adriano-software-ruby-Cartesian-lib-cartesian_iterator_rb.html'>
178
- /home/adriano/software/ruby/Cartesian/lib/cartesian_iterator.rb </a> </td>
179
- <td class='lines_total'> <tt> 108 </tt> </td> <td class='lines_code'> <tt>
180
- 89 </tt> </td> <td> <table cellspacing='0' align='right' cellpadding='0'>
181
- <tr> <td> <tt class='coverage_total'> 100.0% </tt> &nbsp; </td> <td> <table
182
- class='percent_graph' cellspacing='0' width='100' cellpadding='0'> <tr> <td
183
- class='covered' width='100' /> <td class='uncovered' width='0' /> </tr>
184
- </table> </td> </tr> </table> </td> <td> <table cellspacing='0'
185
- align='right' cellpadding='0'> <tr> <td> <tt class='coverage_code'> 100.0%
186
- </tt> &nbsp; </td> <td> <table class='percent_graph' cellspacing='0'
187
- width='100' cellpadding='0'> <tr> <td class='covered' width='100' /> <td
188
- class='uncovered' width='0' /> </tr> </table> </td> </tr> </table> </td>
189
- </tr> </tbody> </table><pre><span class="marked0"><a name="line1"></a> 1
190
- require 'grid_search' </span><span class="inferred1"><a name="line2"></a> 2
191
- </span><span class="marked0"><a name="line3"></a> 3 class CartesianIterator
192
- </span><span class="inferred1"><a name="line4"></a> 4 </span><span
193
- class="marked0"><a name="line5"></a> 5 include GridSearch </span><span
194
- class="inferred1"><a name="line6"></a> 6 </span><span class="marked0"><a
195
- name="line7"></a> 7 def initialize(foo, bar) </span><span class="marked1"><a
196
- name="line8"></a> 8 @lists = [] </span><span class="marked0"><a
197
- name="line9"></a> 9 @tot_iter = 1 </span><span class="marked1"><a
198
- name="line10"></a> 10 product!(foo) </span><span class="marked0"><a
199
- name="line11"></a> 11 product!(bar) </span><span class="inferred1"><a
200
- name="line12"></a> 12 end </span><span class="inferred0"><a
201
- name="line13"></a> 13 </span><span class="marked1"><a name="line14"></a> 14
202
- def dup </span><span class="marked0"><a name="line15"></a> 15
203
- Marshal.load(Marshal.dump(self)) </span><span class="inferred1"><a
204
- name="line16"></a> 16 end </span><span class="inferred0"><a
205
- name="line17"></a> 17 </span><span class="marked1"><a name="line18"></a> 18
206
- def equal(other) </span><span class="marked0"><a name="line19"></a> 19
207
- self.instance_variables.each do |var_name| </span><span class="marked1"><a
208
- name="line20"></a> 20 return false if self.instance_variable_get(var_name)
209
- != other.instance_variable_get(var_name) </span><span class="inferred0"><a
210
- name="line21"></a> 21 end </span><span class="marked1"><a name="line22"></a>
211
- 22 true </span><span class="inferred0"><a name="line23"></a> 23 end
212
- </span><span class="marked1"><a name="line24"></a> 24 alias == equal
213
- </span><span class="inferred0"><a name="line25"></a> 25 </span><span
214
- class="marked1"><a name="line26"></a> 26 def product!(other) </span><span
215
- class="marked0"><a name="line27"></a> 27 @lists &lt;&lt; other.to_a.dup
216
- </span><span class="marked1"><a name="line28"></a> 28 @tot_iter *=
217
- @lists[-1].size </span><span class="marked0"><a name="line29"></a> 29 self
218
- </span><span class="inferred1"><a name="line30"></a> 30 end </span><span
219
- class="marked0"><a name="line31"></a> 31 alias right_product! product!
220
- </span><span class="marked1"><a name="line32"></a> 32 alias x! product!
221
- </span><span class="inferred0"><a name="line33"></a> 33 </span><span
222
- class="marked1"><a name="line34"></a> 34 def left_product!(other)
223
- </span><span class="marked0"><a name="line35"></a> 35 @lists.unshift
224
- other.to_a.dup </span><span class="marked1"><a name="line36"></a> 36
225
- @tot_iter *= @lists[-1].size </span><span class="marked0"><a
226
- name="line37"></a> 37 self </span><span class="inferred1"><a
227
- name="line38"></a> 38 end </span><span class="inferred0"><a
228
- name="line39"></a> 39 </span><span class="marked1"><a name="line40"></a> 40
229
- def product(other) </span><span class="marked0"><a name="line41"></a> 41
230
- (result = self.dup).product!(other) </span><span class="marked1"><a
231
- name="line42"></a> 42 result </span><span class="inferred0"><a
232
- name="line43"></a> 43 end </span><span class="marked1"><a name="line44"></a>
233
- 44 alias right_product product </span><span class="marked0"><a
234
- name="line45"></a> 45 alias x product </span><span class="inferred1"><a
235
- name="line46"></a> 46 </span><span class="marked0"><a name="line47"></a> 47
236
- def left_product(other) </span><span class="marked1"><a name="line48"></a>
237
- 48 (result = self.dup).left_product!(other) </span><span class="marked0"><a
238
- name="line49"></a> 49 result </span><span class="inferred1"><a
239
- name="line50"></a> 50 end </span><span class="inferred0"><a
240
- name="line51"></a> 51 </span><span class="marked1"><a name="line52"></a> 52
241
- def each </span><span class="marked0"><a name="line53"></a> 53 return false
242
- if @tot_iter &lt; 1 </span><span class="inferred1"><a name="line54"></a> 54
243
- </span><span class="marked0"><a name="line55"></a> 55 elems = []
244
- </span><span class="marked1"><a name="line56"></a> 56 for list in @lists
245
- </span><span class="marked0"><a name="line57"></a> 57 elems &lt;&lt;
246
- list.restart_and_raw_next </span><span class="inferred1"><a
247
- name="line58"></a> 58 end </span><span class="marked0"><a name="line59"></a>
248
- 59 yield *elems </span><span class="inferred1"><a name="line60"></a> 60
249
- </span><span class="marked0"><a name="line61"></a> 61 last_list_index =
250
- @lists.size-1 </span><span class="marked1"><a name="line62"></a> 62 n =
251
- last_list_index </span><span class="marked0"><a name="line63"></a> 63 loop
252
- do </span><span class="marked1"><a name="line64"></a> 64 if elems[n] =
253
- @lists[n].raw_next </span><span class="marked0"><a name="line65"></a> 65
254
- yield *elems </span><span class="marked1"><a name="line66"></a> 66 n =
255
- last_list_index </span><span class="marked0"><a name="line67"></a> 67 next
256
- </span><span class="marked1"><a name="line68"></a> 68 elsif n &gt; 0
257
- </span><span class="marked0"><a name="line69"></a> 69 elems[n] =
258
- @lists[n].restart_and_raw_next </span><span class="marked1"><a
259
- name="line70"></a> 70 n -= 1 </span><span class="inferred0"><a
260
- name="line71"></a> 71 else </span><span class="marked1"><a
261
- name="line72"></a> 72 return true </span><span class="inferred0"><a
262
- name="line73"></a> 73 end </span><span class="inferred1"><a
263
- name="line74"></a> 74 end </span><span class="inferred0"><a
264
- name="line75"></a> 75 end </span><span class="inferred1"><a
265
- name="line76"></a> 76 </span><span class="marked0"><a name="line77"></a> 77
266
- def to_a </span><span class="marked1"><a name="line78"></a> 78 array = []
267
- </span><span class="marked0"><a name="line79"></a> 79 self.each {|*element|
268
- array &lt;&lt; element } </span><span class="marked1"><a name="line80"></a>
269
- 80 array </span><span class="inferred0"><a name="line81"></a> 81 end
270
- </span><span class="inferred1"><a name="line82"></a> 82 </span><span
271
- class="inferred0"><a name="line83"></a> 83 end </span><span
272
- class="inferred1"><a name="line84"></a> 84 </span><span class="marked0"><a
273
- name="line85"></a> 85 module Iterable </span><span class="marked1"><a
274
- name="line86"></a> 86 def restart </span><span class="marked0"><a
275
- name="line87"></a> 87 @next_index = -1 </span><span class="marked1"><a
276
- name="line88"></a> 88 true </span><span class="inferred0"><a
277
- name="line89"></a> 89 end </span><span class="marked1"><a name="line90"></a>
278
- 90 alias start restart </span><span class="inferred0"><a name="line91"></a>
279
- 91 </span><span class="marked1"><a name="line92"></a> 92 def next
280
- </span><span class="marked0"><a name="line93"></a> 93 @next_index or restart
281
- </span><span class="marked1"><a name="line94"></a> 94 raw_next </span><span
282
- class="inferred0"><a name="line95"></a> 95 end </span><span
283
- class="inferred1"><a name="line96"></a> 96 </span><span class="marked0"><a
284
- name="line97"></a> 97 def raw_next </span><span class="marked1"><a
285
- name="line98"></a> 98 self[@next_index += 1] </span><span
286
- class="inferred0"><a name="line99"></a> 99 end </span><span
287
- class="inferred1"><a name="line100"></a>100 </span><span class="marked0"><a
288
- name="line101"></a>101 def restart_and_raw_next </span><span
289
- class="marked1"><a name="line102"></a>102 self[@next_index = 0] </span><span
290
- class="inferred0"><a name="line103"></a>103 end </span><span
291
- class="inferred1"><a name="line104"></a>104 end </span><span
292
- class="inferred0"><a name="line105"></a>105 </span><span class="marked1"><a
293
- name="line106"></a>106 class Array </span><span class="marked0"><a
294
- name="line107"></a>107 include Iterable </span><span class="inferred1"><a
295
- name="line108"></a>108 end </span></pre>
296
- <hr />
297
- <p> Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'> rcov
298
- code coverage analysis tool for Ruby </a> version 0.8.1.2. </p>
299
- <p>
300
- <a href='http://validator.w3.org/check/referer'>
301
- <img src='http://www.w3.org/Icons/valid-xhtml10' height='31' alt='Valid XHTML 1.0!' width='88' />
302
- </a>
303
- <a href='http://jigsaw.w3.org/css-validator/check/referer'>
304
- <img src='http://jigsaw.w3.org/css-validator/images/vcss' alt='Valid CSS!' style='border:0;width:88px;height:31px' />
305
- </a>
306
- </p>
307
- </body>
308
- </html>
@@ -1,384 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
- <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
3
- <head>
4
- <title>
5
- /home/adriano/software/ruby/Cartesian/lib/cartesian.rb - C0 code coverage
6
- information
7
- </title>
8
- <style type='text/css'>
9
- body { background-color: rgb(240, 240, 245); }
10
- </style>
11
- <style type='text/css'>
12
- span.cross-ref-title { font-size: 140%; } span.cross-ref a {
13
- text-decoration: none; } span.cross-ref { background-color:#f3f7fa;
14
- border: 1px dashed #333; margin: 1em; padding: 0.5em; overflow: hidden; }
15
- a.crossref-toggle { text-decoration: none; } span.marked0 {
16
- background-color: rgb(185, 210, 200); display: block; } span.marked1 {
17
- background-color: rgb(190, 215, 205); display: block; } span.inferred0 {
18
- background-color: rgb(175, 200, 200); display: block; } span.inferred1 {
19
- background-color: rgb(180, 205, 205); display: block; } span.uncovered0 {
20
- background-color: rgb(225, 110, 110); display: block; } span.uncovered1 {
21
- background-color: rgb(235, 120, 120); display: block; } span.overview {
22
- border-bottom: 8px solid black; } div.overview { border-bottom: 8px solid
23
- black; } body { font-family: verdana, arial, helvetica; } div.footer {
24
- font-size: 68%; margin-top: 1.5em; } h1, h2, h3, h4, h5, h6 {
25
- margin-bottom: 0.5em; } h5 { margin-top: 0.5em; } .hidden { display: none;
26
- } div.separator { height: 10px; } /* Commented out for better readability,
27
- esp. on IE */ /* table tr td, table tr th { font-size: 68%; } td.value
28
- table tr td { font-size: 11px; } */ table.percent_graph { height: 12px;
29
- border: #808080 1px solid; empty-cells: show; } table.percent_graph
30
- td.covered { height: 10px; background: #00f000; } table.percent_graph
31
- td.uncovered { height: 10px; background: #e00000; } table.percent_graph
32
- td.NA { height: 10px; background: #eaeaea; } table.report {
33
- border-collapse: collapse; width: 100%; } table.report td.heading {
34
- background: #dcecff; border: #d0d0d0 1px solid; font-weight: bold;
35
- text-align: center; } table.report td.heading:hover { background: #c0ffc0;
36
- } table.report td.text { border: #d0d0d0 1px solid; } table.report
37
- td.value, table.report td.lines_total, table.report td.lines_code {
38
- text-align: right; border: #d0d0d0 1px solid; } table.report tr.light {
39
- background-color: rgb(240, 240, 245); } table.report tr.dark {
40
- background-color: rgb(230, 230, 235); }
41
- </style>
42
- <script type='text/javascript'>
43
- // <![CDATA[ function toggleCode( id ) { if ( document.getElementById )
44
- elem = document.getElementById( id ); else if ( document.all ) elem =
45
- eval( "document.all." + id ); else return false; elemStyle = elem.style;
46
- if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else {
47
- elemStyle.display = "none" } return true; } // Make cross-references
48
- hidden by default document.writeln( "<style
49
- type=\"text/css\">span.cross-ref { display: none }</style>" ) // ]]>
50
- </script>
51
- <style type='text/css'>
52
- span.run0 { background-color: rgb(178, 204, 255); display: block; }
53
- span.run1 { background-color: rgb(178, 206, 255); display: block; }
54
- span.run2 { background-color: rgb(178, 209, 255); display: block; }
55
- span.run3 { background-color: rgb(178, 211, 255); display: block; }
56
- span.run4 { background-color: rgb(178, 214, 255); display: block; }
57
- span.run5 { background-color: rgb(178, 218, 255); display: block; }
58
- span.run6 { background-color: rgb(178, 220, 255); display: block; }
59
- span.run7 { background-color: rgb(178, 223, 255); display: block; }
60
- span.run8 { background-color: rgb(178, 225, 255); display: block; }
61
- span.run9 { background-color: rgb(178, 228, 255); display: block; }
62
- span.run10 { background-color: rgb(178, 232, 255); display: block; }
63
- span.run11 { background-color: rgb(178, 234, 255); display: block; }
64
- span.run12 { background-color: rgb(178, 237, 255); display: block; }
65
- span.run13 { background-color: rgb(178, 239, 255); display: block; }
66
- span.run14 { background-color: rgb(178, 242, 255); display: block; }
67
- span.run15 { background-color: rgb(178, 246, 255); display: block; }
68
- span.run16 { background-color: rgb(178, 248, 255); display: block; }
69
- span.run17 { background-color: rgb(178, 251, 255); display: block; }
70
- span.run18 { background-color: rgb(178, 253, 255); display: block; }
71
- span.run19 { background-color: rgb(178, 255, 253); display: block; }
72
- span.run20 { background-color: rgb(178, 255, 249); display: block; }
73
- span.run21 { background-color: rgb(178, 255, 247); display: block; }
74
- span.run22 { background-color: rgb(178, 255, 244); display: block; }
75
- span.run23 { background-color: rgb(178, 255, 242); display: block; }
76
- span.run24 { background-color: rgb(178, 255, 239); display: block; }
77
- span.run25 { background-color: rgb(178, 255, 235); display: block; }
78
- span.run26 { background-color: rgb(178, 255, 233); display: block; }
79
- span.run27 { background-color: rgb(178, 255, 230); display: block; }
80
- span.run28 { background-color: rgb(178, 255, 228); display: block; }
81
- span.run29 { background-color: rgb(178, 255, 225); display: block; }
82
- span.run30 { background-color: rgb(178, 255, 221); display: block; }
83
- span.run31 { background-color: rgb(178, 255, 219); display: block; }
84
- span.run32 { background-color: rgb(178, 255, 216); display: block; }
85
- span.run33 { background-color: rgb(178, 255, 214); display: block; }
86
- span.run34 { background-color: rgb(178, 255, 211); display: block; }
87
- span.run35 { background-color: rgb(178, 255, 207); display: block; }
88
- span.run36 { background-color: rgb(178, 255, 205); display: block; }
89
- span.run37 { background-color: rgb(178, 255, 202); display: block; }
90
- span.run38 { background-color: rgb(178, 255, 200); display: block; }
91
- span.run39 { background-color: rgb(178, 255, 197); display: block; }
92
- span.run40 { background-color: rgb(178, 255, 193); display: block; }
93
- span.run41 { background-color: rgb(178, 255, 191); display: block; }
94
- span.run42 { background-color: rgb(178, 255, 188); display: block; }
95
- span.run43 { background-color: rgb(178, 255, 186); display: block; }
96
- span.run44 { background-color: rgb(178, 255, 183); display: block; }
97
- span.run45 { background-color: rgb(178, 255, 179); display: block; }
98
- span.run46 { background-color: rgb(179, 255, 178); display: block; }
99
- span.run47 { background-color: rgb(182, 255, 178); display: block; }
100
- span.run48 { background-color: rgb(184, 255, 178); display: block; }
101
- span.run49 { background-color: rgb(187, 255, 178); display: block; }
102
- span.run50 { background-color: rgb(191, 255, 178); display: block; }
103
- span.run51 { background-color: rgb(193, 255, 178); display: block; }
104
- span.run52 { background-color: rgb(196, 255, 178); display: block; }
105
- span.run53 { background-color: rgb(198, 255, 178); display: block; }
106
- span.run54 { background-color: rgb(201, 255, 178); display: block; }
107
- span.run55 { background-color: rgb(205, 255, 178); display: block; }
108
- span.run56 { background-color: rgb(207, 255, 178); display: block; }
109
- span.run57 { background-color: rgb(210, 255, 178); display: block; }
110
- span.run58 { background-color: rgb(212, 255, 178); display: block; }
111
- span.run59 { background-color: rgb(215, 255, 178); display: block; }
112
- span.run60 { background-color: rgb(219, 255, 178); display: block; }
113
- span.run61 { background-color: rgb(221, 255, 178); display: block; }
114
- span.run62 { background-color: rgb(224, 255, 178); display: block; }
115
- span.run63 { background-color: rgb(226, 255, 178); display: block; }
116
- span.run64 { background-color: rgb(229, 255, 178); display: block; }
117
- span.run65 { background-color: rgb(233, 255, 178); display: block; }
118
- span.run66 { background-color: rgb(235, 255, 178); display: block; }
119
- span.run67 { background-color: rgb(238, 255, 178); display: block; }
120
- span.run68 { background-color: rgb(240, 255, 178); display: block; }
121
- span.run69 { background-color: rgb(243, 255, 178); display: block; }
122
- span.run70 { background-color: rgb(247, 255, 178); display: block; }
123
- span.run71 { background-color: rgb(249, 255, 178); display: block; }
124
- span.run72 { background-color: rgb(252, 255, 178); display: block; }
125
- span.run73 { background-color: rgb(255, 255, 178); display: block; }
126
- span.run74 { background-color: rgb(255, 252, 178); display: block; }
127
- span.run75 { background-color: rgb(255, 248, 178); display: block; }
128
- span.run76 { background-color: rgb(255, 246, 178); display: block; }
129
- span.run77 { background-color: rgb(255, 243, 178); display: block; }
130
- span.run78 { background-color: rgb(255, 240, 178); display: block; }
131
- span.run79 { background-color: rgb(255, 238, 178); display: block; }
132
- span.run80 { background-color: rgb(255, 234, 178); display: block; }
133
- span.run81 { background-color: rgb(255, 232, 178); display: block; }
134
- span.run82 { background-color: rgb(255, 229, 178); display: block; }
135
- span.run83 { background-color: rgb(255, 226, 178); display: block; }
136
- span.run84 { background-color: rgb(255, 224, 178); display: block; }
137
- span.run85 { background-color: rgb(255, 220, 178); display: block; }
138
- span.run86 { background-color: rgb(255, 218, 178); display: block; }
139
- span.run87 { background-color: rgb(255, 215, 178); display: block; }
140
- span.run88 { background-color: rgb(255, 212, 178); display: block; }
141
- span.run89 { background-color: rgb(255, 210, 178); display: block; }
142
- span.run90 { background-color: rgb(255, 206, 178); display: block; }
143
- span.run91 { background-color: rgb(255, 204, 178); display: block; }
144
- span.run92 { background-color: rgb(255, 201, 178); display: block; }
145
- span.run93 { background-color: rgb(255, 198, 178); display: block; }
146
- span.run94 { background-color: rgb(255, 196, 178); display: block; }
147
- span.run95 { background-color: rgb(255, 192, 178); display: block; }
148
- span.run96 { background-color: rgb(255, 189, 178); display: block; }
149
- span.run97 { background-color: rgb(255, 187, 178); display: block; }
150
- span.run98 { background-color: rgb(255, 184, 178); display: block; }
151
- span.run99 { background-color: rgb(255, 182, 178); display: block; }
152
- span.run100 { background-color: rgb(255, 178, 178); display: block; }
153
- </style>
154
- </head>
155
- <body>
156
- <h3>
157
- C0 code coverage information
158
- </h3>
159
- <p>
160
- Generated on Tue Nov 04 04:48:28 -0200 2008 with
161
- <a href='http://eigenclass.org/hiki/rcov'>
162
- rcov 0.8.1.2
163
- </a>
164
- </p>
165
- <hr />
166
- <pre><span class='marked0'>Code reported as executed by Ruby looks like
167
- this... </span><span class='marked1'>and this: this line is also marked as
168
- covered. </span><span class='inferred0'>Lines considered as run by rcov, but
169
- not reported by Ruby, look like this, </span><span class='inferred1'>and
170
- this: these lines were inferred by rcov (using simple heuristics).
171
- </span><span class='uncovered0'>Finally, here&apos;s a line marked as not
172
- executed. </span></pre>
173
- <table class='report'> <thead> <tr> <td class='heading'> Name </td> <td
174
- class='heading'> Total lines </td> <td class='heading'> Lines of code </td>
175
- <td class='heading'> Total coverage </td> <td class='heading'> Code coverage
176
- </td> </tr> </thead> <tbody> <tr class='light'> <td> <a
177
- href='-home-adriano-software-ruby-Cartesian-lib-cartesian_rb.html'>
178
- /home/adriano/software/ruby/Cartesian/lib/cartesian.rb </a> </td> <td
179
- class='lines_total'> <tt> 161 </tt> </td> <td class='lines_code'> <tt> 52
180
- </tt> </td> <td> <table cellspacing='0' align='right' cellpadding='0'> <tr>
181
- <td> <tt class='coverage_total'> 100.0% </tt> &nbsp; </td> <td> <table
182
- class='percent_graph' cellspacing='0' width='100' cellpadding='0'> <tr> <td
183
- class='covered' width='100' /> <td class='uncovered' width='0' /> </tr>
184
- </table> </td> </tr> </table> </td> <td> <table cellspacing='0'
185
- align='right' cellpadding='0'> <tr> <td> <tt class='coverage_code'> 100.0%
186
- </tt> &nbsp; </td> <td> <table class='percent_graph' cellspacing='0'
187
- width='100' cellpadding='0'> <tr> <td class='covered' width='100' /> <td
188
- class='uncovered' width='0' /> </tr> </table> </td> </tr> </table> </td>
189
- </tr> </tbody> </table><pre><span class="inferred1"><a name="line1"></a> 1 #
190
- </span><span class="inferred0"><a name="line2"></a> 2 # The CartesianProduct
191
- module provide methods for the calculation </span><span class="inferred1"><a
192
- name="line3"></a> 3 # of the cartesian producted between two enumberable
193
- objects. </span><span class="inferred0"><a name="line4"></a> 4 #
194
- </span><span class="inferred1"><a name="line5"></a> 5 # It can also be
195
- easily mixed in into any enumberable class, </span><span
196
- class="inferred0"><a name="line6"></a> 6 # i.e. any class with Enumerable
197
- module mixed in. </span><span class="inferred1"><a name="line7"></a> 7 #
198
- Notice that the names of the methods for mixin are different. </span><span
199
- class="inferred0"><a name="line8"></a> 8 # </span><span class="inferred1"><a
200
- name="line9"></a> 9 # Module: </span><span class="inferred0"><a
201
- name="line10"></a> 10 # Cartesian::product(foo, bar) </span><span
202
- class="inferred1"><a name="line11"></a> 11 # </span><span
203
- class="inferred0"><a name="line12"></a> 12 # Mixin: </span><span
204
- class="inferred1"><a name="line13"></a> 13 # foo.cartesian( bar )
205
- </span><span class="inferred0"><a name="line14"></a> 14 # </span><span
206
- class="inferred1"><a name="line15"></a> 15 # The module is automatically
207
- mixed in Array class. </span><span class="inferred0"><a name="line16"></a>
208
- 16 # </span><span class="inferred1"><a name="line17"></a> 17 # == Author
209
- </span><span class="inferred0"><a name="line18"></a> 18 # Adriano MITRE
210
- &lt;adriano.mitre@gmail.com&gt; </span><span class="inferred1"><a
211
- name="line19"></a> 19 # </span><span class="inferred0"><a name="line20"></a>
212
- 20 # == Example </span><span class="inferred1"><a name="line21"></a> 21 #
213
- </span><span class="inferred0"><a name="line22"></a> 22 # as module
214
- </span><span class="inferred1"><a name="line23"></a> 23 # require
215
- 'cartesian' </span><span class="inferred0"><a name="line24"></a> 24 # foo =
216
- [1, 2] </span><span class="inferred1"><a name="line25"></a> 25 # bar =
217
- [&quot;a&quot;, &quot;b&quot;] </span><span class="inferred0"><a
218
- name="line26"></a> 26 # Cartesian::product(foo, bar) #=&gt; [[1,
219
- &quot;a&quot;], [1, &quot;b&quot;], [2, &quot;a&quot;], [2, &quot;b&quot;]]
220
- </span><span class="inferred1"><a name="line27"></a> 27 # as mixin
221
- </span><span class="inferred0"><a name="line28"></a> 28 # require
222
- 'cartesian' </span><span class="inferred1"><a name="line29"></a> 29 # foo =
223
- [1, 2] </span><span class="inferred0"><a name="line30"></a> 30 # bar =
224
- [&quot;a&quot;, &quot;b&quot;] </span><span class="inferred1"><a
225
- name="line31"></a> 31 # foo.cartesian(bar) #=&gt; [[1, &quot;a&quot;], [1,
226
- &quot;b&quot;], [2, &quot;a&quot;], [2, &quot;b&quot;]] </span><span
227
- class="inferred0"><a name="line32"></a> 32 # </span><span
228
- class="inferred1"><a name="line33"></a> 33 </span><span class="marked0"><a
229
- name="line34"></a> 34 require 'cartesian_iterator' </span><span
230
- class="inferred1"><a name="line35"></a> 35 </span><span class="marked0"><a
231
- name="line36"></a> 36 module Cartesian </span><span class="inferred1"><a
232
- name="line37"></a> 37 </span><span class="inferred0"><a name="line38"></a>
233
- 38 # Produces the cartesian product of self and other. </span><span
234
- class="inferred1"><a name="line39"></a> 39 # The result is an array of pairs
235
- (i.e. two-element arrays). </span><span class="inferred0"><a
236
- name="line40"></a> 40 # </span><span class="inferred1"><a name="line41"></a>
237
- 41 # Cartesian::product( [1,2], %w(A B) ) #=&gt; [[1, &quot;A&quot;], [1,
238
- &quot;B&quot;], [2, &quot;A&quot;], [2, &quot;B&quot;]] </span><span
239
- class="inferred0"><a name="line42"></a> 42 # </span><span
240
- class="inferred1"><a name="line43"></a> 43 # or, if mixed in into Array,
241
- </span><span class="inferred0"><a name="line44"></a> 44 # </span><span
242
- class="inferred1"><a name="line45"></a> 45 # [1,2].cartesian %w(A B) #=&gt;
243
- [[1, &quot;A&quot;], [1, &quot;B&quot;], [2, &quot;A&quot;], [2,
244
- &quot;B&quot;]] </span><span class="inferred0"><a name="line46"></a> 46 #
245
- </span><span class="marked1"><a name="line47"></a> 47 def
246
- Cartesian.product(first, second) </span><span class="marked0"><a
247
- name="line48"></a> 48 first.x(second).to_a </span><span class="inferred1"><a
248
- name="line49"></a> 49 end </span><span class="inferred0"><a
249
- name="line50"></a> 50 </span><span class="inferred1"><a name="line51"></a>
250
- 51 # Behaves as product, except for the elements are joined. </span><span
251
- class="inferred0"><a name="line52"></a> 52 # </span><span
252
- class="inferred1"><a name="line53"></a> 53 # Cartesian::joined_cartesian(
253
- [1,2], %w(A B) ) #=&gt; [&quot;1A&quot;, &quot;1B&quot;, &quot;2A&quot;,
254
- &quot;2B&quot;] </span><span class="inferred0"><a name="line54"></a> 54 #
255
- </span><span class="inferred1"><a name="line55"></a> 55 # or, if mixed in
256
- into Array, </span><span class="inferred0"><a name="line56"></a> 56 #
257
- </span><span class="inferred1"><a name="line57"></a> 57 #
258
- [1,2].joined_cartesian %w(A B) #=&gt; [&quot;1A&quot;, &quot;1B&quot;,
259
- &quot;2A&quot;, &quot;2B&quot;] </span><span class="inferred0"><a
260
- name="line58"></a> 58 # </span><span class="marked1"><a name="line59"></a>
261
- 59 def Cartesian.joined_product(first, second) </span><span
262
- class="marked0"><a name="line60"></a> 60 product(first, second).map {|pair|
263
- pair.join } </span><span class="inferred1"><a name="line61"></a> 61 end
264
- </span><span class="inferred0"><a name="line62"></a> 62 </span><span
265
- class="inferred1"><a name="line63"></a> 63 # Cartesian.joined_product for
266
- mixin. </span><span class="inferred0"><a name="line64"></a> 64 #
267
- </span><span class="marked1"><a name="line65"></a> 65 def
268
- joined_cartesian(other) </span><span class="marked0"><a name="line66"></a>
269
- 66 Cartesian.joined_product(self, other) </span><span class="inferred1"><a
270
- name="line67"></a> 67 end </span><span class="inferred0"><a
271
- name="line68"></a> 68 </span><span class="inferred1"><a name="line69"></a>
272
- 69 # Convenient way of iterating over the elements. </span><span
273
- class="inferred0"><a name="line70"></a> 70 # Preferable when the cartesian
274
- product array </span><span class="inferred1"><a name="line71"></a> 71 # is
275
- not needed, for the consumption of memory </span><span class="inferred0"><a
276
- name="line72"></a> 72 # is fixed and very small, in contrast with the
277
- </span><span class="inferred1"><a name="line73"></a> 73 # exponential memory
278
- requirements of the </span><span class="inferred0"><a name="line74"></a> 74
279
- # conventional approach. </span><span class="inferred1"><a
280
- name="line75"></a> 75 # </span><span class="inferred0"><a name="line76"></a>
281
- 76 # for row, col in (1..10).x(1..30) </span><span class="inferred1"><a
282
- name="line77"></a> 77 # Matrix[row, col] = row**2 + col**3 </span><span
283
- class="inferred0"><a name="line78"></a> 78 # end </span><span
284
- class="inferred1"><a name="line79"></a> 79 # </span><span
285
- class="inferred0"><a name="line80"></a> 80 # Of course, calls can be chained
286
- as in </span><span class="inferred1"><a name="line81"></a> 81 # </span><span
287
- class="inferred0"><a name="line82"></a> 82 # for x, y, z in
288
- (1..10).x(1..10).x(1..10) </span><span class="inferred1"><a
289
- name="line83"></a> 83 # # ... do something ... </span><span
290
- class="inferred0"><a name="line84"></a> 84 # end </span><span
291
- class="inferred1"><a name="line85"></a> 85 # </span><span
292
- class="inferred0"><a name="line86"></a> 86 #-- </span><span
293
- class="inferred1"><a name="line87"></a> 87 # for letter, number in %w{a b
294
- c}.x(1..3) </span><span class="inferred0"><a name="line88"></a> 88 # ... do
295
- something ... </span><span class="inferred1"><a name="line89"></a> 89 # end
296
- </span><span class="inferred0"><a name="line90"></a> 90 #++ </span><span
297
- class="inferred1"><a name="line91"></a> 91 # </span><span
298
- class="inferred0"><a name="line92"></a> 92 # Beware that both +self+ and
299
- +other+ must implement </span><span class="inferred1"><a name="line93"></a>
300
- 93 # +to_a+, i.e., be convertible to array. </span><span
301
- class="inferred0"><a name="line94"></a> 94 # </span><span class="marked1"><a
302
- name="line95"></a> 95 def x(other) </span><span class="marked0"><a
303
- name="line96"></a> 96 case other </span><span class="marked1"><a
304
- name="line97"></a> 97 when CartesianIterator </span><span
305
- class="inferred0"><a name="line98"></a> 98 other.left_product(self)
306
- </span><span class="inferred1"><a name="line99"></a> 99 else </span><span
307
- class="marked0"><a name="line100"></a>100 CartesianIterator.new(self, other)
308
- </span><span class="inferred1"><a name="line101"></a>101 end </span><span
309
- class="inferred0"><a name="line102"></a>102 end </span><span
310
- class="marked1"><a name="line103"></a>103 alias cartesian x </span><span
311
- class="marked0"><a name="line104"></a>104 alias right_product x </span><span
312
- class="inferred1"><a name="line105"></a>105 </span><span class="marked0"><a
313
- name="line106"></a>106 def left_product(other) </span><span
314
- class="marked1"><a name="line107"></a>107 case other </span><span
315
- class="marked0"><a name="line108"></a>108 when CartesianIterator
316
- </span><span class="inferred1"><a name="line109"></a>109
317
- other.right_product(self) </span><span class="inferred0"><a
318
- name="line110"></a>110 else </span><span class="marked1"><a
319
- name="line111"></a>111 CartesianIterator.new(other, self) </span><span
320
- class="inferred0"><a name="line112"></a>112 end </span><span
321
- class="inferred1"><a name="line113"></a>113 end </span><span
322
- class="inferred0"><a name="line114"></a>114 </span><span
323
- class="inferred1"><a name="line115"></a>115 # Concise way of iterating
324
- multi-dimensionally </span><span class="inferred0"><a name="line116"></a>116
325
- # over the same array or range. </span><span class="inferred1"><a
326
- name="line117"></a>117 # </span><span class="inferred0"><a
327
- name="line118"></a>118 # For instance, </span><span class="inferred1"><a
328
- name="line119"></a>119 # </span><span class="inferred0"><a
329
- name="line120"></a>120 # for x,y,z in [0,1]**3 </span><span
330
- class="inferred1"><a name="line121"></a>121 # puts [x, y, z].join(',')
331
- </span><span class="inferred0"><a name="line122"></a>122 # end </span><span
332
- class="inferred1"><a name="line123"></a>123 # </span><span
333
- class="inferred0"><a name="line124"></a>124 # produces the following output
334
- </span><span class="inferred1"><a name="line125"></a>125 # </span><span
335
- class="inferred0"><a name="line126"></a>126 # 0,0,0 </span><span
336
- class="inferred1"><a name="line127"></a>127 # 0,0,1 </span><span
337
- class="inferred0"><a name="line128"></a>128 # 0,1,0 </span><span
338
- class="inferred1"><a name="line129"></a>129 # 0,1,1 </span><span
339
- class="inferred0"><a name="line130"></a>130 # 1,0,0 </span><span
340
- class="inferred1"><a name="line131"></a>131 # 1,0,1 </span><span
341
- class="inferred0"><a name="line132"></a>132 # 1,1,0 </span><span
342
- class="inferred1"><a name="line133"></a>133 # 1,1,1 </span><span
343
- class="inferred0"><a name="line134"></a>134 # </span><span
344
- class="inferred1"><a name="line135"></a>135 # It also works with Range
345
- objects. </span><span class="inferred0"><a name="line136"></a>136 #
346
- </span><span class="marked1"><a name="line137"></a>137 def **(fixnum)
347
- </span><span class="marked0"><a name="line138"></a>138 if fixnum &lt; 0
348
- </span><span class="marked1"><a name="line139"></a>139 raise ArgumentError,
349
- &quot;negative power&quot; </span><span class="marked0"><a
350
- name="line140"></a>140 elsif fixnum == 0 </span><span class="marked1"><a
351
- name="line141"></a>141 return [] </span><span class="marked0"><a
352
- name="line142"></a>142 elsif fixnum == 1 </span><span class="marked1"><a
353
- name="line143"></a>143 return self </span><span class="inferred0"><a
354
- name="line144"></a>144 else </span><span class="marked1"><a
355
- name="line145"></a>145 iter = CartesianIterator.new(self, self) </span><span
356
- class="marked0"><a name="line146"></a>146 (fixnum-2).times do </span><span
357
- class="marked1"><a name="line147"></a>147 iter.product!(self) </span><span
358
- class="inferred0"><a name="line148"></a>148 end </span><span
359
- class="marked1"><a name="line149"></a>149 iter </span><span
360
- class="inferred0"><a name="line150"></a>150 end </span><span
361
- class="inferred1"><a name="line151"></a>151 end </span><span
362
- class="marked0"><a name="line152"></a>152 alias :power! :** </span><span
363
- class="inferred1"><a name="line153"></a>153 end </span><span
364
- class="inferred0"><a name="line154"></a>154 </span><span class="marked1"><a
365
- name="line155"></a>155 class Array </span><span class="marked0"><a
366
- name="line156"></a>156 include Cartesian </span><span class="inferred1"><a
367
- name="line157"></a>157 end </span><span class="inferred0"><a
368
- name="line158"></a>158 </span><span class="marked1"><a
369
- name="line159"></a>159 class Range </span><span class="marked0"><a
370
- name="line160"></a>160 include Cartesian </span><span class="inferred1"><a
371
- name="line161"></a>161 end </span></pre>
372
- <hr />
373
- <p> Generated using the <a href='http://eigenclass.org/hiki.rb?rcov'> rcov
374
- code coverage analysis tool for Ruby </a> version 0.8.1.2. </p>
375
- <p>
376
- <a href='http://validator.w3.org/check/referer'>
377
- <img src='http://www.w3.org/Icons/valid-xhtml10' height='31' alt='Valid XHTML 1.0!' width='88' />
378
- </a>
379
- <a href='http://jigsaw.w3.org/css-validator/check/referer'>
380
- <img src='http://jigsaw.w3.org/css-validator/images/vcss' alt='Valid CSS!' style='border:0;width:88px;height:31px' />
381
- </a>
382
- </p>
383
- </body>
384
- </html>