vigna / fastutil

fastutil extends the Java™ Collections Framework by providing type-specific maps, sets, lists and queues.
Apache License 2.0
1.76k stars 196 forks source link

LongSet.of throws IllegalArgumentException (v8.5.4) #261

Closed mseidel closed 3 years ago

mseidel commented 3 years ago

When using LongSet.of() with an array size > 4, an exception is thrown:

java.lang.IllegalArgumentException: Load factor must be greater than 0 and smaller than 1
    at it.unimi.dsi.fastutil.longs.LongOpenHashSet.<init>(LongOpenHashSet.java:73)
    at it.unimi.dsi.fastutil.longs.LongSet.of(LongSet.java:195)

This is due to a load factor of 1 being used and the constructor of LongOpenHashSet throwing an exception for that:

if (f <= 0 || f >= 1) throw new IllegalArgumentException("Load factor must be greater than 0 and smaller than 1");

The latter is probably the actual bug and should be "f > 1" instead.

vigna commented 3 years ago

No, actually the 1.0f is a bit crazy. Such sets could be horribly slow. git blame claims I did this but I have no memory. Commit 40ddda60d69c75cf6aa105028ab94672b7a9a454 should fix the problem.