Changeset 14510
- Timestamp:
- Aug 15, 2007, 10:41:43 AM (19 years ago)
- Location:
- trunk/ippTools/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pxtree.c
r14494 r14510 73 73 } 74 74 75 // func() returning false means decend no futher along this branch 75 76 76 bool pxTreeCrawl(pxNode *node, pxNodeFunc func )77 bool pxTreeCrawl(pxNode *node, pxNodeFunc func, void *arg) 77 78 { 78 79 // if func() returns false, stop 79 if (!func( node)) {80 if (!func(arg, node)) { 80 81 return false; 81 82 } … … 84 85 pxNode *child = NULL; 85 86 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); 91 88 } 92 89 psFree(iter); … … 94 91 return true; 95 92 } 93 94 bool pxNodeFuncCountDependants(void *arg, pxNode *node) 95 { 96 (*(int *)arg)++; 97 return true; 98 } 99 100 bool pxNodeHasChildren(pxNode *node) 101 { 102 int children = psListLength(node->children); 103 104 return children ? true : false; 105 } 106 107 bool 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 33 33 } pxNode; 34 34 35 typedef bool (*pxNodeFunc)( pxNode *node);35 typedef bool (*pxNodeFunc)(void *arg, pxNode *node); 36 36 37 37 pxNode *pxNodeAlloc( … … 47 47 bool pxTreeCrawl( 48 48 pxNode *node, 49 pxNodeFunc func 49 pxNodeFunc func, 50 void *arg 50 51 ); 52 53 bool pxNodeFuncCountDependants(void *arg, pxNode *node); 54 55 bool pxNodeHasChildren(pxNode *node); 56 57 bool pxNodeHasGrandChildren(pxNode *node); 58 51 59 52 60 /*
Note:
See TracChangeset
for help on using the changeset viewer.
