X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FMerger.java;h=17d1b57db8412fe0e1c87cfd14d492875fea2848;hb=4712d3e6ee08461b7754dbfba1c9e82372bb474d;hp=1efcf8ad276cf0d6d4922ed92bda4a466af458fc;hpb=74aebd92f41d03f4a44c9a455ef8c05465136412;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 1efcf8ad..17d1b57d 100644 --- a/era.mi/src/era/mi/logic/components/Merger.java +++ b/era.mi/src/era/mi/logic/components/Merger.java @@ -6,11 +6,12 @@ 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.WireArray.WireArrayEnd; import era.mi.logic.wires.WireArrayObserver; -public class Merger implements WireArrayObserver, Component { - private WireArrayInput outI; +public class Merger implements WireArrayObserver, Component +{ + private WireArrayEnd outI; private WireArray[] inputs; private int[] beginningIndex; @@ -19,13 +20,15 @@ public class Merger implements WireArrayObserver, Component { * @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) { + 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++) { + for (int i = 0; i < inputs.length; i++) + { beginningIndex[i] = length; length += inputs[i].length; inputs[i].addObserver(this); @@ -36,39 +39,46 @@ public class Merger implements WireArrayObserver, Component { "The output of merging n WireArrays into one must have length = a1.length() + a2.length() + ... + an.length()."); } - public WireArray getInput(int index) { + public WireArray getInput(int index) + { return inputs[index]; } - public WireArray getUnion() { + public WireArray getUnion() + { return outI.owner; } @Override - public void update(WireArray initiator, Bit[] oldValues) { + public void update(WireArray initiator, Bit[] oldValues) + { int index = find(initiator); int beginning = beginningIndex[index]; outI.feedSignals(beginning, initiator.getValues()); } - private int find(WireArray w) { + private int find(WireArray w) + { for (int i = 0; i < inputs.length; i++) if (inputs[i] == w) return i; return -1; } - public WireArray[] getInputs() { + public WireArray[] getInputs() + { return inputs.clone(); } @Override - public List getAllInputs() { + public List getAllInputs() + { return Collections.unmodifiableList(Arrays.asList(inputs)); } @Override - public List getAllOutputs() { + public List getAllOutputs() + { return Collections.unmodifiableList(Arrays.asList(outI.owner)); } }