kodkod.engine.bool
Class BooleanAccumulator

java.lang.Object
  extended by kodkod.engine.bool.BooleanValue
      extended by kodkod.engine.bool.BooleanAccumulator
All Implemented Interfaces:
java.lang.Comparable<BooleanValue>, java.lang.Iterable<BooleanValue>

public final class BooleanAccumulator
extends BooleanValue
implements java.lang.Iterable<BooleanValue>

An accumulator for easy construction of gates with multiple inputs. An accumulator cannot be combined with other boolean values using BooleanFactory methods. To use the circuit represented by an accumulator, one must first convert it into a gate by calling BooleanFactory.accumulate(BooleanAccumulator).

Author:
Emina Torlak
specfield:
components: set BooleanValue
op: Operator.Nary

Method Summary
 BooleanValue add(BooleanValue v)
          Adds the given value to this.components and returns the result.
 boolean isShortCircuited()
          Returns true if this gate is short circuited; that is, its inputs are reduced to this.op.shortCircuit.
 java.util.Iterator<BooleanValue> iterator()
          Returns an iterator over this.components, in the increasing order of labels.
 int label()
          Returns 0.
 Operator op()
          Returns the operator for this accumulator.
 int size()
          Returns the size of this accumulator.
 java.lang.String toString()
           
static BooleanAccumulator treeGate(Operator.Nary op)
          Returns a tree based implementation of BooleanAccumulator.
static BooleanAccumulator treeGate(Operator.Nary op, BooleanValue[] inputs)
          Returns a tree based implementation of BooleanAccumulator, initialized with the given inputs.
 
Methods inherited from class kodkod.engine.bool.BooleanValue
compareTo
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

treeGate

public static BooleanAccumulator treeGate(Operator.Nary op)
Returns a tree based implementation of BooleanAccumulator. The addInput operation executes in O(lg n) time where n is the number of gate inputs.

Returns:
an empty tree based BooleanAccumulator with the given operator.
Throws:
java.lang.NullPointerException - - op = null

treeGate

public static BooleanAccumulator treeGate(Operator.Nary op,
                                          BooleanValue[] inputs)
Returns a tree based implementation of BooleanAccumulator, initialized with the given inputs. The addInput operation executes in O(lg n) time where n is the number of gate inputs.

Returns:
a tree based BooleanAccumulator with the given operator, initialized with the given inputs
Throws:
java.lang.NullPointerException - - op = null || inputs = null

op

public Operator op()
Returns the operator for this accumulator.

Specified by:
op in class BooleanValue
Returns:
this.op

add

public BooleanValue add(BooleanValue v)
Adds the given value to this.components and returns the result. Specifically, if the addition of the value causes the gate to evaluate to op.shortCircuit, then this.inputs is set to op.shortCircuit. If the given value has already been added or it is equal to this.op.identity, nothing changes. Otherwise, v is added to this.input. The method returns this.op.shortCircuit if this.inputs contains it after the addition, otherwise it returns the gate itself.

Returns:
this.components' = op.shortCircuit => op.shortCircuit, this
effects:
v = this.op.shortCircuit || v.negation in this.components => this.components' = this.op.shortCircuit, v !in BooleanConstant => this.components' = this.components + v, this.components' = this.components

isShortCircuited

public boolean isShortCircuited()
Returns true if this gate is short circuited; that is, its inputs are reduced to this.op.shortCircuit.

Returns:
this.inputs = this.op.shortCircuit

size

public int size()
Returns the size of this accumulator.

Returns:
#this.inputs

iterator

public java.util.Iterator<BooleanValue> iterator()
Returns an iterator over this.components, in the increasing order of labels. The returned iterator does not support removal.

Specified by:
iterator in interface java.lang.Iterable<BooleanValue>
Returns:
an iterator over this.components, in the increasing order of labels.

label

public int label()
Returns 0.

Specified by:
label in class BooleanValue
Returns:
0.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object