Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. import sun.awt.image.ImageWatched;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.util.Dictionary;
  8. import java.util.HashSet;
  9. import java.util.LinkedList;
  10. import java.util.Set;
  11.  
  12. import static com.sun.corba.se.impl.util.Utility.printStackTrace;
  13.  
  14. /**
  15. * Created by Maysan on 14-Dec-17.
  16. */
  17. public class Function {
  18. //inputLabels[0] is a set of input labels for party 0.
  19. //inputLabels[1] is a set of input labels for party 1.
  20. Set<String>[] inputLabels;
  21.  
  22. int numOfGates;
  23. int numOfParties;
  24. int numOfOutputWires;
  25. String OutputWireLabel;
  26.  
  27. //since there is no identifiers for the circuits, the circuits are identified by their input wires
  28. //example: given circuit c with input labels "4","5"; inputLabelsToCircuitsDict["4"]=inputLabelsToCircuitsDict["5"]=c
  29. Dictionary<String,Circuit> inputLabelsToCircuitsDict;
  30.  
  31.  
  32. Function(String inputFile){
  33.  
  34. try {
  35. FileReader fileReader = new FileReader(inputFile);
  36. BufferedReader bufferedReader = new BufferedReader(fileReader);
  37.  
  38. numOfGates = Integer.parseInt(bufferedReader.readLine());
  39. numOfParties = Integer.parseInt(bufferedReader.readLine());
  40. if(numOfParties != 2){
  41. System.out.println("Only 2 parties supported.");
  42. bufferedReader.close();
  43. throw new IllegalArgumentException();
  44. }
  45.  
  46. //Parse parties' input labels
  47. for (int i=0 ; i<numOfParties ; i++){
  48. String line = bufferedReader.readLine();
  49. String[] lineArray = line.split("\\s+");
  50. int party = Integer.parseInt(lineArray[0]);
  51. int numOfInputWires = Integer.parseInt(lineArray[1]);
  52. inputLabels[party] = new HashSet<String>();
  53. for (int j=0 ; j<numOfInputWires ; j++){
  54. inputLabels[party].add(lineArray[2+j]);
  55. }
  56. }
  57.  
  58. numOfOutputWires = Integer.parseInt(bufferedReader.readLine());
  59.  
  60. //TODO: check how to parse multiple output wires
  61. OutputWireLabel = bufferedReader.readLine();
  62.  
  63. bufferedReader.close();
  64. } catch (FileNotFoundException e) {
  65. System.out.println("File not found: " + inputFile);
  66. } catch (IOException e) {
  67. System.out.println("Reading Error in: " + inputFile);
  68. printStackTrace();
  69. }
  70.  
  71. }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement