Changeset 113 for trunk/src/helpers/tree.c
- Timestamp:
- Oct 23, 2001, 11:25:46 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/tree.c
r106 r113 285 285 * initializes the root of a tree. 286 286 * 287 */ 288 289 void treeInit(TREE **root) 287 *@@changed V0.9.16 (2001-10-19) [umoeller]: added plCount 288 */ 289 290 void treeInit(TREE **root, 291 PLONG plCount) // out: tree item count, set to 0 (ptr can be NULL) 290 292 { 291 293 *root = LEAF; 294 295 if (plCount) 296 *plCount = 0; // V0.9.16 (2001-10-19) [umoeller] 292 297 } 293 298 … … 511 516 * STATUS_DUPLICATE_KEY if a node with the 512 517 * same ulKey already exists. 518 * 519 *@@changed V0.9.16 (2001-10-19) [umoeller]: added plCount 513 520 */ 514 521 515 522 int treeInsert(TREE **root, // in: root of the tree 523 PLONG plCount, // in/out: item count (ptr can be NULL) 516 524 TREE *x, // in: new node to insert 517 525 FNTREE_COMPARE *pfnCompare) // in: comparison func … … 531 539 if (0 == (iResult = pfnCompare(key, current->ulKey))) // if (compEQ(key, current->key)) 532 540 return STATUS_DUPLICATE_KEY; 541 533 542 parent = current; 534 543 current = (iResult < 0) // compLT(key, current->key) … … 561 570 x); 562 571 // lastFind = NULL; 572 573 if (plCount) 574 (*plCount)++; // V0.9.16 (2001-10-19) [umoeller] 563 575 564 576 return STATUS_OK; … … 740 752 * Returns 0 if the node was deleted or 741 753 * STATUS_INVALID_NODE if not. 754 * 755 *@@changed V0.9.16 (2001-10-19) [umoeller]: added plCount 742 756 */ 743 757 744 758 int treeDelete(TREE **root, // in: root of the tree 759 PLONG plCount, // in/out: item count (ptr can be NULL) 745 760 TREE *tree) // in: tree node to delete 746 761 { … … 820 835 y); 821 836 837 if (plCount) 838 (*plCount)--; // V0.9.16 (2001-10-19) [umoeller] 839 822 840 return (STATUS_OK); 823 824 /* TREE *x,825 *y; */826 // *z;827 828 /*****************************829 * delete node z from tree *830 *****************************/831 832 // find node in tree833 /* if (lastFind && compEQ(lastFind->key, key))834 // if we just found node, use pointer835 z = lastFind;836 else {837 z = *root;838 while(z != LEAF)839 {840 int iResult = pfnCompare(key, z->key);841 if (iResult == 0)842 // if(compEQ(key, z->key))843 break;844 else845 z = (iResult < 0) // compLT(key, z->key)846 ? z->left847 : z->right;848 }849 if (z == LEAF)850 return STATUS_KEY_NOT_FOUND;851 }852 853 if ( z->left == LEAF854 || z->right == LEAF855 )856 {857 // y has a LEAF node as a child858 y = z;859 }860 else861 {862 // find tree successor with a LEAF node as a child863 y = z->right;864 while (y->left != LEAF)865 y = y->left;866 }867 868 // x is y's only child869 if (y->left != LEAF)870 x = y->left;871 else872 x = y->right;873 874 // remove y from the parent chain875 x->parent = y->parent;876 if (y->parent)877 if (y == y->parent->left)878 y->parent->left = x;879 else880 y->parent->right = x;881 else882 *root = x;883 884 // y is about to be deleted...885 886 if (y != z)887 {888 // now, the original code simply copied the data889 // from y to z... we can't safely do that since890 // we don't know about the real data in the891 // caller's TREE structure892 z->ulKey = y->ulKey;893 // z->rec = y->rec; // hope this works...894 // the original implementation used rec895 // for the node's data896 897 if (cbStruct > sizeof(TREE))898 {899 memcpy(((char*)&z) + sizeof(TREE),900 ((char*)&y) + sizeof(TREE),901 cbStruct - sizeof(TREE));902 }903 }904 905 if (y->color == BLACK)906 deleteFixup(root,907 x);908 909 // free(y);910 // lastFind = NULL;911 912 return STATUS_OK; */913 841 } 914 842 … … 1120 1048 1121 1049 TREE** treeBuildArray(TREE* pRoot, 1122 unsigned long *pulCount) // in: item count, out: array item count1050 PLONG plCount) // in: item count, out: array item count 1123 1051 { 1124 1052 TREE **papNodes = NULL, 1125 1053 **papThis = NULL; 1126 unsigned long cb = (sizeof(TREE*) * (*pulCount)),1054 long cb = (sizeof(TREE*) * (*plCount)), 1127 1055 cNodes = 0; 1128 1056 … … 1140 1068 // copy nodes to array 1141 1069 while ( pNode 1142 && cNodes < (*p ulCount) // just to make sure1070 && cNodes < (*plCount) // just to make sure 1143 1071 ) 1144 1072 { … … 1151 1079 1152 1080 // output count 1153 *p ulCount = cNodes;1081 *plCount = cNodes; 1154 1082 } 1155 1083 }
Note:
See TracChangeset
for help on using the changeset viewer.