diff options
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -0,0 +1,54 @@ +#include "sptree.h" +#include <stdio.h> + +int fcmp(const double* a, const double* b){ + if(*a < *b) return -1; + if(*a > *b) return 1; + return 0; +} + +int main(){ + void* ptr, *ptrl, *ptrr; + double key; int val, i; + ctl_sptree_init(&ptr, sizeof(double), sizeof(int), fcmp); + + for(i = 0; i < 5; i++){ + key = i, val = i + 5; + ctl_sptree_add(&ptr, &key, &val); + } + printf("before\n"); + key = 0; + val = *(int*)ctl_sptree_find(&ptr, &key); + printf("key = %.2f, %d\n", key, val); + key = 3; + ctl_sptree_del(&ptr, &key); + key = 0; + val = *(int*)ctl_sptree_find(&ptr, &key); + printf("key = %.2f, %d\n", key, val); + + printf("+++++++++\n"); + key = 2.7; + ctl_sptree_split(&ptr, &key, &ptrl, &ptrr); + + key = 4; + val = *(int*)ctl_sptree_find(&ptrr, &key); + printf("after\n"); + printf("key = %.2f, %d\n", key, val); + key = 4; ctl_sptree_del(&ptrr, &key); + + ptr = ctl_sptree_merge(&ptrl, &ptrr); + printf("=========\n"); + + for(i = 0; i < 5; i++){ + key = i + 0.2, val = i + 5; + ctl_sptree_add(&ptr, &key, &val); + } + + key = 2.2; + val = *(int*)ctl_sptree_find(&ptr, &key); + printf("key = %.2f, %d\n", key, val); + + + ctl_sptree_free(&ptr); + return 0; +} |