X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FMerger.java;h=a9d1410160808ebb866f57e34a90b395a4dab6b9;hb=b7ce41467a2cbd9f45554982730741810e99feaa;hp=591bfc1bac47da336df2993fc46d7fd7efb5bd1f;hpb=bcf8d773c7a836c2ee17e17a49c296ebf31d2777;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 index 591bfc1b..a9d14101 100644 --- a/era.mi/src/era/mi/logic/components/Merger.java +++ b/era.mi/src/era/mi/logic/components/Merger.java @@ -1,85 +1,83 @@ package era.mi.logic.components; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import era.mi.logic.Bit; -import era.mi.logic.wires.WireArray; -import era.mi.logic.wires.WireArray.WireArrayInput; -import era.mi.logic.wires.WireArrayObserver; +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 implements WireArrayObserver, Component +public class Merger implements WireObserver, Component { - private WireArrayInput outI; - private WireArray[] inputs; - private int[] beginningIndex; + private ReadWriteEnd out; + private ReadEnd[] inputs; + private int[] beginningIndex; - /** - * - * @param union The output of merging n {@link WireArray}s into one. Must have - * length = a1.length() + a2.length() + ... + an.length(). - * @param inputs The inputs to be merged into the union - */ - public Merger(WireArray union, WireArray... inputs) - { - this.inputs = inputs; - this.outI = union.createInput(); - this.beginningIndex = new int[inputs.length]; - - int length = 0; - for (int i = 0; i < inputs.length; i++) + /** + * + * @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(ReadWriteEnd union, ReadEnd... inputs) { - beginningIndex[i] = length; - length += inputs[i].length; - inputs[i].addObserver(this); - } + this.inputs = inputs; + this.out = union; + this.beginningIndex = new int[inputs.length]; - if (length != union.length) - throw new IllegalArgumentException( - "The output of merging n WireArrays into one must have length = a1.length() + a2.length() + ... + an.length()."); - } + int length = 0; + for (int i = 0; i < inputs.length; i++) + { + beginningIndex[i] = length; + length += inputs[i].length(); + inputs[i].addObserver(this); + } - public WireArray getInput(int index) - { - return inputs[index]; - } + 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 WireArray getUnion() - { - return outI.owner; - } + public ReadEnd getInput(int index) + { + return inputs[index]; + } - @Override - public void update(WireArray initiator, Bit[] oldValues) - { - int index = find(initiator); - int beginning = beginningIndex[index]; - outI.feedSignals(beginning, initiator.getValues()); - } + public ReadEnd getUnion() + { + return out; + } - private int find(WireArray w) - { - for (int i = 0; i < inputs.length; i++) - if (inputs[i] == w) - return i; - return -1; - } + @Override + public void update(ReadEnd initiator, BitVector oldValues) + { + int index = find(initiator); + int beginning = beginningIndex[index]; + out.feedSignals(beginning, inputs[index].getValues()); + } - public WireArray[] getInputs() - { - return inputs.clone(); - } + 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() + public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(inputs)); + return List.of(inputs); } @Override - public List getAllOutputs() + public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(outI.owner)); + return List.of(out); } }