Code Library Of Others/sgtlaugh/Palindrome Tree.cpp
inline bool insert(char ch){
        S[slen++] = ch, cur = nextlink(cur);
        int c = ch - 'a', flag = trie[cur][c]; /// Change here if any non-lower case character can occur

        if (!flag){
            len[idx] = len[cur] + 2;
            link[idx] = trie[nextlink(link[cur])][c];
            trie[cur][c] = idx++;
        }

        cur = trie[cur][c];
        counter[cur]++; /// count of palindromic substring cur in the string
        lps = max(lps, len[cur]); /// Update the longest palindromic substring after adding this character
        return !flag;
    }
/// Returns true if a new distinct palindromic substring appears after adding current character
Returns true if a new distinct palindromic substring appears after adding current character
Returns true if a new distinct palindromic substring appears after adding current character
inline bool insert(char ch){
        S[slen++] = ch, cur = nextlink(cur);
        int c = ch - 'a', flag = trie[cur][c]; 
        if (!flag){
            len[idx] = len[cur] + 2;
            link[idx] = trie[nextlink(link[cur])][c];
            trie[cur][c] = idx++;
        }
        cur = trie[cur][c];
        counter[cur]++; 
        lps = max(lps, len[cur]); 
        return !flag;
    }
inline bool insert ( char ch ) { S [ slen ++ ] = ch , cur = nextlink ( cur ) ; int c = ch - ' ' , flag = trie [ cur ] [ c ] ; if ( ! flag ) { len [ idx ] = len [ cur ] + 2 ; link [ idx ] = trie [ nextlink ( link [ cur ] ) ] [ c ] ; trie [ cur ] [ c ] = idx ++ ; } cur = trie [ cur ] [ c ] ; counter [ cur ] ++ ; lps = max ( lps , len [ cur ] ) ; return ! flag ; }
Returns true if a new distinct palindromic substring appears after adding current character
Returns true if a new distinct palindromic substring appears after adding current character
/// Change here if any non-lower case character can occur /// count of palindromic substring cur in the string /// Update the longest palindromic substring after adding this character