Class: LogicTools::SameXImplicants
- Inherits:
-
Object
- Object
- LogicTools::SameXImplicants
- Includes:
- Enumerable
- Defined in:
- lib/logic_tools/logicsimplify_qm.rb
Overview
Represents a group of implicants with only singletons, sortable by number of ones.
Instance Method Summary collapse
-
#[](i) ⇒ Object
Gets implicant
i. -
#add(implicant) ⇒ Object
(also: #<<)
Adds
implicantto the group. -
#each(&blk) ⇒ Object
Iterates over the implicants of the group.
-
#initialize ⇒ SameXImplicants
constructor
Creates a group of implicants.
-
#inspect ⇒ Object
:nodoc:.
-
#size ⇒ Object
Gets the number of implicants of the group.
-
#sort! ⇒ Object
Sort the implicants by number of ones.
-
#to_s ⇒ Object
Converts to a string.
Constructor Details
#initialize ⇒ SameXImplicants
Creates a group of implicants.
173 174 175 176 177 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 173 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.
190 191 192 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 190 def [](i) @implicants[i] end |
#add(implicant) ⇒ Object Also known as: <<
Adds implicant to the group.
195 196 197 198 199 200 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 195 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.
185 186 187 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 185 def each(&blk) @implicants.each(&blk) end |
#inspect ⇒ Object
:nodoc:
214 215 216 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 214 def inspect # :nodoc: to_s end |
#size ⇒ Object
Gets the number of implicants of the group.
180 181 182 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 180 def size @implicants.size end |
#sort! ⇒ Object
Sort the implicants by number of ones.
205 206 207 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 205 def sort! @implicants.sort_by! {|implicant| implicant.count } end |
#to_s ⇒ Object
Converts to a string
210 211 212 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 210 def to_s # :nodoc: @implicants.to_s end |