Fast word datatype using an array of unsigned char.

class sage.combinat.words.word_char.WordDatatype_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].

has_prefix(other)

Test whether other is a prefix of self.

INPUT:

  • other – a word or a sequence (e.g. tuple, list)

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
is_empty()

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
is_square()

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
length()

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'>
letters()

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]
sage.combinat.words.word_char.reversed_word_iterator(w)

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]