/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ #include #include #include #include "IntMap.h" #if QUIET #define show(x,y) #define printTree1(x) /* depth of tree is 23 */ #define MAX (8 * 1024 * 1024) #else #define show(x,y) showTree0(x,y) #define printTree1(x) printTree(x) #define MAX 128 #endif void printKeyAttr(Key k, Attr a) { printf("%ld :-> %ld\n", k, a); } void printTree(Tree t) { foreach(printKeyAttr,t); } int main(void) { #if ! QUIET { IntMap t1 = empty; show("{}", t1); t1 = insert(1, 1, t1); show("1", t1); t1 = insert(1024, 1024, t1); show("1,1024", t1); t1 = insert(2,2, t1); show("1,2,1024", t1); t1 = insert(1025,1025, t1); show("1,2,1024,1025", t1); t1 = insert(1023,1023, t1); show("1,2,1023,1024,1025", t1); printTree1(t1); } printf("\n"); #endif { Key i; IntMap m; for (i = 0, m = empty; i < MAX; ++i) { m = insert(i, i, m); } printTree1(m); show("filled tree", m); { int found = 1; Attr res; for (i = 0; i < MAX; ++i) { int b = isInMap(i, m, &res); b = b && res == i; if ( ! b ) { printf("isIn: %ld not found in tree\n", i); } found = found && b; } if ( ! found ) { printf("isIn: some elements not found\n"); } } for (i = 0; i < MAX; ++i) { m = remov(i, m); } show("empty tree", m); } return 0; }