add(new_val)
            click to toggle source
          
          
          
  
            
            
            
            
            
               
               
def add(new_val)
  tbl = @tbl.dup
  tbl[new_val] = true
  Set.new(tbl)
end
             
             
            
           
          
          
         
      
        
          
          
          
            each(&blk)
            click to toggle source
          
          
          
  
            
            
            
            
            
               
               
def each(&blk)
  @tbl.each_key(&blk)
end
             
             
            
           
          
          
         
      
        
          
          
          
            include?(elem)
            click to toggle source
          
          
          
  
            
            
            
            
            
               
               
def include?(elem)
  @tbl[elem]
end
             
             
            
           
          
          
         
      
        
          
          
          
            inspect()
            click to toggle source
          
          
          
  
            
            
            
            
            
               
               
def inspect
  s = []
  each {|v| s << v.inspect }
  "{#{ s.join(", ") }}"
end
             
             
            
           
          
          
         
      
        
          
          
          
            intersection(other)
            click to toggle source
          
          
          
  
            
            
            
            
            
               
               
def intersection(other)
  tbl = {}
  h = 0
  each do |elem|
    if other.include?(elem)
      tbl << elem
      h ^= elem.hash
    end
  end
  Set.new(tbl, h)
end
             
             
            
           
          
          
         
      
        
          
          
          
            map(&blk)
            click to toggle source
          
          
          
  
            
            
            
            
            
               
               
def map(&blk)
  tbl = {}
  each do |elem|
    v = yield(elem)
    tbl[v] = true
  end
  Set.new(tbl)
end
             
             
            
           
          
          
         
      
        
          
          
          
            size()
            click to toggle source
          
          
          
          
          
         
      
        
          
          
          
            sum(other)
            click to toggle source
          
          
          
  
            
            
            
            
            
               
               
def sum(other)
  if @tbl.size == 0
    other
  elsif other.tbl.size == 0
    self
  else
    Set.new(@tbl.merge(other.tbl))
  end
end