1 package era.mi.logic.components;
3 import era.mi.logic.Util;
4 import era.mi.logic.Bit;
5 import era.mi.logic.WireArray;
6 import era.mi.logic.WireArrayObserver;
9 public class Merger implements WireArrayObserver
11 private WireArray out;
12 private WireArray[] inputs;
14 //TODO: General problem with this concept; New inputs coming in at the same time override each other
18 * @param union The output of merging n {@link WireArray}s into one. Must have length = a1.length() + a2.length() + ... + an.length().
19 * @param inputs The inputs to be merged into the union
21 public Merger(WireArray union, WireArray... inputs)
27 for(WireArray input : inputs)
29 length += input.length();
30 input.addObserver(this);
33 if(length != union.length())
34 throw new IllegalArgumentException("The output of merging n WireArrays into one must have length = a1.length() + a2.length() + ... + an.length().");
37 protected void compute()
39 Bit[][] bits = new Bit[inputs.length][];
40 for(int i = 0; i < inputs.length; i++)
41 bits[i] = inputs[i].getValues();
42 Bit[] newOut = Util.concat(bits);
43 out.feedSignals(newOut);
46 public WireArray getInput(int index)
51 public WireArray getUnion()
57 public void update(WireArray initiator)
59 compute(); //No inner delay