// Path: src/main/java/sssj/time/Timeline.java
// public interface Timeline {
//   long nextTimestamp();
// 
//   public static class Sequential implements Timeline {
//     private long current = 0;
// 
//     @Override
//     public long nextTimestamp() {
//       return current++;
//     }
// 
//     @Override
//     public String toString() {
//       return "Sequential";
//     }
//   }
// 
//   public static class Poisson implements Timeline {
//     private long current = 0;
//     private ExponentialDistribution p;
// 
//     public Poisson(double rate) {
//       // exponential interarrival times with mean = 1/lambda
//       p = new ExponentialDistribution(1 / rate);
//     }
// 
//     @Override
//     public long nextTimestamp() {
//       current += Math.max(1, p.sample()); // ensure unique timestamps
//       return current;
//     }
// 
//     @Override
//     public String toString() {
//       return "Poisson(" + 1.0 / p.getMean() + ")";
//     }
//   }
// }


import static org.junit.Assert.*;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import sssj.time.Timeline;

  @Test
  public void testOnData() throws FileNotFoundException, IOException {
    File file = new File(this.getClass().getResource(EXAMPLE_FILENAME).getPath());
    VectorStream reader = new BinaryVectorStreamReader(file);
    assertEquals(804414, reader.numVectors());
    Vector v = reader.iterator().next();
    Vector r = Vector.l2normalize(Format.VW.getRecordParser().apply(vw_example));
    assertEquals(r, v);
  }

  // @Test
  public void testSpeed() throws IOException {
    File file;
    VectorStream reader;
    int nnz;
    long start, finish;

    file = new File("data/RCV1-seq.bin");
    reader = new BinaryVectorStreamReader(file);
    nnz = 0;
    start = System.currentTimeMillis();
    for (Vector v : reader) {
      nnz += v.size();
    }
    finish = System.currentTimeMillis();
    System.out.println("nnz=" + nnz);
    System.out.println("BINARY READER - Total time taken: " + TimeUnit.MILLISECONDS.toMillis(finish - start) + " ms.");

    file = new File("data/RCV1.vw");
// Path: src/main/java/sssj/time/Timeline.java
// public interface Timeline {
//   long nextTimestamp();
// 
//   public static class Sequential implements Timeline {
//     private long current = 0;
// 
//     @Override
//     public long nextTimestamp() {
//       return current++;
//     }
// 
//     @Override
//     public String toString() {
//       return "Sequential";
//     }
//   }
// 
//   public static class Poisson implements Timeline {
//     private long current = 0;
//     private ExponentialDistribution p;
// 
//     public Poisson(double rate) {
//       // exponential interarrival times with mean = 1/lambda
//       p = new ExponentialDistribution(1 / rate);
//     }
// 
//     @Override
//     public long nextTimestamp() {
//       current += Math.max(1, p.sample()); // ensure unique timestamps
//       return current;
//     }
// 
//     @Override
//     public String toString() {
//       return "Poisson(" + 1.0 / p.getMean() + ")";
//     }
//   }
// }


// Path: src/test/java/sssj/io/BinaryVectorStreamReaderTest.java
import static org.junit.Assert.*;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import sssj.time.Timeline;


  @Test
  public void testOnData() throws FileNotFoundException, IOException {
    File file = new File(this.getClass().getResource(EXAMPLE_FILENAME).getPath());
    VectorStream reader = new BinaryVectorStreamReader(file);
    assertEquals(804414, reader.numVectors());
    Vector v = reader.iterator().next();
    Vector r = Vector.l2normalize(Format.VW.getRecordParser().apply(vw_example));
    assertEquals(r, v);
  }

  // @Test
  public void testSpeed() throws IOException {
    File file;
    VectorStream reader;
    int nnz;
    long start, finish;

    file = new File("data/RCV1-seq.bin");
    reader = new BinaryVectorStreamReader(file);
    nnz = 0;
    start = System.currentTimeMillis();
    for (Vector v : reader) {
      nnz += v.size();
    }
    finish = System.currentTimeMillis();
    System.out.println("nnz=" + nnz);
    System.out.println("BINARY READER - Total time taken: " + TimeUnit.MILLISECONDS.toMillis(finish - start) + " ms.");

    file = new File("data/RCV1.vw");
    reader = new VectorStreamReader(file, Format.VW, new Timeline.Sequential());