Home </br>Permutation Generators </br>Combination Generators </br>Set/Subset Generators </br>Cartesian Product Generators </br>Math Functions </br>Ranking Algorithms </br>Number System Algorithms
JNumberTools provides the following 7 generators for sets and subsets. All mth generators are BigInteger compatible, enabling rapid generation of subsets at very large indices, such as 10100.
Currently Available Algorithms
Generates all subsets of a given set in lexicographical order, including the empty set (φ). For example, for the set [“A”, “B”, “C”], it generates: [], [A], [B], [C], [A, B], [A, C], [B, C], [A, B, C].
// All subsets of ["Apple", "Banana", "Guava"] in lex order
JNumberTools.subsets()
.of("Apple", "Banana", "Guava")
.all()
.lexOrder()
.stream().toList();
Generates every mth subset of a given set in lexicographical order, starting from a given index. This API directly generates the desired subset without iterating through preceding subsets, making it highly efficient.
// Every 1 billionth subset of numbers in range [0,40) starting from 0th index
JNumberTools.subsets()
.of(40)
.all()
.lexOrderMth(1_000_000_000, 0)
.stream().toList();
Generates all subsets within a specified size range in lexicographical order. For example, for the set [“A”, “B”, “C”] with size range [2,3], it generates: [A, B], [A, C], [B, C], [A, B, C].
// All subsets of ["Apple", "Banana", "Guava"] in size range [2,3] in lex order
JNumberTools.subsets()
.of("Apple", "Banana", "Guava")
.inRange(2, 3)
.lexOrder()
.stream().toList();
Generates every mth subset within a specified size range in lexicographical order, starting from a given index. This API directly generates the desired subset without computing preceding subsets.
// Every 1 billionth subset of numbers in range [0,40) with size range [10,39] starting from 0th index
JNumberTools.subsets()
.of(40)
.inRange(10, 39)
.lexOrderMth(1_000_000_000, 0)
.stream().toList();
Generates n random subsets with duplicates allowed.
// Generate 5 random subsets of numbers in range [0,10) with duplicates
JNumberTools.subsets()
.of(10)
.all()
.choice(5)
.stream().forEach(System.out::println);
// Generate 5 random subsets of ["Apple", "Banana", "Guava"] with duplicates
JNumberTools.subsets()
.of("Apple", "Banana", "Guava")
.all()
.choice(5)
.stream().forEach(System.out::println);
Generates n random subsets without duplicates.
// Generate 5 random subsets of numbers in range [0,10) without duplicates
JNumberTools.subsets()
.of(10)
.all()
.sample(5)
.stream().forEach(System.out::println);
// Generate 5 random subsets of ["Apple", "Banana", "Guava"] without duplicates
JNumberTools.subsets()
.of("Apple", "Banana", "Guava")
.all()
.sample(5)
.stream().forEach(System.out::println);
Generates subsets at indices specified by a custom sequence.
// Generates subsets of numbers in range [0,100) at specified indices
var iterable = List.of(10, 20, 1_000_000_000L, new BigInteger("1000000000000000000000"));
JNumberTools.subsets()
.of(100)
.all()
.byRanks(iterable)
.stream().toList();
Home </br>Permutation Generators </br>Combination Generators </br>Set/Subset Generators </br>Cartesian Product Generators </br>Math Functions </br>Ranking Algorithms </br>Number System Algorithms