]> git.ipfire.org Git - thirdparty/squid.git/blob - test-suite/splay.cc
Summary: Merge from delay-class-4
[thirdparty/squid.git] / test-suite / splay.cc
1 /*
2 * $Id: splay.cc,v 1.1 2003/02/05 10:37:14 robertc Exp $
3 *
4 * based on ftp://ftp.cs.cmu.edu/user/sleator/splaying/top-down-splay.c
5 * http://bobo.link.cs.cmu.edu/cgi-bin/splay/splay-cgi.pl
6 */
7
8 #include "config.h"
9
10 #if HAVE_STDIO_H
11 #include <stdio.h>
12 #endif
13 #if HAVE_STDLIB_H
14 #include <stdlib.h>
15 #endif
16 #if HAVE_UNISTD_H
17 #include <unistd.h>
18 #endif
19
20 #include "splay.h"
21 #include "util.h"
22
23 typedef struct {
24 int i;
25 } intnode;
26
27 int
28 compareint(void const *a, void const *n)
29 {
30 intnode *A = (intnode *)a;
31 intnode *B = (intnode *)n;
32 //((splayNode *)n)->data;
33 return A->i - B->i;
34 }
35
36 void
37 printint(void *a, void *state)
38 {
39 intnode *A = (intnode *)a;
40 printf("%d\n", A->i);
41 }
42
43 int
44 main(int argc, char *argv[])
45 {
46 int i;
47 intnode *I;
48 splayNode *top = NULL;
49 srandom(time(NULL));
50 for (i = 0; i < 100; i++) {
51 I = (intnode *)xcalloc(sizeof(intnode), 1);
52 I->i = random();
53 top = splay_insert(I, top, compareint);
54 }
55 splay_walk(top, printint, NULL);
56 return 0;
57 }