Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "GainBucket.h"
int main(int argc, char **argv) {
void CheckBuckets(struct gainbucket GB, long n, long bs);
long n, bs, i, j, offset;
struct gainbucket GB ;
printf("Test BucketInsert: ");
n= 100 ; /* number of buckets */
bs = 5; /* bucket size */
offset = n/2 ;
/* Insert vertices in increasing order of gain value */
GB.NrBuckets =0 ;
GB.Root = NULL ;
for (j=0; j<bs; j++)
for (i=0; i<n; i++)
BucketInsert(&GB, i-offset, j*n + i) ;
CheckBuckets(GB, n, bs) ;
printf("OK\n") ;
exit(0);
} /* end main */
void CheckBuckets(struct gainbucket GB, long n, long bs) {
long nrentries = 0, i, j, offset ;
struct bucket *pB ;
struct bucketentry *pE ;
/* printf("Number of Buckets: %ld \n", GB.NrBuckets) ; */
if (GB.NrBuckets != n){
printf("Error\n") ;
exit(1);
}
pB = GB.Root ;
offset = n/2 ;
i = 0;
while ( pB != NULL ) {
j = 0;
pE = pB->entry ;
while ( pE != NULL ) {
/* printf("B[% ld] vntnr: %ld \n", (pE->bucket)->value,
pE->vtxnr) ; */
if ( (pE->bucket)->value != n-1-i - offset ||
pE->vtxnr != n-1-i + (bs-1-j) *n ) {
printf("Error\n") ;
exit(1);
}
nrentries++ ;
j++ ;
pE = pE->next ;
}
pB = pB->next ;
if (j!= bs){
printf("Error\n") ;
exit(1);
}
i++ ;
}
/* printf("TotalNrEntries: %ld\n", nrentries) ; */
if (nrentries != n*bs){
printf("Error\n") ;
exit(1);
}
} /* end CheckBuckets */