| Interface | Description |
|---|---|
| PrefixMap<S extends CharSequence> |
A map from prefixes to string intervals (and possibly vice versa).
|
| StringMap<S extends CharSequence> |
A map from strings to numbers (and possibly vice versa).
|
| Class | Description |
|---|---|
| AbstractPrefixMap |
An abstract implementation of a prefix map.
|
| BloomFilter<T> |
A Bloom filter.
|
| ByteBufferLongBigList |
A bridge between byte buffers and long big lists.
|
| CircularCharArrayBuffer |
A circular char buffer that can be used to implement a sliding
window over a text.
|
| FrontCodedStringList |
Compact storage of strings using front-coding compression (a.k.a. compression by prefix omission).
|
| HyperLogLogCounterArray |
An array of approximate sets each represented using a HyperLogLog counter.
|
| ImmutableBinaryTrie<T> |
An immutable implementation of binary tries.
|
| ImmutableBinaryTrie.Node |
A node in the trie.
|
| ImmutableExternalPrefixMap |
An immutable prefix map mostly stored in external memory.
|
| Interval |
An interval of integers.
|
| Intervals |
A class providing static methods and objects that do useful things with intervals.
|
| KahanSummation |
Kahan's
summation algorithm encapsulated in an object.
|
| LiterallySignedStringMap |
A string map based on a function signed using the original list of strings.
|
| LongInterval |
An interval of longs.
|
| LongIntervals |
A class providing static methods and objects that do useful things with intervals.
|
| PermutedFrontCodedStringList |
A
FrontCodedStringList whose indices are permuted. |
| Properties |
An extension of
PropertiesConfiguration
providing setters for primitive types, a simpler way to save preferences
and transparent handling of Enum lowercased keys. |
| SemiExternalGammaList |
Provides semi-external random access to a list of γ-encoded integers.
|
| ShiftAddXorSignedStringMap |
A string map based on a function signed using Shift-Add-Xor hashes.
|
| SplitMix64Random |
A non-splittable version of the SplitMix pseudorandom number generator used by Java 8's
SplittableRandom. |
| SplitMix64RandomGenerator |
A non-splittable version of the SplitMix pseudorandom number generator used by Java 8's
SplittableRandom. |
| StringMaps |
A class providing static methods and objects that do useful things with string maps
and prefix maps.
|
| StringMaps.SynchronizedPrefixMap<S extends CharSequence> | |
| StringMaps.SynchronizedStringMap<S extends CharSequence> | |
| TernaryIntervalSearchTree |
Ternary interval search trees.
|
| TextPattern |
QuickSearch matching against a constant string.
|
| XorRShR128PlusRandomGenerator |
An unbelievably fast, top-quality pseudorandom number generator that
returns the sum of consecutive outputs of a Marsaglia Xorshift generator (described in “Xorshift RNGs”, Journal of
Statistical Software, 8:1−6, 2003) with 128 bits of state.
|
| XorShift1024StarRandom |
A fast, top-quality pseudorandom number generator that
combines a long-period instance of George Marsaglia's Xorshift generators (described in “Xorshift RNGs”, Journal of
Statistical Software, 8:1−6, 2003) with a multiplication.
|
| XorShift1024StarRandomGenerator |
A fast, top-quality pseudorandom number generator that
combines a long-period instance of George Marsaglia's Xorshift generators (described in “Xorshift RNGs”, Journal of
Statistical Software, 8:1−6, 2003) with a multiplication.
|
| XorShift128PlusRandom |
An unbelievably fast, top-quality pseudorandom number generator that
returns the sum of consecutive outputs of a Marsaglia Xorshift generator (described in “Xorshift RNGs”, Journal of
Statistical Software, 8:1−6, 2003) with 128 bits of state.
|
| XorShift128PlusRandomGenerator |
An unbelievably fast, top-quality pseudorandom number generator that
returns the sum of consecutive outputs of a Marsaglia Xorshift generator (described in “Xorshift RNGs”, Journal of
Statistical Software, 8:1−6, 2003) with 128 bits of state.
|
| XorShift64StarRandom | Deprecated
Use
SplitMix64Random instead. |
| XorShift64StarRandomGenerator | Deprecated
Use
SplitMix64RandomGenerator instead. |
Miscellaneaous utility classes.
We provide a number of fast, high-quality PRNGs with different features. As a general review:
SplitMix64Random is the fastest generator, but it has a relatively short period (264) so it should
not be used to generate very long sequences (the rule of thumb to have a period greater than the square of the length of the sequence you want to generate).
It is a non-splittable version of Java 8's SplittableRandom.
XorShift128PlusRandom is a fast-as-light, all-purpose top-quality generator. It is slightly slower than SplitMix64Random,
but its period (2128 − 1) is sufficient for any single-thread application.
XorShift1024StarRandom is fast and provides a long period (21024 − 1) for massive parallel computations.
Both XorShift128PlusRandom and XorShift1024StarRandom
provide jump functions which make it possible to generate long non-overlapping sequences.
A table summarizing timings is provided below. Note that we test several different method parameters to show
the large gap between full 64-bit generators and ThreadLocalRandom.
ThreadLocalRandom
| SplittableRandom
| SplitMix64RandomGenerator
| XorShift128PlusRandom
| XorShift1024StarRandom
| |
|---|---|---|---|---|---|
| nextInt() | 1.72 | 1.26 | 1.17 | 1.47 | 2.18 |
| nextLong() | 1.66 | 1.25 | 1.19 | 1.35 | 2.07 |
| nextDouble() | 2.07 | 2.07 | 1.54 | 1.55 | 2.21 |
| nextInt(1000000) | 2.85 | 2.66 | 2.23 | 2.83 | 3.31 |
| nextInt(2^29+2^28) | 7.44 | 7.04 | 2.69 | 3.14 | 3.60 |
| nextInt(2^30) | 1.80 | 1.38 | 1.60 | 2.39 | 2.83 |
| nextInt(2^30+1) | 14.98 | 13.52 | 2.40 | 2.96 | 3.33 |
| nextInt(2^30+2^29) | 7.36 | 6.86 | 2.52 | 3.01 | 3.52 |
| nextLong(1000000000000) | 2.68 | 2.62 | 2.74 | 2.71 | 3.70 |
| nextLong(2^62+1) | 14.95 | 14.09 | 14.54 | 12.90 | 15.35 |
Unfortunately, we have no way to control the optimizations performed
by the JVM. In C, for example, we use
gcc's -fno-move-loop-invariants and -fno-unroll-loops options. These
options are essential to get a sensible result: without them, the
optimizer can move outside the testing loop constant loads (e.g.,
multiplicative constants). SplittableRandom and SplitMix64RandomGenerator
are particularly advantaged in this respect, as they contain three large constants whose
load can be moved outside the testing loop. The best advice is always that of measuring
the speed of your application with different generators.
The quality of all generators we provide is very high: for instance, they perform better than WELL1024a
or MT19937 (AKA the Mersenne Twister) in the TestU01 BigCrush test suite.
In particular, SplitMix64Random, XorShift128PlusRandom and XorShift1024StarRandom pass BigCrush.
More details can be found on the xorshift*/xorshift+ generators and the PRNG shootout page.
For each generator, we provide a version that extends Random, overriding (as usual) the next(int) method. Nonetheless,
since the generators are all inherently 64-bit also nextInt(), nextFloat(),
nextLong(), nextDouble(), nextBoolean()
and nextBytes(byte[]) have been overridden for speed (preserving, of course, Random's semantics).
In particular, nextDouble() and nextFloat()
use a multiplication-free conversion.
If you do not need an instance of Random, or if you need a RandomGenerator to use
with Commons Math, there is for each generator a corresponding RandomGenerator
implementation, which indeed we suggest to use in general if you do not need a generator implementing Random.