1 package era.mi.logic.components;
3 import era.mi.logic.wires.WireArray;
4 import era.mi.logic.wires.WireArray.WireArrayInput;
5 import era.mi.logic.wires.WireArrayObserver;
7 public class Mapper implements WireArrayObserver
9 private int[] inBeginningIndex, outBeginningIndex;
10 private WireArray[] inputs;
11 private WireArrayInput[] outputsI;
13 public Mapper(WireArray[] inputs, WireArray[] outputs)
15 this.inputs = inputs.clone();
17 int beginningIndex = 0;
18 for (int i = 0; i < inputs.length; i++)
20 inBeginningIndex[i] = beginningIndex;
21 beginningIndex += inputs[i].length;
22 inputs[i].addObserver(this);
24 int inputsLength = beginningIndex;
26 for (int i = 0; i < outputs.length; i++)
28 outputsI[i] = outputs[i].createInput();
29 outBeginningIndex[i] = beginningIndex;
30 beginningIndex += outputs[i].length;
32 if (inputsLength != beginningIndex)
33 throw new IllegalArgumentException("Mapper inputs must add up to the same length as outputs. ("
34 + inputsLength + ", " + beginningIndex + ").");
38 public void update(WireArray initiator)
40 for (int i = 0; i < inputs.length; i++)
42 if (inputs[i] == initiator)
44 int inB = inBeginningIndex[i];
45 // int outB = outBeginningIndex TODO
51 private int findLower(int[] sorted, int value)
53 int a = 0, b = sorted.length;
56 int inspect = (a + b) >> 1;
57 if (sorted[inspect] == value)
59 if (sorted[inspect] > value)