コード例 #1
0
ファイル: suffixtree.c プロジェクト: pombredanne/nmergec
/**
 * Find a location of the suffix in the tree.
 * @param st the suffixtree in question
 * @param j the extension number counting from 0
 * @param i the current phase - 1
 * @param log the log to record errors in
 * @return the position (combined node and edge-offset)
 */ 
static pos *find_beta( suffixtree *st, int j, int i, plugin_log *log )
{
    pos *p;
    if ( st->old_j > 0 && st->old_j == j )
    {
        p = pos_create();
        p->loc = st->old_beta.loc;
        p->v = st->old_beta.v;
    }
    else if ( j>i )  // empty string
    {
        p = pos_create();
        p->loc = 0;
        p->v = st->root;
    }
    else if ( j==0 )    // entire string
    {
        p = pos_create();
        p->loc = i;
        p->v = st->f;
    }
    else // walk across tree
    {
        node *v = st->last.v;
        int len = st->last.loc-node_start(st->last.v)+1;
        path *q = path_create( node_start(v), len, log );
        v = node_parent( v );
        while ( v != st->root && node_link(v)==NULL )
        {
            path_prepend( q, node_len(v) );
            v = node_parent( v );
        }
        if ( v != st->root )
        {
            v = node_link( v );
            p = walk_down( st, v, q );
        }
        else
        {
            path_dispose( q );
            p = walk_down( st, st->root, path_create(j,i-j+1,log) );
        }
    }
    st->last = *p;
    return p;
}
コード例 #2
0
ファイル: find-strings.c プロジェクト: bbyk/cwo
/**
 * Find a location of the suffix in the tree.
 * @param j the extension number counting from 0
 * @param i the current phase - 1
 * @return the position (combined node and edge-offset)
 */
static pos *find_beta( int j, int i )
{
    pos *p;
    if ( old_j > 0 && old_j == j )
    {
        p = pos_create();
        p->loc = old_beta.loc;
        p->v = old_beta.v;
    }
    else if ( j>i )  // empty string
    {
        p = pos_create();
        p->loc = 0;
        p->v = root;
    }
    else if ( j==0 )    // entire string
    {
        p = pos_create();
        p->loc = i;
        p->v = f;
    }
    else // walk across tree
    {
        node *v = last.v;
        int len = last.loc-node_start(last.v)+1;
        path *q = path_create( node_start(v), len );
        v = node_parent( v );
        while ( v != root && node_link(v)==NULL )
        {
            path_prepend( q, node_len(v) );
            v = node_parent( v );
        }
        if ( v != root )
        {
            v = node_link( v );
            p = walk_down( v, q );
        }
        else
        {
            path_dispose( q );
            p = walk_down( root, path_create(j,i-j+1) );
        }
    }
    last = *p;
    return p;
}
コード例 #3
0
/**
 * Try to make the new node into a parent of the tree-node n. The problem 
 * here is that we must include any siblings of n in r if they fit.
 * @param n the node above which to add the parent
 * @param r the new unattached node 
 */
static void dom_make_parent( dom *d, node *n, node *r )
{
    node *parent = node_parent(n);
    node *prev = node_prec_sibling( n );
    if ( parent==NULL )
        printf("parent is NULL\n");
    //fprintf( stderr,"n: %s %d:%d; r %s %d:%d\n",node_name(n),node_offset(n),
    //    node_end(n),node_name(r),node_offset(r),node_end(r));
    //node_debug_check_siblings( node_first_child(parent) );
    while ( n != NULL && !node_follows(r,n) )
    {
        node *next = node_next_sibling(n);
        if ( dom_nests(d,node_name(n),node_name(r)) )
        {
            if ( range_encloses_node(n,r) || range_equals_node(n,r) )
            {
                node_detach_sibling( n, prev );
                node_add_child( r, n );
                if ( node_overlaps_on_right(parent,r) )
                {
                    node_split( r, node_end(parent) );
                    node *r2 = node_next_sibling( r );
                    node_detach_sibling( r, NULL );
                    dom_store_range( d, node_to_range(r2) );
                    node_dispose( r2 );
                }
            }
            else if ( node_overlaps_on_left(n,r) )
            {
                node_split( n, node_end(r) );
                node_detach_sibling( n, prev );
                node_add_child( r, n );
                break;
            }
            else
                break;
        }
        else 
        {
            // split off the rest of r and and push it back
            // Q: what happens to r??
            node *r2;
            node_split( r, node_offset(n) );
            r2 = node_next_sibling( r );
            node_detach_sibling( r, NULL );
            dom_store_range( d, node_to_range(r2) );
            //queue_push( d->q, node_to_range(r2) );
            node_dispose( r2 );
            break;
        }
        n = next;
        if ( n != NULL )
            prev = node_prec_sibling( n );
    }
    // make n's original parent the parent of r
    node_add_child( parent, r );
   // node_debug_check_siblings( node_first_child(parent) );
}
コード例 #4
0
ファイル: xml.c プロジェクト: imp/slist
Boolean_t
tgt_node_process(xmlTextReaderPtr r, tgt_node_t **node)
{
	const xmlChar	*name;
	const xmlChar	*value;
	char		**ap;
	xmlElementType	node_type;
	tgt_node_t	*n;
	tgt_node_t	*an;

	n = *node;
	if (n == NULL) {
		n = node_alloc();
		if (n == NULL)
			return (False);
		*node = n;
	}

	name = (xmlChar *)xmlTextReaderConstName(r);
	if (name == NULL) {
		node_free(n);
		*node = NULL;
		return (False);
	}

	node_type = (xmlElementType)xmlTextReaderNodeType(r);

	value = (xmlChar *)xmlTextReaderConstValue(r);

	if (node_type == XML_ELEMENT_NODE) {
		if (n->x_state != NodeAlloc) {
			n = node_child(n);
			*node = n;
			if (n == NULL)
				return (False);
		}
		if (xmlTextReaderAttributeCount(r) > 0) {

			for (ap = common_attr_list; *ap; ap++) {
				value = xmlTextReaderGetAttribute(r,
				    (xmlChar *)*ap);

				if (value != NULL) {
					if ((an = node_alloc_attr(n)) == NULL)
						return (False);
					if (node_name(an, (xmlChar *)*ap) ==
					    False) {
						node_free(an);
						return (False);
					}
					if (node_value(an, value, True) ==
					    False) {
						node_free(an);
						return (False);
					}
					free((char *)value);
				}
			}
		}

		if (node_name(n, name) == False) {
			node_free(n);
			*node = NULL;
			return (False);
		}
	} else if ((value != NULL) && (node_type == XML_TEXT_NODE)) {
		if (node_value(n, value, True) == False) {
			node_free(n);
			*node = NULL;
			return (False);
		}
	} else if (node_type == XML_ELEMENT_DECL) {
		n = node_parent(n);
		if (n == NULL)
			return (False);
		*node = n;
	} else if (node_type == XML_COMMENT_NODE) {
		n = node_child(n);
		if (node_name(n, (xmlChar *)XML_COMMENT_STR) == False) {
			node_free(n);
			*node = NULL;
			return (False);
		}
		if (node_value(n, (xmlChar *)value, False) == False) {
			node_free(n);
			*node = NULL;
			return (False);
		}
	} else if (node_type != XML_DTD_NODE) {
		node_free(n);
		*node = NULL;
		return (False);
	}
	return (True);
}