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.
174 175 176 177 178 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 174 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.
191 192 193 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 191 def [](i) @implicants[i] end |
#add(implicant) ⇒ Object Also known as: <<
Adds implicant to the group.
196 197 198 199 200 201 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 196 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.
186 187 188 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 186 def each(&blk) @implicants.each(&blk) end |
#inspect ⇒ Object
:nodoc:
215 216 217 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 215 def inspect # :nodoc: to_s end |
#size ⇒ Object
Gets the number of implicants of the group.
181 182 183 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 181 def size @implicants.size end |
#sort! ⇒ Object
Sort the implicants by number of ones.
206 207 208 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 206 def sort! @implicants.sort_by! {|implicant| implicant.count } end |
#to_s ⇒ Object
Converts to a string
211 212 213 |
# File 'lib/logic_tools/logicsimplify_qm.rb', line 211 def to_s # :nodoc: @implicants.to_s end |