~ubuntu-branches/ubuntu/intrepid/racc/intrepid

« back to all changes in this revision

Viewing changes to packages/racc/lib/racc/iset.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2005-04-09 17:54:44 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050409175444-fvtir838ypkn7a58
Tags: 1.4.4-1
* new upstream version.  (closes: #301768)
* added racc2y.1 and y2racc.1.
* modified racc2y and y2racc to use optparse instead of deprecated getopts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
2
# iset.rb
3
3
#
4
 
#   Copyright (c) 1999-2001 Minero Aoki <aamine@loveruby.net>
5
 
#
6
 
#   This program is free software.
7
 
#   You can distribute/modify this program under the terms of
8
 
#   the GNU Lesser General Public License version 2 or later.
9
 
#
10
 
 
 
4
# Copyright (c) 1999-2003 Minero Aoki <aamine@loveruby.net>
 
5
#
 
6
# This program is free software.
 
7
# You can distribute/modify this program under the terms of
 
8
# the GNU LGPL, Lesser General Public License version 2.
 
9
# For details of the GNU LGPL, see the file "COPYING".
 
10
#
11
11
 
12
12
module Racc
13
13
 
15
15
  # ISet
16
16
  #
17
17
  # indexed set.
18
 
  # all items respond to :ident
 
18
  # all items must respond to :ident
19
19
  #
20
20
 
21
21
  class ISet
24
24
      @set = a
25
25
    end
26
26
 
27
 
    attr :set
 
27
    attr_reader :set
28
28
 
29
29
    def add( i )
30
 
      @set[ i.ident ] = i
 
30
      @set[i.ident] = i
31
31
    end
32
32
 
33
33
    def []( key )
34
 
      @set[ key.ident ]
 
34
      @set[key.ident]
35
35
    end
36
36
 
37
37
    def []=( key, val )
38
 
      @set[ key.ident ] = val
 
38
      @set[key.ident] = val
39
39
    end
40
40
 
41
41
    alias include? []
42
42
    alias key? []
43
43
 
44
44
    def update( other )
45
 
      s = @set; o = other.set
46
 
      i = t = nil
47
 
      o.each_index {|i| if t = o[i] then s[i] = t end }
 
45
      s = @set
 
46
      o = other.set
 
47
      o.each_index do |idx|
 
48
        if t = o[idx]
 
49
          s[idx] = t
 
50
        end
 
51
      end
48
52
    end
49
53
 
50
54
    def update_a( a )
51
55
      s = @set
52
56
      i = nil
53
 
      a.each {|i| s[ i.ident ] = i }
 
57
      a.each {|i| s[i.ident] = i }
54
58
    end
55
59
 
56
60
    def delete( key )
57
 
      i = @set[ key.ident ]
58
 
      @set[ key.ident ] = nil
 
61
      i = @set[key.ident]
 
62
      @set[key.ident] = nil
59
63
      i
60
64
    end
61
65
 
62
66
    def each( &block )
63
 
      @set.compact.each( &block )
 
67
      @set.compact.each(&block)
64
68
    end
65
69
 
66
70
    def to_a
86
90
    end
87
91
 
88
92
    def dup
89
 
      ISet.new @set.dup
 
93
      ISet.new(@set.dup)
90
94
    end
91
95
  
92
96
  end   # class ISet