The StringRange class
Class for generating strings in a given range and in a particular order.
The StringRange
class implements a range object for strings and produces the
same output as WordRange() | ToString("ab")
, but is more convenient in some
cases.
The order and range of the words in a StringRange
instance can be set
using the member functions:
See also
Example
>>> from libsemigroups_pybind11 import StringRange, Order
>>> strings = StringRange();
>>> strings.order(Order.shortlex) \
... .alphabet("ba") \
... .min(1) \
... .max(5)
<StringRange of length 30 in shortlex order>
>>> strings.order()
<Order.shortlex: 1>
>>> from libsemigroups_pybind11 import ToWord
>>> strings.alphabet("a").min(0).max(10)
<StringRange of length 10 in shortlex order>
>>> wrds = strings | ToWord("a")
>>> list(wrds)
[[], [0], [0, 0], [0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
Contents
Class for generating strings in a given range and in a particular order. |
|
Overloaded function. |
|
Check if the range object is exhausted. |
|
Copy a |
|
The actual size of the range. |
|
Overloaded function. |
|
Get the current value. |
|
Initialize an existing |
|
Overloaded function. |
|
Set one past the last string in the range by length. |
|
Set the first string in the range by length. |
|
Advance to the next value. |
|
Overloaded function. |
|
The possible size of the range. |
|
Overloaded function. |
Full API
- class StringRange
- __init__(self: StringRange) None
Default constructor. Constructs an empty range with:
StringRange.min()
equal to0
;StringRange.max()
equal to0
;StringRange.order()
equal toOrder.shortlex
;StringRange.first()
equal to the empty string;StringRange.last()
equal to the empty string;StringRange.upper_bound()
equal to0
;StringRange.alphabet()
equal to the empty string.
- alphabet(*args, **kwargs)
Overloaded function.
- alphabet(self: StringRange) str
The current alphabet.
Returns the current alphabet in a
StringRange
object.- Returns:
The current alphabet.
- Return type:
- alphabet(self: StringRange, x: str) StringRange
Set the alphabet.
Sets the alphabet in a
StringRange
object.- Parameters:
x (str) – the alphabet.
- Returns:
self.
- Return type:
- Raises:
LibsemigroupsError – if x contains repeated letters.
- at_end(self: StringRange) bool
Check if the range object is exhausted.
Returns
True
if aStringRange
object is exhausted, andFalse
if not.- Returns:
Whether the object is exhausted.
- Return type:
- copy(self: StringRange) StringRange
Copy a
StringRange
object.- Returns:
A copy.
- Return type:
- count(self: StringRange) int
The actual size of the range.
Returns the number of strings in the range object. If
StringRange.order()
isOrder.shortlex
, thenStringRange.size_hint()
is used. Iforder()
is notOrder.shortlex
, then a copy of the range may have to be looped over in order to find the return value of this function.- Returns:
The size of the range.
- Return type:
- first(*args, **kwargs)
Overloaded function.
- first(self: StringRange) str
The current first string in the range.
Returns the first string in a
StringRange
object.- Returns:
The first string.
- Return type:
See also
- first(self: StringRange, frst: str) StringRange
Set the first string in the range.
Sets the first string in a
StringRange
object to be frst.- Parameters:
frst (str) – the first string.
- Returns:
self.
- Return type:
See also
- get(self: StringRange) str
Get the current value.
Returns the current string in a
StringRange
object.- Returns:
The current value.
- Return type:
- init(self: StringRange) StringRange
Initialize an existing
StringRange
object.This function puts a
StringRange
object back into the same state as if it had been newly default constructed.- Returns:
self.
- Return type:
- last(*args, **kwargs)
Overloaded function.
- last(self: StringRange) str
The current one past the last string in the range.
Returns one past the last string in a
StringRange
object.- Returns:
One past the last string.
- Return type:
See also
- last(self: StringRange, lst: str) StringRange
Set one past the last string in the range.
Sets one past the last string in a
StringRange
object to be lst.- Parameters:
lst (str) – the first string.
- Returns:
self.
- Return type:
- Raises:
LibsemigroupsError – if lst contains letters not belonging to
StringRange.alphabet()
.
See also
- max(self: StringRange, val: int) StringRange
Set one past the last string in the range by length.
Sets one past the last string in a
StringRange
object to be \(\alpha^n\) where \(\alpha\) is the first letter ofStringRange.alphabet
(or"a"
if the alphabet is empty) and \(n\) corresponds to val.- Parameters:
val (int) – the exponent.
- Returns:
self.
- Return type:
- min(self: StringRange, val: int) StringRange
Set the first string in the range by length.
Sets the first string in a
StringRange
object to be \(\alpha^n\) where \(\alpha\) is the first letter ofStringRange.alphabet
(or"a"
if the alphabet is empty) and \(n\) corresponds to val.- Parameters:
val (int) – the exponent.
- Returns:
self.
- Return type:
- next(self: StringRange) None
Advance to the next value.
Advances a
StringRange
object to the next value (if any).See also
- order(*args, **kwargs)
Overloaded function.
- order(self: StringRange) Order
The current order of the strings in the range.
Returns the current order of the strings in a
StringRange
object.- Returns:
The current order.
- Return type:
- order(self: StringRange, val: Order) StringRange
Set the order of the strings in the range.
Sets the order of the strings in a
StringRange
object to val.- Parameters:
val (Order) – the order.
- Returns:
self.
- Return type:
- Raises:
LibsemigroupsError – if val is not
Order.shortlex
orOrder.lex
.
- size_hint(self: StringRange) int
The possible size of the range.
Returns the number of words in a
StringRange
object ifStringRange.order()
isOrder.shortlex
. Iforder()
is notOrder.shortlex
, then the return value of this function is meaningless.- Returns:
A value of type
int
.- Return type:
- upper_bound(self: StringRange, n: int) StringRange
Overloaded function.
- upper_bound(self: StringRange) int
The current upper bound on the length of a string in the range.
Returns the current upper bound on the length of a string in a
StringRange
object. This setting is only used ifStringRange.order()
isOrder.lex
.
- upper_bound(self: StringRange, n: int) StringRange
Set an upper bound for the length of a string in the range.
Sets an upper bound for the length of a string in a
StringRange
object. This setting is only used ifStringRange.order()
isOrder.lex
.- Parameters:
n (int) – the upper bound.
- Returns:
self.
- Return type: