aggregateknowledge / java-hll

Java library for the HyperLogLog algorithm
http://research.neustar.biz/2013/12/24/open-source-release-java-hll/
Apache License 2.0
311 stars 70 forks source link

Wrong max value for log2m? #1

Closed iconara closed 10 years ago

iconara commented 10 years ago

The docs say that the log2m parameter must "be at least 4 and at most 31", but it seems that 30 is the highest possible value.

The following line raises a NegativeArraySizeException:

new HLL(31, 8, -1, true, HLLType.FULL);

Here's the full stack trace:

Exception in thread "main" java.lang.NegativeArraySizeException
    at net.agkn.hll.util.BitVector.<init>(BitVector.java:68)
    at net.agkn.hll.HLL.initializeStorage(HLL.java:434)
    at net.agkn.hll.HLL.<init>(HLL.java:202)
    at Spike.main(Spike.java:7)

If I change 31 to 30 it works fine.

ghost commented 10 years ago

Thanks for noticing! This has been fixed and I've added some bounds checking to the constructors to enforce this.