combinations :: CartesianIterator :: _iterators
The array of iterations that will be increased in the lexicographic order.combinations :: CartesianIterator :: iterators
The array of iterations that will be increased in the lexicographic order.combinations :: CartesianIterator :: iterators=
The array of iterations that will be increased in the lexicographic order.combinations $ CartesianIterator :: SELF
Type of this instance, automatically specialized in every classcombinations :: CartesianIterator :: _iterators
The array of iterations that will be increased in the lexicographic order.core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Iterator :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
combinations :: CartesianIterator :: iterators
The array of iterations that will be increased in the lexicographic order.combinations :: CartesianIterator :: iterators=
The array of iterations that will be increased in the lexicographic order.core :: Object :: native_class_name
The class name of the object in CString format.Iterator
whose elements are sorted by the function
core :: Object :: output_class_name
Display class name on stdout (debug only).
private class CartesianIterator[E]
super Iterator[SequenceRead[E]]
var collection: CartesianCollection[E]
# The array of iterations that will be increased in the lexicographic order.
var iterators = new Array[Iterator[E]]
init
do
for c in collection.collections do
var it = c.iterator
iterators.add it
if not it.is_ok then is_ok = false
end
end
redef var is_ok = true
redef fun item
do
var len = iterators.length
var res = new Array[E].with_capacity(len)
for i in [0..len[ do
var it = iterators[i]
res.add(it.item)
end
return res
end
redef fun next
do
var rank = iterators.length - 1
# Odometer-like increment starting from the last iterator
loop
var it = iterators[rank]
it.next
if it.is_ok then return
# The iterator if over
if rank == 0 then
# It it is the first, then the whole thing is over
is_ok = false
return
end
# If not, restart the iterator and increment the previous one
# (like a carry)
iterators[rank] = collection.collections[rank].iterator
rank -= 1
end
end
end
lib/combinations/combinations.nit:118,1--170,3