Distinct generator for integral ranges.
More...
|
| | distinct_range (T left, T right) |
| | Creates distinct generator for values in given range.
|
| count_type | size () const |
| | Returns the number of values left to generate.
|
| T | gen () |
| | Generates a distinct random value in the defined range.
|
| auto | gen_list (int count) |
| | Generates a list of several distinct values.
|
| auto | gen_all () |
| | Generates all distinct values left to generate.
|
template<typename T>
struct tgen::distinct_range< T >
Distinct generator for integral ranges.
Examples
std::cout << u.gen() << " " << u.gen() << " " << u.gen() << std::endl;
Distinct generator for integral ranges.
Definition at line 1158 of file tgen.h.
◆ distinct_range()
Creates distinct generator for values in given range.
- Parameters
-
| left | Left endpoint of the range. |
| right | Right endpoint of the range. |
The generator will generate values in [l, r].
Examples
Definition at line 1175 of file tgen.h.
◆ gen()
Generates a distinct random value in the defined range.
- Returns
- A value in the given range that has not been generated before, uniformly at random.
- Exceptions
-
| std::runtime_error | if there no more values to generate. |
Time complexity
O(log(n)) for the n-th call of gen.
Examples
std::cout << u.gen() << " " << u.gen() << " " << u.gen() << std::endl;
Definition at line 1184 of file tgen.h.
◆ gen_all()
Generates all distinct values left to generate.
- Returns
- A uniformly random tgen::list::value with all distinct values from the range that have not been generated yet.
- Exceptions
-
Time complexity
Expected O(r), where r is the number of remaining values.
Examples
auto gen_all()
Generates all distinct values left to generate.
Definition at line 1267 of file tgen.h.
◆ gen_list()
Generates a list of several distinct values.
- Returns
- A uniformly random tgen::list::value with size distinct values from the range.
- Exceptions
-
| std::runtime_error | if there are not enough values to generate. |
Time complexity
Expected O(size), except when first materializing a small remaining range of r values as a dense pool, which costs O(r). Later batches reuse that pool. All draws share state with distinct_range::gen.
Examples
auto gen_list(int count)
Generates a list of several distinct values.
Definition at line 1214 of file tgen.h.
◆ size()
Returns the number of values left to generate.
- Returns
- The number of values left to generate, as count_type: uint64_t for coordinate types smaller than 64 bits, or unsigned __int128 for 64-bit types. The wider count can represent all 2^64 values of a full 64-bit range.
Time complexity
O(1).
Examples
u.gen(), u.gen();
std::cout << u.size() << std::endl;
Definition at line 1179 of file tgen.h.
The documentation for this struct was generated from the following files:
- /home/runner/work/tgen/tgen/single_include/tgen.h
- base.dox