// Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
// 
//   private long start;
// 
//   public Timing() {
//     super();
//   }
// 
//   public void start() {
//     start = getCpuTime();
//   }
// 
//   public long duration() {
//     long now = getCpuTime();
//     long diff = now - start;
//     start = now;
//     return diff;
//   }
// 
//   public static long getCpuTime() {
//     ThreadMXBean bean = ManagementFactory.getThreadMXBean();
//     return bean.isCurrentThreadCpuTimeSupported() ?
//         bean.getCurrentThreadCpuTime() : 0L;
//   }
// 
//   /**
//    * Get user time in nanoseconds.
//    */
//   public static long getUserTime() {
//     ThreadMXBean bean = ManagementFactory.getThreadMXBean();
//     return bean.isCurrentThreadCpuTimeSupported() ?
//         bean.getCurrentThreadUserTime() : 0L;
//   }
// 
//   /**
//    * Get system time in nanoseconds.
//    */
//   public static long getSystemTime() {
//     ThreadMXBean bean = ManagementFactory.getThreadMXBean();
//     return bean.isCurrentThreadCpuTimeSupported() ?
//         (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
//   }
// }
// 
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
// 
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
// 
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS;
      new BinaryValueWriter().write(pdbResults,
          new FileOutputStream("data/dominators-java-" + vf.toString() + "-single.bin"));
    }

    if (LOG_TEXTUAL_RESULTS) {
      new StandardTextWriter().write(pdbResults,
          new FileWriter("data/dominators-java-" + vf.toString() + "-single.txt"));
    }

    return pdbResults;
  }

  public static ISet testAll(IValueFactory vf) throws IOException, FileNotFoundException {
    IMap data =
        (IMap) new BinaryValueReader().read(vf, new FileInputStream(CURRENT_DATA_SET_FILE_NAME));
    ISetWriter result = vf.setWriter();

    long before = Timing.getCpuTime();
    for (IValue key : data) {
      try {
        result.insert(new DominatorsPDB(vf).jDominators((ISet) data.get(key)));
      } catch (RuntimeException e) {
        System.err.println(e.getMessage());
      }
    }
    System.err.println(vf.toString() + "\nDuration: "
        + ((Timing.getCpuTime() - before) / 1000000000) + " seconds\n");

    ISet pdbResults = result.done();

// Path: src/main/java/org/rascalmpl/interpreter/utils/Timing.java
// public final class Timing {
// 
//   private long start;
// 
//   public Timing() {
//     super();
//   }
// 
//   public void start() {
//     start = getCpuTime();
//   }
// 
//   public long duration() {
//     long now = getCpuTime();
//     long diff = now - start;
//     start = now;
//     return diff;
//   }
// 
//   public static long getCpuTime() {
//     ThreadMXBean bean = ManagementFactory.getThreadMXBean();
//     return bean.isCurrentThreadCpuTimeSupported() ?
//         bean.getCurrentThreadCpuTime() : 0L;
//   }
// 
//   /**
//    * Get user time in nanoseconds.
//    */
//   public static long getUserTime() {
//     ThreadMXBean bean = ManagementFactory.getThreadMXBean();
//     return bean.isCurrentThreadCpuTimeSupported() ?
//         bean.getCurrentThreadUserTime() : 0L;
//   }
// 
//   /**
//    * Get system time in nanoseconds.
//    */
//   public static long getSystemTime() {
//     ThreadMXBean bean = ManagementFactory.getThreadMXBean();
//     return bean.isCurrentThreadCpuTimeSupported() ?
//         (bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime()) : 0L;
//   }
// }
// 
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final String DATA_SET_SINGLE_FILE_NAME = "data/single.bin";
// 
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_BINARY_RESULTS = false;
// 
// Path: src/main/java/dom/AllDominatorsRunner.java
// public static final boolean LOG_TEXTUAL_RESULTS = false;


// Path: src/main/java/dom/DominatorsPDB.java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import io.usethesource.capsule.Set;
import io.usethesource.capsule.Set.Transient;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ITuple;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.io.old.BinaryValueReader;
import io.usethesource.vallang.io.old.BinaryValueWriter;
import org.rascalmpl.interpreter.utils.Timing;
import static dom.AllDominatorsRunner.CURRENT_DATA_SET_FILE_NAME;
import static dom.AllDominatorsRunner.DATA_SET_SINGLE_FILE_NAME;
import static dom.AllDominatorsRunner.LOG_BINARY_RESULTS;
import static dom.AllDominatorsRunner.LOG_TEXTUAL_RESULTS;

      new BinaryValueWriter().write(pdbResults,
          new FileOutputStream("data/dominators-java-" + vf.toString() + "-single.bin"));
    }

    if (LOG_TEXTUAL_RESULTS) {
      new StandardTextWriter().write(pdbResults,
          new FileWriter("data/dominators-java-" + vf.toString() + "-single.txt"));
    }

    return pdbResults;
  }

  public static ISet testAll(IValueFactory vf) throws IOException, FileNotFoundException {
    IMap data =
        (IMap) new BinaryValueReader().read(vf, new FileInputStream(CURRENT_DATA_SET_FILE_NAME));
    ISetWriter result = vf.setWriter();

    long before = Timing.getCpuTime();
    for (IValue key : data) {
      try {
        result.insert(new DominatorsPDB(vf).jDominators((ISet) data.get(key)));
      } catch (RuntimeException e) {
        System.err.println(e.getMessage());
      }
    }
    System.err.println(vf.toString() + "\nDuration: "
        + ((Timing.getCpuTime() - before) / 1000000000) + " seconds\n");

    ISet pdbResults = result.done();

    if (LOG_BINARY_RESULTS) {