FF10_Wplus1_Wplus1.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // by Boyang Wei
  2. package YaoGC;
  3. public class FF10_Wplus1_Wplus1 extends CompositeCircuit {
  4. private final int w;
  5. private final boolean b; // find 1 or find 0
  6. private int s; // sigma
  7. public FF10_Wplus1_Wplus1(int w, boolean b, int s) {
  8. super(w + 1, w + 1, w * 3, "FindFirstZeroOrOne_" + (w + 1) + "_" + w
  9. + 1);
  10. this.w = w;
  11. this.b = b;
  12. this.s = s;
  13. }
  14. protected void createSubCircuits() throws Exception {
  15. for (int i = 0; i < w * 2; i++) {
  16. if (s <= i && i <= w + s - 1) {
  17. if (b)
  18. subCircuits[i] = new FF10_2_2(1);
  19. else
  20. subCircuits[i] = new FF10_2_2(2);
  21. } else { // i < s || w+s-1 < i
  22. subCircuits[i] = new FF10_2_2(3);
  23. }
  24. }
  25. for (int i = 2 * w; i < w * 3; i++)
  26. subCircuits[i] = XOR_2_1.newInstance();
  27. s = 0;
  28. super.createSubCircuits();
  29. }
  30. protected void connectWires() throws Exception {
  31. inputWires[0].connectTo(subCircuits[0].inputWires, 0); // Enable wire
  32. for (int i = 0; i < w; i++) {
  33. inputWires[i + 1].connectTo(subCircuits[i].inputWires, 1); // green
  34. // wire
  35. inputWires[i + 1].connectTo(subCircuits[i + w].inputWires, 1); // green
  36. // wire
  37. subCircuits[i].outputWires[1].connectTo(
  38. subCircuits[i + 2 * w].inputWires, 0); // orange wire
  39. subCircuits[i + w].outputWires[1].connectTo(
  40. subCircuits[i + 2 * w].inputWires, 1); // orange wire
  41. }
  42. for (int i = 0; i < 2 * w - 1; i++)
  43. subCircuits[i].outputWires[0].connectTo(
  44. subCircuits[i + 1].inputWires, 0); // blue wire
  45. }
  46. protected void defineOutputWires() {
  47. for (int i = 0; i < w; i++)
  48. outputWires[i] = subCircuits[i + 2 * w].outputWires[0]; // orange
  49. // wire
  50. outputWires[w] = subCircuits[2 * w - 1].outputWires[0]; // Success wire
  51. }
  52. }