Cache ItemSet#leading_item_sets return values - #28
This commit is contained in:
parent
5f1c306273
commit
588c5e21c7
@ -99,21 +99,24 @@ class Propane
|
|||||||
# @return [Set<ItemSet>]
|
# @return [Set<ItemSet>]
|
||||||
# Set of all ItemSets that lead up to this ItemSet.
|
# Set of all ItemSets that lead up to this ItemSet.
|
||||||
def leading_item_sets
|
def leading_item_sets
|
||||||
result = Set.new
|
@_leading_item_sets ||=
|
||||||
eval_sets = Set[self]
|
begin
|
||||||
evaled = Set.new
|
result = Set.new
|
||||||
while eval_sets.size > 0
|
eval_sets = Set[self]
|
||||||
eval_set = eval_sets.first
|
evaled = Set.new
|
||||||
eval_sets.delete(eval_set)
|
while eval_sets.size > 0
|
||||||
evaled << eval_set
|
eval_set = eval_sets.first
|
||||||
eval_set.in_sets.each do |in_set|
|
eval_sets.delete(eval_set)
|
||||||
result << in_set
|
evaled << eval_set
|
||||||
unless evaled.include?(in_set)
|
eval_set.in_sets.each do |in_set|
|
||||||
eval_sets << in_set
|
result << in_set
|
||||||
|
unless evaled.include?(in_set)
|
||||||
|
eval_sets << in_set
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
result
|
||||||
end
|
end
|
||||||
end
|
|
||||||
result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Represent the ItemSet as a String.
|
# Represent the ItemSet as a String.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user