Sha256: cb3322b0eef94da6ce4e640afa0233100624970f0159cd37fd86e26c285def88
Contents?: true
Size: 1.52 KB
Versions: 396
Compression:
Stored size: 1.52 KB
Contents
class CustomSet attr_reader :data def initialize(input_data = []) @data = parse_data(input_data.to_a.uniq) end def delete(datum) data.each do |n| @data -= Array(n) if n.datum.eql?(datum) end self end def difference(other) shared = nodes - other.nodes CustomSet.new(shared) end def disjoint?(other) remainder = nodes - other.nodes remainder.length == data.length end def empty CustomSet.new end def empty? size == 0 end def intersection(other) intersection = nodes.select do |node| other.nodes.any? { |other_node| other_node.eql?(node) } end CustomSet.new(intersection) end def member?(datum) data.any? { |node| node.datum.eql?(datum) } end alias include? member? def add(datum) unless data.any? { |node| node.datum.eql?(datum) } add_datum(datum) end self end def size nodes.uniq.count end def subset?(other) nodes.all? { |other_node| other.nodes.any? { |node| node.eql?(other_node) } } end def to_a nodes.uniq end def union(other) union = (nodes + other.nodes).uniq CustomSet.new(union) end def ==(other) nodes == other.nodes end def nodes data.map(&:datum).sort end def add_datum(datum) @data << Node.new(datum) end private def parse_data(input_data) input_data.map do |d| Node.new(d) end end end class Node attr_reader :datum def initialize(input_datum) @datum = input_datum end end module BookKeeping VERSION = 1 end
Version data entries
396 entries across 396 versions & 1 rubygems