Parent

Included Modules

Files

Class Index [+]

Quicksearch

CartesianIterator

Public Class Methods

new(foo, bar) click to toggle source
   # File lib/cartesian_iterator.rb, line 3
3:   def initialize(foo, bar)
4:     @lists = []
5:     @tot_iter = 1
6:     product!(foo)
7:     product!(bar)
8:   end

Public Instance Methods

==(other) click to toggle source
Alias for: equal
dup() click to toggle source
    # File lib/cartesian_iterator.rb, line 10
10:   def dup
11:     Marshal.load(Marshal.dump(self))
12:   end
each() click to toggle source
    # File lib/cartesian_iterator.rb, line 48
48:   def each
49:     return false if @tot_iter < 1
50: 
51:     elems = []
52:     for list in @lists
53:       elems << list.restart_and_raw_next
54:     end
55:     if RUBY_VERSION <= '1.9.1'; yield(*elems.map {|x| x }); else; yield(*elems); end # Yeah, v.map{|x|x} should be equal to v, but strangely it is NOT in Ruby versions prior to 1.9.2.
56: 
57:     last_list_index = @lists.size-1
58:     n = last_list_index
59:     loop do
60:       if elems[n] = @lists[n].raw_next
61:         if RUBY_VERSION <= '1.9.1'; yield(*elems.map {|x| x }); else; yield(*elems); end # See previous comment.
62:         n = last_list_index
63:         next
64:       elsif n > 0
65:         elems[n] = @lists[n].restart_and_raw_next
66:         n -= 1
67:       else
68:         return true
69:       end
70:     end
71:   end
equal(other) click to toggle source
    # File lib/cartesian_iterator.rb, line 14
14:   def equal(other)
15:     self.instance_variables.each do |var_name|
16:       return false if self.instance_variable_get(var_name) != other.instance_variable_get(var_name)
17:     end
18:     true
19:   end
Also aliased as: ==
left_product(other) click to toggle source
    # File lib/cartesian_iterator.rb, line 43
43:   def left_product(other)
44:     (result = self.dup).left_product!(other)
45:     result
46:   end
left_product!(other) click to toggle source
    # File lib/cartesian_iterator.rb, line 30
30:   def left_product!(other)
31:     @lists.unshift other.to_a.dup
32:     @tot_iter *= @lists[1].size
33:     self
34:   end
product(other) click to toggle source
    # File lib/cartesian_iterator.rb, line 36
36:   def product(other)
37:     (result = self.dup).product!(other)
38:     result
39:   end
Also aliased as: right_product, x
product!(other) click to toggle source
    # File lib/cartesian_iterator.rb, line 22
22:   def product!(other)
23:     @lists << other.to_a.dup
24:     @tot_iter *= @lists[1].size
25:     self
26:   end
Also aliased as: right_product!, x!
right_product(other) click to toggle source
Alias for: product
right_product!(other) click to toggle source
Alias for: product!
x(other) click to toggle source
Alias for: product
x!(other) click to toggle source
Alias for: product!

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.