Class: LogicTools::SameXImplicants

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/logic_tools/logicsimplify.rb

Overview

Represents a group of implicants with only singletons, sortable by number of ones.

Instance Method Summary collapse

Constructor Details

#initializeSameXImplicants

Creates a group of implicants.



166
167
168
169
170
# File 'lib/logic_tools/logicsimplify.rb', line 166

def initialize
    @implicants = []
    @singletons =  Set.new # Set used for ensuring each implicant is
                           # present only once in the group
end

Instance Method Details

#[](i) ⇒ Object

Gets implicant i.



183
184
185
# File 'lib/logic_tools/logicsimplify.rb', line 183

def [](i)
    @implicants[i]
end

#add(implicant) ⇒ Object Also known as: <<

Adds implicant to the group.



188
189
190
191
192
193
# File 'lib/logic_tools/logicsimplify.rb', line 188

def add(implicant)
    # Nothing to do if +implicant+ is already present.
    return if @singletons.include?(implicant.bits)
    @implicants << implicant
    @singletons.add(implicant.bits.dup)
end

#each(&blk) ⇒ Object

Iterates over the implicants of the group.



178
179
180
# File 'lib/logic_tools/logicsimplify.rb', line 178

def each(&blk)
    @implicants.each(&blk)
end

#inspectObject

:nodoc:



207
208
209
# File 'lib/logic_tools/logicsimplify.rb', line 207

def inspect # :nodoc:
    to_s
end

#sizeObject

Gets the number of implicants of the group.



173
174
175
# File 'lib/logic_tools/logicsimplify.rb', line 173

def size
    @implicants.size
end

#sort!Object

Sort the implicants by number of ones.



198
199
200
# File 'lib/logic_tools/logicsimplify.rb', line 198

def sort!
    @implicants.sort_by! {|implicant| implicant.count }
end

#to_sObject

Converts to a string



203
204
205
# File 'lib/logic_tools/logicsimplify.rb', line 203

def to_s # :nodoc:
    @implicants.to_s
end