public class LowStorageShuffler
extends java.lang.Object
implements java.io.Serializable
next()
on a LowStorageShuffler
to get the next distinct int in the shuffled ordering; next() will return -1 if there are no more distinct ints (if
bound
items have already been returned). You can go back to the previous item with previous()
,
which similarly returns -1 if it can't go earlier in the sequence. You can restart the sequence with
restart()
to use the same sequence over again, or restart(long)
to use a different seed (the bound
is fixed).
round(long, long)
method used here reuses the CrossHash.Water.wow(long, long)
method; it acts like an unbalanced, irreversible PRNG with two states, and that turns out to be just fine for a
Feistel network. This also uses a different seed for each round.
ShuffledIntSequence
, which extends this class and uses different
behavior so it "re-shuffles" the results when all results have been produced.
Modifier and Type | Field and Description |
---|---|
int |
bound |
protected int |
halfBits |
protected int |
index |
protected long |
key0 |
protected long |
key1 |
protected long |
key2 |
protected long |
key3 |
protected int |
leftMask |
protected int |
pow4 |
protected int |
rightMask |
Constructor and Description |
---|
LowStorageShuffler()
Constructs a LowStorageShuffler with a random seed and a bound of 10.
|
LowStorageShuffler(int bound)
Constructs a LowStorageShuffler with the given exclusive upper bound and a random seed.
|
LowStorageShuffler(int bound,
long seed)
Constructs a LowStorageShuffler with the given exclusive upper bound and int seed.
|
Modifier and Type | Method and Description |
---|---|
LowStorageShuffler |
copy()
Fully copies this LowStorageShuffler, including its current index in its sequence and internal seeds.
|
static LowStorageShuffler |
deserializeFromString(java.lang.String data) |
int |
encode(int index)
Encodes an index with a 4-round Feistel network.
|
boolean |
equals(java.lang.Object o) |
int |
hashCode() |
int |
next()
Gets the next distinct int in the sequence, or -1 if all distinct ints have been returned that are non-negative
and less than
bound . |
int |
previous()
Gets the previous returned int from the sequence (as yielded by
next() ), or -1 if next() has never been
called (or the LowStorageShuffler has reached the beginning from repeated calls to this method). |
void |
restart()
Starts the same sequence over from the beginning.
|
void |
restart(long seed)
Starts the sequence over, but can change the seed (completely changing the sequence).
|
static int |
round(long data,
long seed) |
java.lang.String |
serializeToString() |
public final int bound
protected int index
protected int pow4
protected int halfBits
protected int leftMask
protected int rightMask
protected long key0
protected long key1
protected long key2
protected long key3
public LowStorageShuffler()
public LowStorageShuffler(int bound)
bound
- how many distinct ints this can returnpublic LowStorageShuffler(int bound, long seed)
bound
- how many distinct ints this can returnseed
- any int; will be used to get several seeds used internallypublic int next()
bound
.public int previous()
next()
), or -1 if next() has never been
called (or the LowStorageShuffler has reached the beginning from repeated calls to this method).public void restart()
public void restart(long seed)
seed
is the same
as the seed given in the constructor, this will use the same sequence, acting like restart()
.seed
- any int; will be used to get several seeds used internallypublic static int round(long data, long seed)
public int encode(int index)
public LowStorageShuffler copy()
public java.lang.String serializeToString()
public static LowStorageShuffler deserializeFromString(java.lang.String data)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
Copyright © Eben Howard 2012–2022. All rights reserved.