T
- The element class which is iterated.public class RandomSubsetIterator<T> extends SubsetIterator<T>
Modifier and Type | Field and Description |
---|---|
private double |
allSubsets
Only used when avoidDuplicats is set to true.
|
private boolean |
avoidDuplicates
Whether to avoid duplicates in the iteration.
|
private long |
generatedSubsets
Only used when avoidDuplicats is set to true.
|
private java.util.Random |
random
The random number generator.
|
private java.util.List<T> |
set
The set over which subsets are iterated.
|
private boolean |
switched
Only used when avoidDuplicats is set to true.
|
private java.util.Set<java.util.BitSet> |
temp
Only used when avoidDuplicats is set to true.
|
Constructor and Description |
---|
RandomSubsetIterator(java.util.Set<T> set,
boolean avoidDuplicates)
Creates a new subset iterator for the given set.
|
Modifier and Type | Method and Description |
---|---|
private java.util.BitSet |
generate(int length,
boolean checkForDuplicates)
Generates a new bit set of the given length.
|
private java.util.BitSet |
generateRandomly(int length)
Generates a random bit set of the given length.
|
boolean |
hasNext() |
private void |
increment(java.util.BitSet bitSet)
Increments the given bit set
|
java.util.Set<T> |
next() |
getSet, remove
private java.util.List<T> set
private boolean avoidDuplicates
private java.util.Random random
private java.util.Set<java.util.BitSet> temp
private long generatedSubsets
private double allSubsets
private boolean switched
public RandomSubsetIterator(java.util.Set<T> set, boolean avoidDuplicates)
set
- some set.avoidDuplicates
- whether to avoid duplicates in the iteration.
NOTE: setting this value to true might increase computation time
and needed space drastically.public boolean hasNext()
hasNext
in interface java.util.Iterator<java.util.Set<T>>
hasNext
in class SubsetIterator<T>
public java.util.Set<T> next()
next
in interface java.util.Iterator<java.util.Set<T>>
next
in class SubsetIterator<T>
private void increment(java.util.BitSet bitSet)
bitSet
- some bit set.private java.util.BitSet generate(int length, boolean checkForDuplicates)
length
- the length of the bit set.checkForDuplicates
- whether to check for duplicates (see above).private java.util.BitSet generateRandomly(int length)
length
- some length.