Class: LogicTools::VoidCube

Inherits:
Cube
  • Object
show all
Defined in:
lib/logic_tools/logicsimplify_es.rb

Overview

Represents an empty cube.

NOTE: for irredundant usage only.

Instance Method Summary collapse

Methods inherited from Cube

#blocking_matrix, #can_merge?, #consensus, #distance, #each_minterm, #include?, #intersect, #intersects?, #merge, #sharp, #width

Constructor Details

#initialize(size) ⇒ VoidCube

Returns a new instance of VoidCube.



141
142
143
144
145
146
# File 'lib/logic_tools/logicsimplify_es.rb', line 141

def initialize(size)
    # NOTE: This bit string is a phony, since the cube is void.
    super("-" * size,false)
    # The real bits
    @vbits = " " * size
end

Instance Method Details

#<=>(cube) ⇒ Object

:nodoc:



197
198
199
# File 'lib/logic_tools/logicsimplify_es.rb', line 197

def <=>(cube) #:nodoc:
    @vbits <=> cube.bits
end

#==(cube) ⇒ Object Also known as: eql?

Compares with another cube.



193
194
195
# File 'lib/logic_tools/logicsimplify_es.rb', line 193

def ==(cube) # :nodoc:
    @vbits == cube.bits
end

#[](i) ⇒ Object

Gets the char value of bit i.



213
214
215
# File 'lib/logic_tools/logicsimplify_es.rb', line 213

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

#[]=(i, b) ⇒ Object

Sets the char value of bit i to b.

Invalid for a VoidCube.


225
226
227
# File 'lib/logic_tools/logicsimplify_es.rb', line 225

def []=(i,b)
    raise "A VoidCube cannot be modified."
end

#cloneObject Also known as: dup

duplicates the cube.



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

def clone # :nodoc:
    VoidCube.new(self.width)
end

#each_byte(&blk) ⇒ Object

Iterates over the bits of the cube as bytes.

Returns an enumerator if no block given.


164
165
166
167
168
169
170
# File 'lib/logic_tools/logicsimplify_es.rb', line 164

def each_byte(&blk)
    # No block given? Return an enumerator.
    return to_enum(:each_byte) unless block_given?
    
    # Block given? Apply it on each bit.
    @vbits.each_byte(&blk)
end

#each_char(&blk) ⇒ Object Also known as: each

Iterates over the bits of the cube as chars.

Returns an enumerator if no block given.


175
176
177
178
179
180
181
# File 'lib/logic_tools/logicsimplify_es.rb', line 175

def each_char(&blk)
    # No block given? Return an enumerator.
    return to_enum(:each_char) unless block_given?
    
    # Block given? Apply it on each bit.
    @vbits.each_char(&blk)
end

#eval(input) ⇒ Object

Evaluates the corresponding function’s value for a binary input.

+input+ is assumed to be an integer.
Returns the evaluation result as a boolean.


152
153
154
# File 'lib/logic_tools/logicsimplify_es.rb', line 152

def eval(input)
    return false
end

#getbyte(i) ⇒ Object

Gets the byte value of bit i.



218
219
220
# File 'lib/logic_tools/logicsimplify_es.rb', line 218

def getbyte(i)
    @vbits.getbyte(i)
end

#hashObject

Gets the hash of a cube



202
203
204
# File 'lib/logic_tools/logicsimplify_es.rb', line 202

def hash
    @vbits.hash
end

#setbyte(i, b) ⇒ Object

Sets the byte value of bit i to b.

Invalid for a VoidCube.


232
233
234
# File 'lib/logic_tools/logicsimplify_es.rb', line 232

def setbyte(i,b)
    raise "A VoidCube cannot be modified."
end

#to_sObject

Converts to a string.



157
158
159
# File 'lib/logic_tools/logicsimplify_es.rb', line 157

def to_s # :nodoc:
    return @vbits.clone
end