Changeset 15221
- Timestamp:
- Oct 4, 2007, 1:35:32 PM (19 years ago)
- Location:
- trunk/ippTools/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pxtree.c
r15190 r15221 32 32 psFree(node->parent); 33 33 psFree(node->children); 34 psFree(node->data); 34 35 } 35 36 … … 43 44 node->parent = NULL; 44 45 node->children = psListAlloc(NULL); 46 node->data = NULL; 45 47 46 48 psMemSetDeallocator(node, (psFreeFunc) pxNodeFree); … … 69 71 // [re]parent the child 70 72 child->parent = psMemIncrRefCounter(node); 73 74 return node; 75 } 76 77 pxNode *pxNodeAddData(pxNode *node, psPtr data) 78 { 79 node->data = psMemIncrRefCounter(data); 71 80 72 81 return node; … … 151 160 pxNode *pxTreeFromMetadata(psMetadata *md) 152 161 { 153 psHash * nodeNames= psHashAlloc(10);162 psHash *forest = psHashAlloc(10); 154 163 155 164 psMetadataIterator *iter = psMetadataIteratorAlloc(md, 0, NULL); … … 160 169 } 161 170 171 // add this node to the forest and hopefully it'll get attached to the 172 // root tree 173 pxTreeBuilder(forest, item->name, item->data.str, NULL); 174 } 175 psFree(iter); 176 177 pxNode *root = psHashLookup(forest, "root"); 178 psFree(forest); 179 180 return psMemIncrRefCounter(root); 181 } 182 183 psHash *pxTreeBuilder(psHash *forest, 184 const char *nodeName, 185 const char *childName, 186 psPtr data) 187 { 188 // try to find a node with this name 189 pxNode *node = psHashLookup(forest, nodeName); 190 if (!node) { 191 // create a new node with this name 192 node = pxNodeAlloc(nodeName); 193 if (data) { 194 pxNodeAddData(node, data); 195 } 196 // add it to the hash of nodes 197 psHashAdd(forest, nodeName, node); 198 // node may be used below because it will still have a ref count of 199 // 1 from being on the hash, this is equivalent to the "view" we 200 // get from a hashlookup 201 psFree(node); 202 } 203 204 // does this node declare a child? 205 if (childName) { 162 206 // try to find a node with this name 163 pxNode * node = psHashLookup(nodeNames, item->name);164 if (! node) {207 pxNode *child = psHashLookup(forest, childName); 208 if (!child ) { 165 209 // create a new node with this name 166 node = pxNodeAlloc(item->name);210 child = pxNodeAlloc(childName); 167 211 // add it to the hash of nodes 168 psHashAdd( nodeNames, item->name, node);169 // node may be used below because it will still have a ref count of170 // 1 from being on the hash, this is equivalent to the "view" we171 // get from a hashlookup172 psFree( node);212 psHashAdd(forest, childName, child); 213 // child may be used below because it will still have a ref 214 // count of 1 from being on the hash, this is equivalent to the 215 // "view" we get from a hashlookup 216 psFree(child); 173 217 } 174 175 // does this node declare a child? 176 if (item->data.str) { 177 // try to find a node with this name 178 pxNode *child = psHashLookup(nodeNames, item->data.str); 179 if (!child ) { 180 // create a new node with this name 181 child = pxNodeAlloc(item->data.str); 182 // add it to the hash of nodes 183 psHashAdd(nodeNames, item->data.str, child); 184 // child may be used below because it will still have a ref 185 // count of 1 from being on the hash, this is equivalent to the 186 // "view" we get from a hashlookup 187 psFree(child); 188 } 189 pxNodeAddChild(node, child); 190 } 191 } 192 psFree(iter); 193 194 pxNode *root = psHashLookup(nodeNames, "root"); 195 psFree(nodeNames); 196 197 return psMemIncrRefCounter(root); 198 } 218 pxNodeAddChild(node, child); 219 } 220 221 return forest; 222 } -
trunk/ippTools/src/pxtree.h
r15187 r15221 31 31 struct pxNode *parent; 32 32 psList *children; 33 void *data; 33 34 } pxNode; 34 35 … … 41 42 pxNode *pxNodeAddParent(pxNode *node, pxNode *parent); 42 43 pxNode *pxNodeAddChild(pxNode *node, pxNode *child); 44 pxNode *pxNodeAddData(pxNode *node, psPtr data); 43 45 44 46 void pxNodePrint( … … 61 63 pxNode *pxTreeFromMetadata(psMetadata *md); 62 64 65 psHash *pxTreeBuilder(psHash *forest, 66 const char *nodeName, 67 const char *childName, 68 psPtr data); 69 63 70 #endif // PXTREE_H
Note:
See TracChangeset
for help on using the changeset viewer.
