Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "curlcheck.h"
00023
00024 #include "splay.h"
00025
00026
00027 static CURLcode unit_setup(void)
00028 {
00029 return CURLE_OK;
00030 }
00031
00032 static void unit_stop(void)
00033 {
00034
00035 }
00036
00037 static void splayprint(struct Curl_tree * t, int d, char output)
00038 {
00039 struct Curl_tree *node;
00040 int i;
00041 int count;
00042 if(t == NULL)
00043 return;
00044
00045 splayprint(t->larger, d+1, output);
00046 for(i=0; i<d; i++)
00047 if(output)
00048 printf(" ");
00049
00050 if(output) {
00051 printf("%ld.%ld[%d]", (long)t->key.tv_sec,
00052 (long)t->key.tv_usec, i);
00053 }
00054
00055 for(count=0, node = t->same; node; node = node->same, count++)
00056 ;
00057
00058 if(output) {
00059 if(count)
00060 printf(" [%d more]\n", count);
00061 else
00062 printf("\n");
00063 }
00064
00065 splayprint(t->smaller, d+1, output);
00066 }
00067
00068 UNITTEST_START
00069
00070
00071 #define NUM_NODES 50
00072
00073 struct Curl_tree *root;
00074 struct Curl_tree nodes[NUM_NODES];
00075 int rc;
00076 int i;
00077 root = NULL;
00078
00079 for(i = 0; i < NUM_NODES; i++) {
00080 struct timeval key;
00081
00082 key.tv_sec = 0;
00083 key.tv_usec = (541*i)%1023;
00084
00085 nodes[i].payload = (void *)key.tv_usec;
00086 root = Curl_splayinsert(key, root, &nodes[i]);
00087 }
00088
00089 puts("Result:");
00090 splayprint(root, 0, 1);
00091
00092 for(i = 0; i < NUM_NODES; i++) {
00093 int rem = (i+7)%NUM_NODES;
00094 printf("Tree look:\n");
00095 splayprint(root, 0, 1);
00096 printf("remove pointer %d, payload %ld\n", rem,
00097 (long)(nodes[rem].payload));
00098 rc = Curl_splayremovebyaddr(root, &nodes[rem], &root);
00099 if(rc) {
00100
00101 printf("remove %d failed!\n", rem);
00102 fail("remove");
00103 }
00104 }
00105
00106 UNITTEST_STOP
00107
00108
00109
00110