import era.mi.logic.types.BitVector;
import era.mi.logic.wires.Wire;
-import era.mi.logic.wires.Wire.WireEnd;
+import era.mi.logic.wires.Wire.ReadEnd;
+import era.mi.logic.wires.Wire.ReadWriteEnd;
import era.mi.logic.wires.WireObserver;
public class Merger implements WireObserver, Component
{
- private WireEnd out;
- private WireEnd[] inputs;
+ private ReadWriteEnd out;
+ private ReadEnd[] inputs;
private int[] beginningIndex;
/**
* @param union The output of merging n {@link Wire}s into one. Must have length = a1.length() + a2.length() + ... + an.length().
* @param inputs The inputs to be merged into the union
*/
- public Merger(WireEnd union, WireEnd... inputs)
+ public Merger(ReadWriteEnd union, ReadEnd... inputs)
{
this.inputs = inputs;
this.out = union;
"The output of merging n WireArrays into one must have length = a1.length() + a2.length() + ... + an.length().");
}
- public WireEnd getInput(int index)
+ public ReadEnd getInput(int index)
{
return inputs[index];
}
- public WireEnd getUnion()
+ public ReadEnd getUnion()
{
return out;
}
@Override
- public void update(Wire initiator, BitVector oldValues)
+ public void update(ReadEnd initiator, BitVector oldValues)
{
int index = find(initiator);
int beginning = beginningIndex[index];
out.feedSignals(beginning, inputs[index].getValues());
}
- private int find(Wire w)
+ private int find(ReadEnd r)
{
for (int i = 0; i < inputs.length; i++)
- if (inputs[i].getWire() == w)
+ if (inputs[i] == r)
return i;
return -1;
}
- public WireEnd[] getInputs()
+ public ReadEnd[] getInputs()
{
return inputs.clone();
}
@Override
- public List<WireEnd> getAllInputs()
+ public List<ReadEnd> getAllInputs()
{
return List.of(inputs);
}
@Override
- public List<WireEnd> getAllOutputs()
+ public List<ReadWriteEnd> getAllOutputs()
{
return List.of(out);
}