libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
StringRange

Defined in word-range.hpp.

This class implements a range object for strings and produces the same output as WordRange() | ToString("ab"), but is more convenient in some cases.

Note
There is a small overhead to using a StringRange object rather than using cbegin_wislo or cbegin_wilo directly.

The order and range of the words in a StringRange instance can be set using the member functions:

Example
StringRange strings;
strings.order(Order::shortlex) // strings in shortlex order
.alphabet("ab") // on 2 letters
.min(1) // of length in the range from 1
.max(5); // to 5
StringRange & min(size_type val)
Set the first string in the range by length.
Definition word-range.hpp:1886
StringRange & max(size_type val)
Set one past the last string in the range by length.
Definition word-range.hpp:1909
StringRange & alphabet(std::string const &x)
Set the alphabet.
StringRange & order(Order val)
Set the order of the strings in the range.
Definition word-range.hpp:1827
StringRange()
Default constructor.
Definition word-range.hpp:1696
@ shortlex
Definition order.hpp:54
See also
WordRange

Public Types

using output_type = std::string const&
 The type of the output of the range object.
 
using size_type = typename std::vector<std::string>::size_type
 Alias for the size type.
 

Public Member Functions

 StringRange ()
 Default constructor.
 
 StringRange (StringRange &&)
 Default move constructor.
 
 StringRange (StringRange const &)
 Default copy constructor.
 
std::string const & alphabet () const noexcept
 The current alphabet.
 
StringRangealphabet (std::string const &x)
 Set the alphabet.
 
bool at_end () const noexcept
 Check if the range object is exhausted.
 
auto begin () const noexcept
 Returns an input iterator pointing to the first string in the range.
 
size_t count () const noexcept
 The actual size of the range.
 
auto end () const noexcept
 Returns an input iterator pointing one beyond the last string in the range.
 
std::string first () const noexcept
 The current first string in the range.
 
StringRangefirst (std::string const &frst)
 Set the first string in the range.
 
output_type get () const
 Get the current value.
 
StringRangeinit ()
 Initialize an existing StringRange object.
 
std::string last () const noexcept
 The current one past the last string in the range.
 
StringRangelast (std::string const &lst)
 Set one past the last string in the range.
 
StringRangemax (size_type val)
 Set one past the last string in the range by length.
 
StringRangemin (size_type val)
 Set the first string in the range by length.
 
void next () noexcept
 Advance to the next value.
 
StringRangeoperator= (StringRange &&)
 Default move assignment operator.
 
StringRangeoperator= (StringRange const &)
 Default copy assignment operator.
 
Order order () const noexcept
 The current order of the strings in the range.
 
StringRangeorder (Order val)
 Set the order of the strings in the range.
 
size_t size_hint () const noexcept
 The possible size of the range.
 
size_type upper_bound () const noexcept
 The current upper bound on the length of a string in the range.
 
StringRangeupper_bound (size_type n)
 Set an upper bound for the length of a string in the range.
 

Constructor & Destructor Documentation

◆ StringRange()

StringRange ( )
inline

Constructs an empty range with:

Member Function Documentation

◆ alphabet() [1/2]

std::string const & alphabet ( ) const
inlinenodiscardnoexcept

Returns the current alphabet in a StringRange object.

Returns
A value of type string.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ alphabet() [2/2]

StringRange & alphabet ( std::string const & x)

Sets the alphabet in a StringRange object.

Parameters
xthe alphabet.
Returns
A reference to *this.
Exceptions
LibsemigroupsExceptionif x contains repeated letters.

◆ at_end()

bool at_end ( ) const
inlinenoexcept

Returns true if a StringRange object is exhausted, and false if not.

Returns
A value of type bool.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ begin()

auto begin ( ) const
inlinenoexcept

This function returns an input iterator pointing to the first string in a StringRange object.

Returns
An input iterator.
Exceptions
This function is noexcept and is guaranteed never to throw.
Note
The return type of end might be different from the return type of begin.
See also
end.

◆ count()

size_t count ( ) const
inlinenoexcept

Returns the number of words in the range object. If order() is Order::shortlex, then size_hint() is used. If order() is not Order::shortlex, then a copy of the range may have to be looped over in order to find the return value of this function.

Returns
A value of type size_t.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ end()

auto end ( ) const
inlinenoexcept

This function returns an input iterator pointing one beyond the last string in a StringRange object.

Returns
An input iterator.
Exceptions
This function is noexcept and is guaranteed never to throw.
Note
The return type of end might be different from the return type of begin.
See also
begin.

◆ first() [1/2]

std::string first ( ) const
inlinenodiscardnoexcept

Returns the first string in a StringRange object.

Returns
A string by value.
Exceptions
This function is noexcept and is guaranteed never to throw.
See also
min

◆ first() [2/2]

StringRange & first ( std::string const & frst)
inline

Sets the first string in a StringRange object to be frst.

Parameters
frstthe first string.
Returns
A reference to *this.
Note
Unlike WordRange::first, this function will throw if frst contains letters not belonging to alphabet().
See also
min

◆ get()

output_type get ( ) const
inline

Returns the current string in a StringRange object.

Returns
A value of type output_type.
Exceptions
This function is noexcept and is guaranteed never to throw.
Warning
If at_end() returns true, then the return value of this function could be anything.

◆ init()

StringRange & init ( )

This function puts a StringRange object back into the same state as if it had been newly default constructed.

Returns
A reference to *this.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ last() [1/2]

std::string last ( ) const
inlinenodiscardnoexcept

Returns one past the last string in a StringRange object.

Returns
A string by value.
Exceptions
This function is noexcept and is guaranteed never to throw.
See also
max

◆ last() [2/2]

StringRange & last ( std::string const & lst)
inline

Sets one past the last string in a StringRange object to be lst.

Parameters
lstone past the last string.
Returns
A reference to *this.
Exceptions
LibsemigroupsExceptionif lst contains letters not belonging to alphabet().
Note
The behaviour of this function is not exactly the same as WordRange::last(word_type const&). That function will not throw if a word contains letters not in the alphabet.
See also
max

◆ max()

StringRange & max ( size_type val)
inline

Sets one past the last string in a StringRange object to be \(\alpha^n\) where \(\alpha\) is the first letter of alphabet() (or "a" if the alphabet is empty) and \(n\) corresponds to val.

Parameters
valthe exponent.
Returns
A reference to *this.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ min()

StringRange & min ( size_type val)
inline

Sets the first string in a StringRange object to be pow("a", val) (the string consisting of val letters equal to "a").

Parameters
valthe exponent.
Returns
A reference to *this.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ next()

void next ( )
inlinenoexcept

Advances a StringRange object to the next value (if any).

Exceptions
This function is noexcept and is guaranteed never to throw.
See also
at_end

◆ order() [1/2]

Order order ( ) const
inlinenodiscardnoexcept

Returns the current order of the strings in a StringRange object.

Returns
A value of type Order.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ order() [2/2]

StringRange & order ( Order val)
inline

Sets the order of the strings in a StringRange object to val.

Parameters
valthe order.
Returns
A reference to *this.
Exceptions
LibsemigroupsExceptionif val is not Order::shortlex or Order::lex.

◆ size_hint()

size_t size_hint ( ) const
inlinenoexcept

Returns the number of words in a StringRange object if order() is Order::shortlex. If order() is not Order::shortlex, then the return value of this function is meaningless.

Returns
A value of type size_t.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ upper_bound() [1/2]

size_type upper_bound ( ) const
inlinenodiscardnoexcept

Returns the current upper bound on the length of a string in a StringRange object. This setting is only used if order() is Order::lex.

Returns
A value of type size_type.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ upper_bound() [2/2]

StringRange & upper_bound ( size_type n)
inline

Sets an upper bound for the length of a string in a StringRange object. This setting is only used if order() is Order::lex.

Parameters
nthe upper bound.
Returns
A reference to *this.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

Member Data Documentation

◆ is_idempotent

bool is_idempotent = true
staticconstexpr

Value indicating that if get() is called twice on a StringRange object that is not changed between the two calls, then the return value of get() is the same both times.


The documentation for this class was generated from the following file: