Sha256: 8432ac789d0e003b554b513d3a0e0e1304ce18b74edb73e957243fc9755943ae

Contents?: true

Size: 1.24 KB

Versions: 3763

Compression:

Stored size: 1.24 KB

Contents

#--
#
#
#
# Copyright (c) 1999-2006 Minero Aoki
#
# This program is free software.
# You can distribute/modify this program under the same terms of ruby.
# see the file "COPYING".
#
#++

module Racc

  # An "indexed" set.  All items must respond to :ident.
  class ISet

    def initialize(a = [])
      @set = a
    end

    attr_reader :set

    def add(i)
      @set[i.ident] = i
    end

    def [](key)
      @set[key.ident]
    end

    def []=(key, val)
      @set[key.ident] = val
    end

    alias include? []
    alias key? []

    def update(other)
      s = @set
      o = other.set
      o.each_index do |idx|
        if t = o[idx]
          s[idx] = t
        end
      end
    end

    def update_a(a)
      s = @set
      a.each {|i| s[i.ident] = i }
    end

    def delete(key)
      i = @set[key.ident]
      @set[key.ident] = nil
      i
    end

    def each(&block)
      @set.compact.each(&block)
    end

    def to_a
      @set.compact
    end

    def to_s
      "[#{@set.compact.join(' ')}]"
    end

    alias inspect to_s

    def size
      @set.nitems
    end

    def empty?
      @set.nitems == 0
    end

    def clear
      @set.clear
    end

    def dup
      ISet.new(@set.dup)
    end

  end   # class ISet

end   # module Racc

Version data entries

3,763 entries across 3,754 versions & 32 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_bank_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_organization_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_id_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_bank_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_id_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_organization_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
ory-client-1.16.1 vendor/bundle/ruby/3.1.0/gems/racc-1.8.1/lib/racc/iset.rb
ory-client-1.16.0 vendor/bundle/ruby/3.1.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_bank_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb
cybrid_api_organization_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/racc-1.8.1/lib/racc/iset.rb