lib/flay.rb in flay-2.9.0 vs lib/flay.rb in flay-2.10.0

- old
+ new

@@ -14,11 +14,11 @@ alias :binread :read unless RUBY19 end end class Flay - VERSION = "2.9.0" # :nodoc: + VERSION = "2.10.0" # :nodoc: class Item < Struct.new(:structural_hash, :name, :bonus, :mass, :locations) alias identical? bonus end @@ -326,20 +326,41 @@ end end end ## + # Given an array of sexp patterns (see sexp_processor), delete any + # buckets whose members match any of the patterns. + + def filter *patterns + return if patterns.empty? + + self.hashes.delete_if { |_, sexps| + sexps.any? { |sexp| + patterns.any? { |pattern| + pattern =~ sexp + } + } + } + end + + ## # Prunes nodes that aren't relevant to analysis or are already - # covered by another node. + # covered by another node. Also deletes nodes based on the + # +:filters+ option. def prune # prune trees that aren't duped at all, or are too small self.hashes.delete_if { |_,nodes| nodes.size == 1 } self.hashes.delete_if { |_,nodes| nodes.all?(&:modified?) } - return prune_liberally if option[:liberal] + if option[:liberal] then + prune_liberally + else + prune_conservatively + end - prune_conservatively + self.filter(*option[:filters]) end ## # Conservative prune. Remove any bucket that is known to contain a # subnode element of a node in another bucket.