/*
 * add (or just increment) an arc
 */
void
addarc(
nltype *parentp,
nltype *childp,
unsigned long count,
unsigned long order)
{
    arctype *arcp;

#ifdef DEBUG
	if(debug & TALLYDEBUG){
	    printf("[addarc] %lu arcs from %s to %s\n" ,
		   count, parentp->name, childp->name);
	}
#endif
	arcp = arclookup(parentp, childp);
	if(arcp != NULL){
	    /*
	     * a hit: just increment the count.
	     */
#ifdef DEBUG
	    if(debug & TALLYDEBUG){
		printf("[tally] hit %ld += %lu\n",
		       arcp->arc_count, count);
	    }
#endif
	    arcp->arc_count += count;
	    return;
	}
	arcp = (arctype *)calloc(1, sizeof(arctype));
	arcp->arc_parentp = parentp;
	arcp->arc_childp = childp;
	arcp->arc_count = count;
	arcp->arc_order = order;
	/*
	 * Prepend this child to the children of this parent.
	 */
	arcp->arc_childlist = parentp->children;
	parentp->children = arcp;
	/*
	 * Prepend this parent to the parents of this child.
	 */
	arcp->arc_parentlist = childp->parents;
	childp->parents = arcp;
}
示例#2
0
文件: arcs.c 项目: Alkzndr/freebsd
    /*
     *	add (or just increment) an arc
     */
void
addarc(nltype *parentp, nltype *childp, long count)
{
    arctype		*arcp;

#   ifdef DEBUG
	if ( debug & TALLYDEBUG ) {
	    printf( "[addarc] %ld arcs from %s to %s\n" ,
		    count , parentp -> name , childp -> name );
	}
#   endif /* DEBUG */
    arcp = arclookup( parentp , childp );
    if ( arcp != 0 ) {
	    /*
	     *	a hit:  just increment the count.
	     */
#	ifdef DEBUG
	    if ( debug & TALLYDEBUG ) {
		printf( "[tally] hit %ld += %ld\n" ,
			arcp -> arc_count , count );
	    }
#	endif /* DEBUG */
	arcp -> arc_count += count;
	return;
    }
    arcp = (arctype *)calloc( 1 , sizeof *arcp );
    if (arcp == NULL)
	errx( 1 , "malloc failed" );
    arcp -> arc_parentp = parentp;
    arcp -> arc_childp = childp;
    arcp -> arc_count = count;
	/*
	 *	prepend this child to the children of this parent
	 */
    arcp -> arc_childlist = parentp -> children;
    parentp -> children = arcp;
	/*
	 *	prepend this parent to the parents of this child
	 */
    arcp -> arc_parentlist = childp -> parents;
    childp -> parents = arcp;
}