private function addChar( $pChar ) {
        $this->text[++$this->position]  = $pChar;
        $this->needSuffixLink           = -1;
        $this->remainder++;

        while( $this->remainder > 0 ) {
            if ( $this->activeLength === 0 ) {
                $this->activeEdge = $this->position;
            }
            
            if ( !array_key_exists( $this->getActiveEdge(), $this->nodes[$this->activeNode]->next ) ) {
                // suffix does not exist in the parent
                $leaf = $this->newNode( $this->position, $this->upperBound );
                $this->nodes[$this->activeNode]->next[$this->getActiveEdge()] = $leaf;
                $this->addSuffixLink( $this->activeNode );
            } else {
                $next = $this->nodes[$this->activeNode]->next[$this->getActiveEdge()];
                if ( $this->walkDown( $next ) ) {
                    continue;
                }
                if ( $this->text[$this->nodes[$next]->start + $this->activeLength] === $pChar ) {
                    $this->activeLength++;
                    $this->addSuffixLink( $this->activeNode );
                    break;
                }
                $split = $this->newNode( $this->nodes[$next]->start, $this->nodes[$next]->start + $this->activeLength );
                $this->nodes[$this->activeNode]->next[$this->getActiveEdge()] = $split;
                $leaf = $this->newNode( $this->position, $this->upperBound );

                $this->nodes[$split]->next[$pChar] = $leaf;
                $this->nodes[$next]->start += $this->activeLength;
                $this->nodes[$split]->next[$this->text[$this->nodes[$next]->start]] = $next;
                $this->addSuffixLink( $split );
            }
            $this->remainder--;

            if ( $this->activeNode == $this->root && $this->activeLength > 0 ) {
                $this->activeLength--;
                $this->activeEdge = $this->position - $this->remainder + 1;
            } else {
                if ( $this->nodes[$this->activeNode]->link > 0 ) {
                    $this->activeNode = $this->nodes[$this->activeNode]->link;
                } else {
                    $this->activeNode = $this->root;
                }
            }
        }
    }
private function addChar( $pChar ) {
        $this->text[++$this->position]  = $pChar;
        $this->needSuffixLink           = -1;
        $this->remainder++;

        while( $this->remainder > 0 ) {
            if ( $this->activeLength === 0 ) {
                $this->activeEdge = $this->position;
            }
            
            if ( !array_key_exists( $this->getActiveEdge(), $this->nodes[$this->activeNode]->next ) ) {
                // suffix does not exist in the parent
                $leaf = $this->newNode( $this->position, $this->upperBound );
                $this->nodes[$this->activeNode]->next[$this->getActiveEdge()] = $leaf;
                $this->addSuffixLink( $this->activeNode );
            } else {
                $next = $this->nodes[$this->activeNode]->next[$this->getActiveEdge()];
                if ( $this->walkDown( $next ) ) {
                    continue;
                }
                if ( $this->text[$this->nodes[$next]->start + $this->activeLength] === $pChar ) {
                    $this->activeLength++;
                    $this->addSuffixLink( $this->activeNode );
                    break;
                }
                $split = $this->newNode( $this->nodes[$next]->start, $this->nodes[$next]->start + $this->activeLength );
                $this->nodes[$this->activeNode]->next[$this->getActiveEdge()] = $split;
                $leaf = $this->newNode( $this->position, $this->upperBound );

                $this->nodes[$split]->next[$pChar] = $leaf;
                $this->nodes[$next]->start += $this->activeLength;
                $this->nodes[$split]->next[$this->text[$this->nodes[$next]->start]] = $next;
                $this->addSuffixLink( $split );
            }
            $this->remainder--;

            if ( $this->activeNode == $this->root && $this->activeLength > 0 ) {
                $this->activeLength--;
                $this->activeEdge = $this->position - $this->remainder + 1;
            } else {
                if ( $this->nodes[$this->activeNode]->link > 0 ) {
                    $this->activeNode = $this->nodes[$this->activeNode]->link;
                } else {
                    $this->activeNode = $this->root;
                }
            }
        }
    }
private function addChar ( $ pChar ) { $ this -> text [ ++ $ this -> position ] = $ pChar ; $ this -> needSuffixLink = - 1 ; $ this -> remainder ++ ; while ( $ this -> remainder > 0 ) { if ( $ this -> activeLength === 0 ) { $ this -> activeEdge = $ this -> position ; } if ( ! array_key_exists ( $ this -> getActiveEdge ( ) , $ this -> nodes [ $ this -> activeNode ] -> next ) ) { // suffix does not exist in the parent $ leaf = $ this -> newNode ( $ this -> position , $ this -> upperBound ) ; $ this -> nodes [ $ this -> activeNode ] -> next [ $ this -> getActiveEdge ( ) ] = $ leaf ; $ this -> addSuffixLink ( $ this -> activeNode ) ; } else { $ next = $ this -> nodes [ $ this -> activeNode ] -> next [ $ this -> getActiveEdge ( ) ] ; if ( $ this -> walkDown ( $ next ) ) { continue ; } if ( $ this -> text [ $ this -> nodes [ $ next ] -> start + $ this -> activeLength ] === $ pChar ) { $ this -> activeLength ++ ; $ this -> addSuffixLink ( $ this -> activeNode ) ; break ; } $ split = $ this -> newNode ( $ this -> nodes [ $ next ] -> start , $ this -> nodes [ $ next ] -> start + $ this -> activeLength ) ; $ this -> nodes [ $ this -> activeNode ] -> next [ $ this -> getActiveEdge ( ) ] = $ split ; $ leaf = $ this -> newNode ( $ this -> position , $ this -> upperBound ) ; $ this -> nodes [ $ split ] -> next [ $ pChar ] = $ leaf ; $ this -> nodes [ $ next ] -> start += $ this -> activeLength ; $ this -> nodes [ $ split ] -> next [ $ this -> text [ $ this -> nodes [ $ next ] -> start ] ] = $ next ; $ this -> addSuffixLink ( $ split ) ; } $ this -> remainder -- ; if ( $ this -> activeNode == $ this -> root && $ this -> activeLength > 0 ) { $ this -> activeLength -- ; $ this -> activeEdge = $ this -> position - $ this -> remainder + 1 ; } else { if ( $ this -> nodes [ $ this -> activeNode ] -> link > 0 ) { $ this -> activeNode = $ this -> nodes [ $ this -> activeNode ] -> link ; } else { $ this -> activeNode = $ this -> root ; } } } }
Adds a single character to the suffix tree.
Updates edges as well as nodes

@param string $pChar A single character
Adds a single character to the suffix tree . Updates edges as well as nodes