IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14510


Ignore:
Timestamp:
Aug 15, 2007, 10:41:43 AM (19 years ago)
Author:
jhoblitt
Message:

add pxNodeFuncCountDependants()
add pxNodeHasChildren()
add pxNodeHasGrandChildren()

Location:
trunk/ippTools/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/pxtree.c

    r14494 r14510  
    7373}
    7474
     75// func() returning false means decend no futher along this branch
    7576
    76 bool pxTreeCrawl(pxNode *node, pxNodeFunc func)
     77bool pxTreeCrawl(pxNode *node, pxNodeFunc func, void *arg)
    7778{
    7879    // if func() returns false, stop
    79     if (!func(node)) {
     80    if (!func(arg, node)) {
    8081        return false;
    8182    }
     
    8485    pxNode *child = NULL;
    8586    while ((child = psListGetAndIncrement(iter))) {
    86         // if func() returns false, pxTreeCrawl() well return false, and we
    87         // should stop
    88         if (!pxTreeCrawl(child, func)) {
    89             return false;
    90         }
     87        pxTreeCrawl(child, func, arg);
    9188    }
    9289    psFree(iter);
     
    9491    return true;
    9592}
     93
     94bool pxNodeFuncCountDependants(void *arg, pxNode *node)
     95{
     96    (*(int *)arg)++;
     97    return true;
     98}
     99
     100bool pxNodeHasChildren(pxNode *node)
     101{
     102    int children = psListLength(node->children);
     103
     104    return children ? true : false;
     105}
     106
     107bool pxNodeHasGrandChildren(pxNode *node)
     108{
     109    // find out how many nodes there are lower in the tree
     110    // subtract the parent node from the count so we have just a tally of
     111    // decendants
     112    int nodes = -1;
     113    pxTreeCrawl(node, pxNodeFuncCountDependants, &nodes);
     114    psTrace("pxtree", PS_LOG_INFO, "node %s has %d dependants", node->name, nodes);
     115
     116    // find out how many children this node has
     117    int children = psListLength(node->children);
     118    psTrace("pxtree", PS_LOG_INFO, "node %s has %d children", node->name, children);
     119
     120    if (!children) {
     121        // no children
     122        return false;
     123    }
     124
     125    if (nodes < children) {
     126        psAbort("you can't have fewer children than decendants!");
     127    }
     128
     129    if (nodes == children) {
     130        // no grandchildren
     131        return false;
     132    }
     133
     134    return true;
     135}
  • trunk/ippTools/src/pxtree.h

    r14494 r14510  
    3333} pxNode;
    3434
    35 typedef bool (*pxNodeFunc)(pxNode *node);
     35typedef bool (*pxNodeFunc)(void *arg, pxNode *node);
    3636
    3737pxNode *pxNodeAlloc(
     
    4747bool pxTreeCrawl(
    4848    pxNode  *node,
    49     pxNodeFunc func
     49    pxNodeFunc func,
     50    void    *arg
    5051);
     52
     53bool pxNodeFuncCountDependants(void *arg, pxNode *node);
     54
     55bool pxNodeHasChildren(pxNode *node);
     56
     57bool pxNodeHasGrandChildren(pxNode *node);
     58
    5159
    5260/*
Note: See TracChangeset for help on using the changeset viewer.