Beispiel #1
0
/**
 * Extend the implicit suffix tree by adding one suffix of the current prefix
 * @param j the offset into str of the suffix's start
 * @param i the offset into str at the end of the current prefix
 * @return 1 if the phase continues else 0
 */
static int extension( int j, int i )
{
    int res = 1;
    pos *p = find_beta( j, i-1 );
    // rule 1 (once a leaf always a leaf)
    if ( node_is_leaf(p->v) && pos_at_edge_end(p) )
        res = 1;
    // rule 2
    else if ( !continues(p,str[i]) )
    {
        //printf("applying rule 2 at j=%d for phase %d\n",j,i);
        node *leaf = node_create_leaf( i );
        if ( p->v==root || pos_at_edge_end(p) )
        {
            node_add_child( p->v, leaf );
            update_current_link( p->v );
        }
        else
        {
            node *u = node_split( p->v, p->loc );
            update_current_link( u );
            if ( i-j==1 )
            {
                node_set_link( u, root );
#ifdef DEBUG
                verify_link( current );
#endif
            }
            else
                current = u;
            node_add_child( u, leaf );
        }
        update_old_beta( p, i );
    }
    // rule 3
    else
    {
        //printf("applying rule 3 at j=%d for phase %d\n",j,i);
        update_current_link( p->v );
        update_old_beta( p, i );
        res = 0;
    }
    free( p );
    return res;
}
Beispiel #2
0
/**
 * Extend the implicit suffix tree by adding one suffix of the current prefix
 * @param st the current suffixtree
 * @param j the offset into str of the suffix's start
 * @param i the offset into str at the end of the current prefix
 * @param log the log to record errors in
 * @return 1 if the phase continues else 0
 */
static int extension( suffixtree *st, int j, int i, plugin_log *log )
{
    int res = 1;
    pos *p = find_beta( st, j, i-1, log );
    // rule 1 (once a leaf always a leaf)
    if ( node_is_leaf(p->v) && pos_at_edge_end(st,p) )
        res = 1;
    // rule 2
    else if ( !continues(st,p,st->str[i]) )
    {
        //printf("applying rule 2 at j=%d for phase %d\n",j,i);
        node *leaf = node_create_leaf( i, log );
        if ( p->v==st->root || pos_at_edge_end(st,p) )
        {
            node_add_child( p->v, leaf, st->str, log );
            update_current_link( st, p->v );
        }
        else
        {
            node *u = node_split( p->v, p->loc, st->str, log );
            update_current_link( st, u );
            if ( i-j==1 )
            {
                node_set_link( u, st->root );
#ifdef DEBUG
                verify_link( current );
#endif
            }
            else 
                st->current = u;
            node_add_child( u, leaf, st->str, log );
        }
        update_old_beta( st, p, i );
    }
    // rule 3
    else
    {
        //printf("applying rule 3 at j=%d for phase %d\n",j,i);
        update_current_link( st, p->v );
        update_old_beta( st, p, i );
        res = 0;
    }
    free( p );
    return res;
}
Beispiel #3
0
bool CWSAThread::startup()
{
    m_maxwsaeventsize = WSA_MAXIMUM_WAIT_EVENTS;
    m_keepalivetimeout = CGlobalConfig::getInstance()->getKeepaliveTimer();
    m_keepaliveinterval = m_keepalivetimeout / 2;
    m_serverip = CGlobalConfig::getInstance()->getListenIp();
    m_serverport = CGlobalConfig::getInstance()->getListenPort();

    m_sendbufsize = CGlobalConfig::getInstance()->getSocketSendBuf();
    m_readbufsize = CGlobalConfig::getInstance()->getSocketRecvBuf();

    m_recvbuflen = m_sendbufsize;
    if (m_sendbufsize < m_readbufsize)
    {
        m_recvbuflen = m_readbufsize;
    }
    if (m_recvbuflen < MAX_SEND_SIZE)
    {
        m_recvbuflen = MAX_SEND_SIZE;
    }
    m_recvbuflen += MAX_SEND_SIZE;

    m_recvbuffer = new char[m_recvbuflen];
    if (!m_recvbuffer)
    {
        LOG(_ERROR_, "CWSAThread::startup() error, _new char[m_recvbuflen] failed, m_recvbuflen=%d", m_recvbuflen);
        exit(-1);
    }

    if (!doListen())
    {
        LOG(_ERROR_, "CWSAThread::startup() error, doListen() failed");
        return false;
    }

    if (!start())
    {
        LOG(_ERROR_, "CWSAThread::startup() error, start() failed");
        return false;
    }

    continues();

    return true;
}