示例#1
0
//searches for a token with regex
static const dtree_dt_node *dtree_search_node(const dtree_dt_index *h,const dtree_dt_node *n,const char *t,dtree_pos_f pos)
{
    unsigned int hash;
    dtree_flag_f rf,nf;
    packed_ptr pp;
    const dtree_dt_node *rflag;
    
    if(!n || !n->curr)
        return NULL;
    
    //bad match
    if(n->data!=*t && n->data!=(*t|0x20) && n->data!=DTREE_PATTERN_ANY)
        return NULL;
    
    t++;
    hash=dtree_hash_char(*t);
    
    //EOS
    if(!hash && *t!='0')
    {
        //only quit if strong with position
        if(dtree_get_flag(h,n,DTREE_DT_FLAG_STRONG,pos))
            return n;
        else if(!n->flags)
            return NULL;
    }
    
    pp=n->nodes[hash];
    rflag=DTREE_DT_GETPP(h,pp);
    
    if(pp)
        rflag=dtree_search_node(h,rflag,t,pos);
    else
        rflag=NULL;
    
    //wildcard
    if(!rflag)
    {
        hash=DTREE_HASH_ANY;
        
        pp=n->nodes[hash];
        rflag=DTREE_DT_GETPP(h,pp);
        
        if(pp)
            rflag=dtree_search_node(h,rflag,t,pos);
        else
            rflag=NULL;
        
        hash=dtree_hash_char(*t);
    }
    
    //n is lazy EOT or stronger match
    if((n->flags & DTREE_DT_FLAG_TOKEN) && ((!hash && *t!='0') || hash>=DTREE_HASH_SEP))
    {
        nf=dtree_get_flags(h,n,pos);
        rf=dtree_get_flags(h,rflag,pos);
        
        if(!rflag)
            rflag=n;
        else if((nf & DTREE_DT_FLAG_STRONG) && !(rf & DTREE_DT_FLAG_STRONG))
            rflag=n;
        else if(rf & DTREE_DT_FLAG_STRONG);
        else if((nf & DTREE_DT_FLAG_CHAIN) && !(nf & DTREE_DT_FLAG_BCHAIN) &&
                !(rf & DTREE_DT_FLAG_CHAIN) && !(rf & DTREE_DT_FLAG_BCHAIN))
            rflag=n;
        else if(rf & DTREE_DT_FLAG_CHAIN);
        else if((nf & DTREE_DT_FLAG_WEAK) && !(rf & DTREE_DT_FLAG_WEAK))
            rflag=n;
    }
    
    return rflag;
}
示例#2
0
//searches for a token with regex
static const dtree_dt_node *dtree_search_node(const dtree_dt_index *h,const dtree_dt_node *n,const char *t)
{
    int hash;
    flag_f rf,nf;
    packed_ptr pp;
    const dtree_dt_node *rflag;
    
    if(!n)
        return NULL;
    
    //bad match
    if(n->data!=*t && n->data!=(*t|0x20) && n->data!=DTREE_PATTERN_ANY)
        return NULL;
    
    t++;
    hash=dtree_hash_char(*t);
    
    //lazy EOT
    if((!hash && *t!='0') || hash>=DTREE_HASH_SEP)
    {
        //only quit if strong
        if(dtree_get_flag(h,n,DTREE_DT_FLAG_STRONG))
            return n;
        else if(!t && !n->flags)
            return NULL;
    }
    
    pp=n->nodes[hash];
    rflag=DTREE_DT_GETPP(h,pp);
    
    if(rflag && *t)
        rflag=dtree_search_node(h,rflag,t);
    
    //wildcard
    if(!rflag)
    {
        hash=dtree_hash_char(DTREE_PATTERN_ANY);
        
        pp=n->nodes[hash];
        rflag=DTREE_DT_GETPP(h,pp);
        
        if(rflag)
            rflag=dtree_search_node(h,rflag,t);
        
        hash=dtree_hash_char(*t);
    }
    
    //partial
    if(!rflag && (n->flags & DTREE_DT_FLAG_TOKEN) && (h->sflags & DTREE_S_FLAG_PARTIAL))
    {
        if(dtree_node_depth(h,n)>=DTREE_S_PART_TLEN)
            rflag=n;
    }
    
    //n is lazy EOT or stronger match
    if((n->flags & DTREE_DT_FLAG_TOKEN) && ((hash==0 && *t!='0') || hash>=DTREE_HASH_SEP))
    {
        nf=dtree_get_flags(h,n);
        rf=dtree_get_flags(h,rflag);
        
        if(!rflag)
            rflag=n;
        else if((nf & DTREE_DT_FLAG_STRONG) && !(rf & DTREE_DT_FLAG_STRONG))
            rflag=n;
        else if((rf & DTREE_DT_FLAG_STRONG));
        else if((nf & DTREE_DT_FLAG_CHAIN) && !(nf & DTREE_DT_FLAG_BCHAIN) &&
                !(rf & DTREE_DT_FLAG_CHAIN) && !(rf & DTREE_DT_FLAG_BCHAIN))
            rflag=n;
        else if((rf & DTREE_DT_FLAG_CHAIN));
        else if((nf & DTREE_DT_FLAG_WEAK))
            rflag=n;
    }
    
    return rflag;
}
示例#3
0
//gets the flag for a token
const dtree_dt_node *dtree_get_node(const dtree_dt_index *h,const char *t,dtree_flag_f sflags,dtree_pos_f pos)
{
    unsigned int hash;
    char n;
    const char *p;
    packed_ptr pp;
    const dtree_dt_node *base;
    const dtree_dt_node *lflag=NULL;
    
    if(!sflags)
        sflags=h->sflags;
    
    if(sflags & DTREE_S_FLAG_REGEX)
    {
        pp=h->head->nodes[dtree_hash_char(*t)];
        base=DTREE_DT_GETPP(h,pp);
        
        lflag=dtree_search_node(h,base,t,pos);
        
        //leading wildcard
        if(!lflag)
        {
            pp=h->head->nodes[DTREE_HASH_ANY];
            base=DTREE_DT_GETPP(h,pp);
            
            if(pp)
                lflag=dtree_search_node(h,base,t,pos);
        }
        
        return lflag;
    }
    
    pp=h->head->nodes[dtree_hash_char(*t)];
    base=DTREE_DT_GETPP(h,pp);
    
    //iterative search
    for(p=t;*p && pp;p++)
    {
        if(base->data!=*p && base->data!=(*p|0x20) && base->data!=DTREE_PATTERN_ANY)
            break;
   
        n=*(p+1);
        hash=dtree_hash_char(n);
        
        //token match
        if((!hash && n!='0') || hash>=DTREE_HASH_SEP)
        {
            //match is valid with position
            if(base->flags && (sflags & DTREE_S_FLAG_PARTIAL || !n) &&
                    (!base->pos || !pos || base->pos==pos))
                return base;
            else if(!n)
                break;
        }
        
        pp=base->nodes[hash];
        base=DTREE_DT_GETPP(h,pp);
    }

    return lflag;
}
示例#4
0
//gets the flag for a token
const dtree_dt_node *dtree_get_node(const dtree_dt_index *h,const char *t,flag_f sflags)
{
    int hash;
    char n;
    const char *p;
    packed_ptr pp;
    const dtree_dt_node *base;
    const dtree_dt_node *lflag=NULL;
    
    if(!sflags)
        sflags=h->sflags;
    
    if(sflags & DTREE_S_FLAG_REGEX)
    {
        pp=h->head->nodes[dtree_hash_char(*t)];
        base=DTREE_DT_GETPP(h,pp);
        
        lflag=dtree_search_node(h,base,t);
        
        //leading wildcard
        if(!lflag)
        {
            pp=h->head->nodes[dtree_hash_char(DTREE_PATTERN_ANY)];
            base=DTREE_DT_GETPP(h,pp);
            
            if(pp)
                lflag=dtree_search_node(h,base,t);
        }
        
        return lflag;
    }
            
    pp=h->head->nodes[dtree_hash_char(*t)];
    base=DTREE_DT_GETPP(h,pp);
    
    //iterative search
    for(p=t;*p && pp;p++)
    {
        if(base->data!=*p && base->data!=(*p|0x20) && base->data!=DTREE_PATTERN_ANY)
            break;
   
        n=*(p+1);
        hash=dtree_hash_char(n);
        
        //token match
        if((!hash && n!='0') || hash>=DTREE_HASH_SEP)
        {
            //not full string
            if(base->flags && (sflags & DTREE_S_FLAG_PARTIAL) && n)
                return base;
            //full token
            else if(base->flags && !n)
                return base;
            else if(!n)
                break;
        }
        
        //partial token match
        if((base->flags & DTREE_DT_FLAG_TOKEN) && (sflags & DTREE_S_FLAG_PARTIAL) && (p+1-t)>=DTREE_S_PART_TLEN)
            lflag=base;
        
        pp=base->nodes[hash];
        base=DTREE_DT_GETPP(h,pp);
    }

    return lflag;
}