Fast word datatype using an array of unsigned char.
Bases: sage.combinat.words.word_datatypes.WordDatatype
A Fast class for words represented by an array unsigned char *.
Currently, only handles letters in [0,255].
Test whether other is a prefix of self.
INPUT:
EXAMPLES:
sage: W = Words([0,1,2])
sage: w = W([0,1,1,0,1,2,0])
sage: w.has_prefix([0,1,1])
True
sage: w.has_prefix([0,1,2])
False
sage: w.has_prefix(w)
True
sage: w.has_prefix(w[:-1])
True
sage: w.has_prefix(w[1:])
False
Return whether the word is empty.
EXAMPLES:
sage: W = Words([0,1,2])
sage: W([0,1,2,2]).is_empty()
False
sage: W([]).is_empty()
True
Returns True if self is a square, and False otherwise.
EXAMPLES:
sage: w = Word([n % 4 for n in range(48)], alphabet=[0,1,2,3])
sage: w.is_square()
True
sage: w = Word([n % 4 for n in range(49)], alphabet=[0,1,2,3])
sage: w.is_square()
False
sage: (w*w).is_square()
True
TESTS:
The above tests correspond to the present class (char):
sage: type(w)
<class 'sage.combinat.words.word.FiniteWord_char'>
sage: Word([], alphabet=[0,1]).is_square()
True
sage: Word([0], alphabet=[0,1]).is_square()
False
sage: Word([0,0], alphabet=[0,1]).is_square()
True
Return the length of the word as a Sage integer.
EXAMPLES:
sage: W = Words([0,1,2,3,4])
sage: w = W([0,1,2,0,3,2,1])
sage: w.length()
7
sage: type(w.length())
<type 'sage.rings.integer.Integer'>
sage: type(len(w))
<type 'int'>
Return the list of letters that appear in this word, listed in the order of first appearance.
EXAMPLES:
sage: W = Words(5)
sage: W([1,3,1,2,2,3,1]).letters()
[1, 3, 2]
This function exists only because it is not possible to use yield in the special method __reversed__.
EXAMPLES:
sage: W = Words([0,1,2])
sage: w = W([0,1,0,0,1,2])
sage: list(reversed(w)) # indirect doctest
[2, 1, 0, 0, 1, 0]