X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FMerger.java;fp=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FMerger.java;h=0000000000000000000000000000000000000000;hb=a28f7aa0dab4248e99159c5a647676170cb17a4e;hp=ab38066558adeef215f56adfba0ea7f9134f3528;hpb=80bfbd8ebf0ad8a7ad98584544a0c73f43e6f3b6;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/components/Merger.java b/era.mi/src/era/mi/logic/components/Merger.java deleted file mode 100644 index ab380665..00000000 --- a/era.mi/src/era/mi/logic/components/Merger.java +++ /dev/null @@ -1,85 +0,0 @@ -package era.mi.logic.components; - -import java.util.List; - -import era.mi.logic.timeline.Timeline; -import era.mi.logic.types.BitVector; -import era.mi.logic.wires.Wire; -import era.mi.logic.wires.Wire.ReadEnd; -import era.mi.logic.wires.Wire.ReadWriteEnd; -import era.mi.logic.wires.WireObserver; - -public class Merger extends Component implements WireObserver -{ - 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(Timeline timeline, ReadWriteEnd union, ReadEnd... inputs) - { - super(timeline); - this.inputs = inputs; - this.out = union; - this.beginningIndex = new int[inputs.length]; - - int length = 0; - for (int i = 0; i < inputs.length; i++) - { - beginningIndex[i] = length; - length += inputs[i].length(); - inputs[i].addObserver(this); - } - - if (length != union.length()) - throw new IllegalArgumentException( - "The output of merging n WireArrays into one must have length = a1.length() + a2.length() + ... + an.length()."); - } - - public ReadEnd getInput(int index) - { - return inputs[index]; - } - - public ReadEnd getUnion() - { - return out; - } - - @Override - public void update(ReadEnd initiator, BitVector oldValues) - { - int index = find(initiator); - int beginning = beginningIndex[index]; - out.feedSignals(beginning, inputs[index].getValues()); - } - - private int find(ReadEnd r) - { - for (int i = 0; i < inputs.length; i++) - if (inputs[i] == r) - return i; - return -1; - } - - public ReadEnd[] getInputs() - { - return inputs.clone(); - } - - @Override - public List getAllInputs() - { - return List.of(inputs); - } - - @Override - public List getAllOutputs() - { - return List.of(out); - } -}