tests/hash: style fixes

v2: Rebase on earlier changes. Keep count initialisation as is.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jan Vesely <jan.vesely@rutgers.edu>
main
Emil Velikov 2015-03-26 23:09:31 +00:00
parent c53da3ac57
commit 4fcb6637f0
1 changed files with 54 additions and 36 deletions

View File

@ -80,21 +80,25 @@ static int dist[DIST_LIMIT];
static void clear_dist(void) {
int i;
for (i = 0; i < DIST_LIMIT; i++) dist[i] = 0;
for (i = 0; i < DIST_LIMIT; i++)
dist[i] = 0;
}
static int count_entries(HashBucketPtr bucket)
{
int count = 0;
for (; bucket; bucket = bucket->next) ++count;
for (; bucket; bucket = bucket->next)
++count;
return count;
}
static void update_dist(int count)
{
if (count >= DIST_LIMIT) ++dist[DIST_LIMIT-1];
else ++dist[count];
if (count >= DIST_LIMIT)
++dist[DIST_LIMIT-1];
else
++dist[count];
}
static void compute_dist(HashTablePtr table)
@ -110,8 +114,10 @@ static void compute_dist(HashTablePtr table)
update_dist(count_entries(bucket));
}
for (i = 0; i < DIST_LIMIT; i++) {
if (i != DIST_LIMIT-1) printf("%5d %10d\n", i, dist[i]);
else printf("other %10d\n", dist[i]);
if (i != DIST_LIMIT-1)
printf("%5d %10d\n", i, dist[i]);
else
printf("other %10d\n", dist[i]);
}
}
@ -150,44 +156,56 @@ int main(void)
printf("\n***** 256 consecutive integers ****\n");
table = drmHashCreate();
for (i = 0; i < 256; i++) drmHashInsert(table, i, (void *)(i << 16 | i));
for (i = 0; i < 256; i++) check_table(table, i, (void *)(i << 16 | i));
for (i = 0; i < 256; i++)
drmHashInsert(table, i, (void *)(i << 16 | i));
for (i = 0; i < 256; i++)
check_table(table, i, (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);
printf("\n***** 1024 consecutive integers ****\n");
table = drmHashCreate();
for (i = 0; i < 1024; i++) drmHashInsert(table, i, (void *)(i << 16 | i));
for (i = 0; i < 1024; i++) check_table(table, i, (void *)(i << 16 | i));
for (i = 0; i < 1024; i++)
drmHashInsert(table, i, (void *)(i << 16 | i));
for (i = 0; i < 1024; i++)
check_table(table, i, (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);
printf("\n***** 1024 consecutive page addresses (4k pages) ****\n");
table = drmHashCreate();
for (i = 0; i < 1024; i++) drmHashInsert(table, i*4096, (void *)(i << 16 | i));
for (i = 0; i < 1024; i++) check_table(table, i*4096, (void *)(i << 16 | i));
for (i = 0; i < 1024; i++)
drmHashInsert(table, i*4096, (void *)(i << 16 | i));
for (i = 0; i < 1024; i++)
check_table(table, i*4096, (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);
printf("\n***** 1024 random integers ****\n");
table = drmHashCreate();
srandom(0xbeefbeef);
for (i = 0; i < 1024; i++) drmHashInsert(table, random(), (void *)(i << 16 | i));
for (i = 0; i < 1024; i++)
drmHashInsert(table, random(), (void *)(i << 16 | i));
srandom(0xbeefbeef);
for (i = 0; i < 1024; i++) check_table(table, random(), (void *)(i << 16 | i));
for (i = 0; i < 1024; i++)
check_table(table, random(), (void *)(i << 16 | i));
srandom(0xbeefbeef);
for (i = 0; i < 1024; i++) check_table(table, random(), (void *)(i << 16 | i));
for (i = 0; i < 1024; i++)
check_table(table, random(), (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);
printf("\n***** 5000 random integers ****\n");
table = drmHashCreate();
srandom(0xbeefbeef);
for (i = 0; i < 5000; i++) drmHashInsert(table, random(), (void *)(i << 16 | i));
for (i = 0; i < 5000; i++)
drmHashInsert(table, random(), (void *)(i << 16 | i));
srandom(0xbeefbeef);
for (i = 0; i < 5000; i++) check_table(table, random(), (void *)(i << 16 | i));
for (i = 0; i < 5000; i++)
check_table(table, random(), (void *)(i << 16 | i));
srandom(0xbeefbeef);
for (i = 0; i < 5000; i++) check_table(table, random(), (void *)(i << 16 | i));
for (i = 0; i < 5000; i++)
check_table(table, random(), (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);