Strings in lexicographic order (silo)¶
The functions libsemigroups::cbegin_silo()
and
libsemigroups::cend_silo()
can be used to iterate through strings in
lexicographic order in some range.
-
const_silo_iterator libsemigroups::cbegin_silo(std::string const &alphabet, size_t const upper_bound, std::string const &first, std::string const &last)¶
Returns a forward iterator pointing to the 3rd parameter
first
.If incremented, the iterator will point to the next least lexicographic string after
w
overalphabet
with length less thanupper_bound
. Iterators of the type returned by this function are equal whenever they are obtained by advancing the return value of any call tocbegin_silo
by the same amount, or they are both obtained by any call tocend_silo
.See also
- Example
std::vector<std::string>(cbegin_silo("ba", 3, "b", "aaa"), cend_silo("ba", 3, "b", "aaa")); // {"b", "bb", "ba", "a", "ab", "aa"};
Note
The parameter
upper_bound
is required because lexicographical ordering is not a well-ordering, and there might be infinitely many strings between a given pair of strings.Warning
Copying iterators of this type is expensive. As a consequence, prefix incrementing
++it
the iteratorit
returned bycbegin_silo
is significantly cheaper than postfix incrementingit++
.Warning
Iterators constructed using different parameters may not be equal, so best not to loop over them.
- Parameters
alphabet – the alphabet
upper_bound – only strings of length less than this value are considered;
first – the starting point for the iteration;
last – the ending point for the iteration.
- Throws
(None) – This function guarantees not to throw a
LibsemigroupsException
.- Returns
An iterator of type
const_silo_iterator
.
-
const_silo_iterator libsemigroups::cend_silo(std::string const &alphabet, size_t const upper_bound, std::string const &first, std::string const &last)¶
Returns a forward iterator pointing to one after the end of the range from
first
tolast
.The iterator returned by this is still dereferenceable and incrementable, but does not point to a string in the correct range.
See also