/***************************************************************************************
author :LuoShuai[bupt]
time :2023.01.28[First edition]
explain :test for map.h
Contact :3573202382@qq.com
****************************************************************************************/
#include "map.h"
typedef struct testStruct{
char numChar;
short numShort;
int numInt;
long numLong;
double numDouble;
char ptrChar[20];
}testStruct;
void print_test(testStruct * teststruct){
printf("testStruct val :\n");
printf("\t\tnumChar :%c[%-2d]\n" , teststruct->numChar ,teststruct->numChar );
printf("\t\tnumShort :%d\n" , teststruct->numShort);
printf("\t\tnumInt :%d\n" , teststruct->numInt);
printf("\t\tnumLong :%ld\n" , teststruct->numLong);
printf("\t\tnumDouble:%lf\n" , teststruct->numDouble);
printf("\t\tptrChar :%s\n" , teststruct->ptrChar);
}
int main()
{
testStruct teststruct;
//调用初始化函数 , 传入key , val的类型和长度
AvlTree *tree = init_avltree( __KV_INT__ , __KV_PTR__ , 0 ,sizeof(teststruct));
int i ,j;
//插入26条数据 , 可以只插入key
for(i=0;i<26;i++){
avl_insert(tree , &i);
}
//打印前序和后序 ,判断是否建立成功
printf("前序:");
avl_prv_trav(tree);
printf("\n");
printf("中序:");
avl_ino_trav(tree);
printf("\n");
//为26个KEY插入26个VAL , 每个VAL为 testStruct类型
for(i=0;i<26;i++){
//为每个KEY,生成不同的VAL
teststruct.numChar = 'A'+i;
teststruct.numShort = i;
teststruct.numInt = 100+i;
teststruct.numLong = 1000+i;
teststruct.numDouble = 0.1+i;
for(j=0;j<19;j++){
teststruct.ptrChar[j] = 'A'+i;
}
teststruct.ptrChar[19] = 0;
avl_addinfo(tree , &i , &teststruct);
}
//根据key查找val
Value *val;
testStruct * ret;
for(i=0;i<26;i++){
printf("findKey:%-2d " , i);
val = avl_find(tree , &i);
ret = (testStruct *)val->ptrKV;
print_test(ret);
}
free_avltree(tree);
}