<commit_before>=begin
= NatSet

NatSet represents a set of naturals - non-negative integers.

== class methods
--- NatSet.empty
--- NatSet.whole
--- NatSet.create(integer_or_range, ...)

== methods
--- empty?
--- whole?
--- open?
--- singleton?
--- self == other
--- self === other
--- eql?(other)
--- hash
--- ~self
--- self + other
--- self - other
--- self & other
=end

class NatSet
  def NatSet.empty
    self.new
  end

  def NatSet.whole
    self.new(0)
  end

  def NatSet.create(*es)
    r = self.empty
    es.each {|e|
      case e
      when Range
	unless Integer === e.begin
	  raise ArgumentError.new("bad value for #{self}.create: #{e}")
	end
	if e.exclude_end?
	  r += self.new(e.begin, e.end)
	else
	  r += self.new(e.begin, e.end+1)
	end
      when Integer
	r += self.new(e, e+1)
      when NatSet
	r += e
      else
        raise ArgumentError.new("bad value for #{self}.create: #{e}")
      end
    }
    r
  end

  def initialize(*es)
    @es = es
  end
  attr_reader :es

  def empty?
    @es.empty?
  end

  def whole?
    @es == [0]
  end

  def open?
    @es.length & 1 != 0
  end

  def singleton?
    if @es.length == 2 && @es[0] == @es[1] - 1
      @es[0]
    else
      nil
    end
  end

  def ==(other)
    @es == other.es
  end
  alias === ==
  alias eql? ==

  def hash
    @es.hash
  end

  def complement
    if @es.empty?
      type.whole
    elsif @es[0] == 0
      type.new(*@es[1..-1])
    else
      self.class.new(0, *@es)
    end
  end
  alias ~ complement
<commit_msg>use class instead of type.<commit_after>=begin
= NatSet

NatSet represents a set of naturals - non-negative integers.

== class methods
--- NatSet.empty
--- NatSet.whole
--- NatSet.create(integer_or_range, ...)

== methods
--- empty?
--- whole?
--- open?
--- singleton?
--- self == other
--- self === other
--- eql?(other)
--- hash
--- ~self
--- self + other
--- self - other
--- self & other
=end

class NatSet
  def NatSet.empty
    self.new
  end

  def NatSet.whole
    self.new(0)
  end

  def NatSet.create(*es)
    r = self.empty
    es.each {|e|
      case e
      when Range
	unless Integer === e.begin
	  raise ArgumentError.new("bad value for #{self}.create: #{e}")
	end
	if e.exclude_end?
	  r += self.new(e.begin, e.end)
	else
	  r += self.new(e.begin, e.end+1)
	end
      when Integer
	r += self.new(e, e+1)
      when NatSet
	r += e
      else
        raise ArgumentError.new("bad value for #{self}.create: #{e}")
      end
    }
    r
  end

  def initialize(*es)
    @es = es
  end
  attr_reader :es

  def empty?
    @es.empty?
  end

  def whole?
    @es == [0]
  end

  def open?
    @es.length & 1 != 0
  end

  def singleton?
    if @es.length == 2 && @es[0] == @es[1] - 1
      @es[0]
    else
      nil
    end
  end

  def ==(other)
    @es == other.es
  end
  alias === ==
  alias eql? ==

  def hash
    @es.hash
  end

  def complement
    if @es.empty?
      self.class.whole
    elsif @es[0] == 0
      self.class.new(*@es[1..-1])
    else
      self.class.new(0, *@es)
    end
  end
  alias ~ complement

{'fraction_non_alphanumeric': 0.161247947454844, 'fraction_numerical': 0.010509031198686371, 'mean_word_length': 1.889943074003795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1582380', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1150, 'n_words': 316}