00001 00008 #include "dkcRedBlackTree.h" 00009 00010 00011 DKC_INLINE DKC_RB_TREE_ROOT * WINAPI 00012 dkcAllocRedBlackTreeRoot(size_t node_max,size_t pool_max, 00013 DKC_RED_BLACK_TREE_DESTRUCTOR_F_TYPE destructor_) 00014 { 00015 DKC_RB_TREE_ROOT *p; 00016 if(NULL==destructor_) return NULL; 00017 p = dkcAllocate(sizeof(DKC_RB_TREE_ROOT)); 00018 if(NULL==p) return NULL; 00019 00020 dkcRedBlackTreeInitSentinelNode( 00021 dkcmREDBLACKTREE_NIL(p) 00022 ); 00023 00024 p->root = dkcmREDBLACKTREE_NIL(p); 00025 p->node_pool = dkcAllocSameObjectPool( 00026 sizeof(DKC_RED_BLACK_NODE),pool_max,NULL,NULL 00027 ); 00028 if(NULL==p->node_pool){ 00029 goto Error; 00030 } 00031 p->node_max = node_max; 00032 p->node_count = 0; 00033 p->destructor = destructor_; 00034 return p; 00035 Error: 00036 dkcFree(&p); 00037 return NULL; 00038 } 00039 00040 int WINAPI dkcFreeRedBlackTreeRoot(DKC_RB_TREE_ROOT **ptr) 00041 { 00042 if(NULL==ptr || NULL==*ptr) 00043 { 00044 return edk_ArgumentException; 00045 } 00046 00047 { 00048 DKC_RB_TREE_ROOT *p = *ptr; 00049 00050 dkcRedBlackTreeAllErase(p); 00051 00052 dkcFreeSameObjectPool(&(p->node_pool)); 00053 } 00054 return dkcFree(ptr); 00055 } 00056 00057 void WINAPI dkcRedBlackTreeAllErase(DKC_RB_TREE_ROOT *p) 00058 { 00059 rb_tree_data_type data = NULL; 00060 while(p->node_count != 0) 00061 { 00062 dkcRedBlackTree_deleteNode(p,p->root,&data); 00063 p->destructor(data); 00064 } 00065 00066 } 00067