Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/fp_growth/inflections.rb
Instance Method Summary collapse
- #content_equal?(other) ⇒ Boolean
-
#is_real_subset_of?(other) ⇒ Boolean
TODO faster.
-
#is_subset_of?(other) ⇒ Boolean
TODO faster.
-
#is_superset_of?(other) ⇒ Boolean
TODO faster.
- #parts(allow_empty = false) ⇒ Object
-
#subsets(include_empty = false, just_real = false, ranks = nil) ⇒ Object
modified from branch14.org/snippets/subsets_in_ruby.html.
Instance Method Details
#content_equal?(other) ⇒ Boolean
67 68 69 70 71 72 73 74 75 |
# File 'lib/fp_growth/inflections.rb', line 67 def content_equal?(other) return false if other.size != size each do |item| return false if !other.find { |other_item| item.respond_to?(:content_equal?) ? item.content_equal?(other_item) : item == other_item } end true end |
#is_real_subset_of?(other) ⇒ Boolean
TODO faster
57 58 59 |
# File 'lib/fp_growth/inflections.rb', line 57 def is_real_subset_of?(other) other.subsets(false, true).find { |subset| content_equal?(subset) } end |
#is_subset_of?(other) ⇒ Boolean
TODO faster
52 53 54 |
# File 'lib/fp_growth/inflections.rb', line 52 def is_subset_of?(other) other.subsets.find { |subset| content_equal?(subset) } end |
#is_superset_of?(other) ⇒ Boolean
TODO faster
47 48 49 |
# File 'lib/fp_growth/inflections.rb', line 47 def is_superset_of?(other) subsets(false, true).find { |subset| other.content_equal?(subset) } end |
#parts(allow_empty = false) ⇒ Object
61 62 63 64 65 |
# File 'lib/fp_growth/inflections.rb', line 61 def parts(allow_empty = false) subsets(allow_empty, !allow_empty).collect do |subset| [ subset, self - subset] end end |
#subsets(include_empty = false, just_real = false, ranks = nil) ⇒ Object
modified from branch14.org/snippets/subsets_in_ruby.html
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fp_growth/inflections.rb', line 20 def subsets(include_empty = false, just_real = false, ranks = nil) result = all_subsets result.shift unless include_empty result.pop if just_real if ranks result = result.select do |i| if ranks.respond_to?(:include?) ranks.include?(i.size) else ranks == i.size end end end result end |