Function malachite_base::strings::exhaustive::shortlex_strings_using_chars
source · pub fn shortlex_strings_using_chars<I: Clone + Iterator<Item = char>>(
cs: I,
) -> StringsFromCharVecs<ShortlexVecs<char, PrimitiveIntIncreasingRange<u64>, I>> ⓘ
Expand description
Generates [String
]s with char
s from a specified iterator, in shortlex order.
Shortlex order means that the [String
]s are output from shortest to longest, and [String
]s
of the same length are output in lexicographic order with respect to the ordering of the
char
s specified by the input iterator.
cs
must be finite; if it’s infinite, only [String
]s of length 0 and 1 are ever produced.
If cs
is empty, the output length is 1; otherwise, the output is infinite.
The lengths of the output [String
]s grow logarithmically.
§Complexity per iteration
$T(i) = O(\log i)$
$M(i) = O(\log i)$
where $T$ is time and $M$ is additional memory.
§Examples
use itertools::Itertools;
use malachite_base::strings::exhaustive::shortlex_strings_using_chars;
let ss = shortlex_strings_using_chars('x'..='z')
.take(20)
.collect_vec();
assert_eq!(
ss.iter().map(String::as_str).collect_vec().as_slice(),
&[
"", "x", "y", "z", "xx", "xy", "xz", "yx", "yy", "yz", "zx", "zy", "zz", "xxx", "xxy",
"xxz", "xyx", "xyy", "xyz", "xzx"
]
);