unit1309.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
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 /* number of nodes to add to the splay tree */
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;              /* the empty tree */
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; /* for simplicity */
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       /* failed! */
00101       printf("remove %d failed!\n", rem);
00102       fail("remove");
00103     }
00104   }
00105 
00106 UNITTEST_STOP
00107 
00108 
00109 
00110 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07