Add ItemSet#leading_item_sets

This commit is contained in:
Josh Holtrop 2022-06-14 07:34:35 -04:00
parent d6e5c4325d
commit 8b152abaa7

View File

@ -17,8 +17,8 @@ class Propane
# Maps a following symbol to its ItemSet. # Maps a following symbol to its ItemSet.
attr_reader :following_item_set attr_reader :following_item_set
# @return [Set] # @return [Set<ItemSet>]
# Item sets leading to this item set. # ItemSets leading to this item set.
attr_reader :in_sets attr_reader :in_sets
# Build an ItemSet. # Build an ItemSet.
@ -81,6 +81,18 @@ class Propane
self == other self == other
end end
# Set of ItemSets that lead to this ItemSet.
#
# This set includes this ItemSet.
#
# @return [Set<ItemSet>]
# Set of all ItemSets that lead up to this ItemSet.
def leading_item_sets
@in_sets.reduce(Set[self]) do |result, item_set|
result + item_set.leading_item_sets
end
end
# Represent the ItemSet as a String. # Represent the ItemSet as a String.
# #
# @return [String] # @return [String]