Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sun.awt.image.ImageWatched;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Dictionary;
- import java.util.HashSet;
- import java.util.LinkedList;
- import java.util.Set;
- import static com.sun.corba.se.impl.util.Utility.printStackTrace;
- /**
- * Created by Maysan on 14-Dec-17.
- */
- public class Function {
- //inputLabels[0] is a set of input labels for party 0.
- //inputLabels[1] is a set of input labels for party 1.
- Set<String>[] inputLabels;
- int numOfGates;
- int numOfParties;
- int numOfOutputWires;
- String OutputWireLabel;
- //since there is no identifiers for the circuits, the circuits are identified by their input wires
- //example: given circuit c with input labels "4","5"; inputLabelsToCircuitsDict["4"]=inputLabelsToCircuitsDict["5"]=c
- Dictionary<String,Circuit> inputLabelsToCircuitsDict;
- Function(String inputFile){
- try {
- FileReader fileReader = new FileReader(inputFile);
- BufferedReader bufferedReader = new BufferedReader(fileReader);
- numOfGates = Integer.parseInt(bufferedReader.readLine());
- numOfParties = Integer.parseInt(bufferedReader.readLine());
- if(numOfParties != 2){
- System.out.println("Only 2 parties supported.");
- bufferedReader.close();
- throw new IllegalArgumentException();
- }
- //Parse parties' input labels
- for (int i=0 ; i<numOfParties ; i++){
- String line = bufferedReader.readLine();
- String[] lineArray = line.split("\\s+");
- int party = Integer.parseInt(lineArray[0]);
- int numOfInputWires = Integer.parseInt(lineArray[1]);
- inputLabels[party] = new HashSet<String>();
- for (int j=0 ; j<numOfInputWires ; j++){
- inputLabels[party].add(lineArray[2+j]);
- }
- }
- numOfOutputWires = Integer.parseInt(bufferedReader.readLine());
- //TODO: check how to parse multiple output wires
- OutputWireLabel = bufferedReader.readLine();
- bufferedReader.close();
- } catch (FileNotFoundException e) {
- System.out.println("File not found: " + inputFile);
- } catch (IOException e) {
- System.out.println("Reading Error in: " + inputFile);
- printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement