Skip to content

Commit

Permalink
Implement WatermanSkipFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
gstamatelat committed Jul 10, 2018
1 parent 9b35a3e commit f177713
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/gr/james/sampling/WatermanSampling.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,31 @@ long skipLength(long streamSize, int sampleSize, Random random) {
}
return skipCount;
}

@Deprecated
private static class WatermanSkipFunction implements SkipFunction {
private final int sampleSize;
private final Random random;
private long streamSize;

public WatermanSkipFunction(int sampleSize, Random random) {
this.sampleSize = sampleSize;
this.random = random;
this.streamSize = sampleSize;
}

@Override
public long skip() throws StreamOverflowException {
if (streamSize == Long.MAX_VALUE) {
throw new StreamOverflowException();
}
streamSize++;
long skipCount = 0;
while (random.nextDouble() * streamSize >= sampleSize && streamSize > 0) {
streamSize++;
skipCount++;
}
return skipCount;
}
}
}

0 comments on commit f177713

Please sign in to comment.