public class Factor
This class is used by class FactorSequence to create a linked list of factors of a text as induced by its Lempel-Ziv (LZ78) factorisation.
Each instance of this class represent a string composed of its an ancestor factor's string plus one character, and contains:
class FactorSequence,
class FactorSequenceprotected Factor ancestor
A pointer to this factor's ancestor, which represents a prefix of this factor's text.
protected Factor next
A pointer to the next factor.
protected int serial_number
This factor's serial number, which indicates the order of this factor inside the linked list of factors of a text.
protected int length
The number of characters of the text represented by this factor.
protected char new_char
The new character of this factor.
public Factor()
Creates a new empty Factor. It has no ancestor and no character (both are set to null). Its serial number is set to zero as well as its length.
This constructor is used to initiate the a linked list of factors of a text. Its next pointer is initially null, but it is typically set to point to the first factor afterwards (with the setNext method).
#setNextpublic Factor(Factor ancestor, int serial_number, char new_char)
Creates a new Factor instance with the specified serial number and new character, and pointing to the given ancestor. Its length is set to its ancestor's length plus 1.
Its next pointer is initially null, but it is typically set to point to the next factor afterwards (with the setNext method).
ancestor - this factor's ancestorserial_number - this factor's serial numbernew_char - this factor's new character#setNextpublic void setNext(Factor next)
Sets this factor's next pointer to point to the specified factor. Although the next factor has typically a serial number equal to this factor's serial number plus 1, no attempt is made to guarantee this rule. This allows special constructs or a different order in the factorisation.
next - the factor that will be pointed to#getNextpublic Factor getAncestor()
Returns this factor's ancestor factor.
public int getAncestorSerialNumber()
This method is a shorthand to return the serial number of this factor's ancestor. Note that it does not check if this factor has an ancestor or not, therefore, if it is called on the root factor, a NullPointerException is raised.
public Factor getNext()
Returns this factor's next factor.
#setNextpublic int getSerialNumber()
Returns this factor's serial number.
public int length()
Returns this factor's length.
public char getNewChar()
Returns this factor's new character.
public java.lang.String toString()
Returns a string representation of the text represented by this factor. It inspects its chain of ancestors up until as far as the root factor, spelling their new characters out.