summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2015-03-26 23:09:31 +0000
committerEmil Velikov <emil.l.velikov@gmail.com>2015-04-05 15:19:50 +0100
commit4fcb6637f0508a0ed0be190d2f5518a2fa9cd041 (patch)
tree313e052feb9bf87e28aaa74ac0d455bb4a4f04c3
parentc53da3ac57aa646936492199f4fabc9f373f57bc (diff)
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>
-rw-r--r--tests/hash.c90
1 files changed, 54 insertions, 36 deletions
diff --git a/tests/hash.c b/tests/hash.c
index ee11e23b..1543c86a 100644
--- a/tests/hash.c
+++ b/tests/hash.c
@@ -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)
@@ -103,43 +107,45 @@ static void compute_dist(HashTablePtr table)
HashBucketPtr bucket;
printf("Entries = %ld, hits = %ld, partials = %ld, misses = %ld\n",
- table->entries, table->hits, table->partials, table->misses);
+ table->entries, table->hits, table->partials, table->misses);
clear_dist();
for (i = 0; i < HASH_SIZE; i++) {
- bucket = table->buckets[i];
- update_dist(count_entries(bucket));
+ bucket = table->buckets[i];
+ 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]);
}
}
static void check_table(HashTablePtr table,
- unsigned long key, void * value)
+ unsigned long key, void * value)
{
void *retval;
int retcode = drmHashLookup(table, key, &retval);
switch (retcode) {
case -1:
- printf("Bad magic = 0x%08lx:"
- " key = %lu, expected = %p, returned = %p\n",
- table->magic, key, value, retval);
- break;
+ printf("Bad magic = 0x%08lx:"
+ " key = %lu, expected = %p, returned = %p\n",
+ table->magic, key, value, retval);
+ break;
case 1:
- printf("Not found: key = %lu, expected = %p, returned = %p\n",
- key, value, retval);
- break;
+ printf("Not found: key = %lu, expected = %p, returned = %p\n",
+ key, value, retval);
+ break;
case 0:
- if (value != retval)
- printf("Bad value: key = %lu, expected = %p, returned = %p\n",
- key, value, retval);
- break;
+ if (value != retval)
+ printf("Bad value: key = %lu, expected = %p, returned = %p\n",
+ key, value, retval);
+ break;
default:
- printf("Bad retcode = %d: key = %lu, expected = %p, returned = %p\n",
- retcode, key, value, retval);
- break;
+ printf("Bad retcode = %d: key = %lu, expected = %p, returned = %p\n",
+ retcode, key, value, retval);
+ break;
}
}
@@ -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);