From: Jan Vesely Subject: Re: [PATCH libdrm 4/9] tests/hash: style fixes Date: Mon, 23 Mar 2015 18:46:33 -0400 Message-ID: <1427150793.3547.45.camel@rutgers.edu> References: <1427061825-27470-1-git-send-email-emil.l.velikov@gmail.com> <1427061825-27470-5-git-send-email-emil.l.velikov@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1140635061==" Return-path: Received: from mail-qg0-f50.google.com (mail-qg0-f50.google.com [209.85.192.50]) by gabe.freedesktop.org (Postfix) with ESMTP id 0A2156E612 for ; Mon, 23 Mar 2015 15:46:35 -0700 (PDT) Received: by qgez102 with SMTP id z102so80330522qge.3 for ; Mon, 23 Mar 2015 15:46:34 -0700 (PDT) In-Reply-To: <1427061825-27470-5-git-send-email-emil.l.velikov@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Emil Velikov Cc: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============1140635061== Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-T9sIFKyUmI0ntazLv7Uy" --=-T9sIFKyUmI0ntazLv7Uy Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, 2015-03-22 at 22:03 +0000, Emil Velikov wrote: > Signed-off-by: Emil Velikov > --- > tests/hash.c | 102 +++++++++++++++++++++++++++++++++++------------------= ------ > 1 file changed, 60 insertions(+), 42 deletions(-) >=20 > diff --git a/tests/hash.c b/tests/hash.c > index 902919f..fa9264a 100644 > --- a/tests/hash.c > +++ b/tests/hash.c > @@ -73,8 +73,8 @@ > =20 > #include "xf86drm.h" > =20 > -#define HASH_SIZE 512 /* Good for about 100 entries */ > - /* If you change this value, you probably > +#define HASH_SIZE 512 /* Good for about 100 entries */ > + /* If you change this value, you probabl= y > have to change the HashHash hashing > function! */ > =20 > @@ -87,9 +87,9 @@ typedef struct HashBucket { > typedef struct HashTable { > unsigned long magic; > unsigned long entries; > - unsigned long hits; /* At top of linked list */ > - unsigned long partials; /* Not at top of linked list */ > - unsigned long misses; /* Not in table */ > + unsigned long hits; /* At top of linked list */ > + unsigned long partials; /* Not at top of linked list */ > + unsigned long misses; /* Not in table */ > HashBucketPtr buckets[HASH_SIZE]; > int p0; > HashBucketPtr p1; > @@ -101,21 +101,25 @@ static int dist[DIST_LIMIT]; > static void clear_dist(void) { > int i; > =20 > - for (i =3D 0; i < DIST_LIMIT; i++) dist[i] =3D 0; > + for (i =3D 0; i < DIST_LIMIT; i++) > + dist[i] =3D 0; > } > =20 > static int count_entries(HashBucketPtr bucket) > { > - int count =3D 0; > + int count; > =20 > - for (; bucket; bucket =3D bucket->next) ++count; > + for (count =3D 0; bucket; bucket =3D bucket->next) > + ++count; I personally prefer to initialize early, especially since it's not for-loop iterating variable, but I don't insist. Reviewed-by: Jan Vesely > return count; > } > =20 > static void update_dist(int count) > { > - if (count >=3D DIST_LIMIT) ++dist[DIST_LIMIT-1]; > - else ++dist[count]; > + if (count >=3D DIST_LIMIT) > + ++dist[DIST_LIMIT-1]; > + else > + ++dist[count]; > } > =20 > static void compute_dist(HashTablePtr table) > @@ -124,43 +128,45 @@ static void compute_dist(HashTablePtr table) > HashBucketPtr bucket; > =20 > printf("Entries =3D %ld, hits =3D %ld, partials =3D %ld, misses =3D = %ld\n", > - table->entries, table->hits, table->partials, table->misses); > + table->entries, table->hits, table->partials, table->misses); > clear_dist(); > for (i =3D 0; i < HASH_SIZE; i++) { > - bucket =3D table->buckets[i]; > - update_dist(count_entries(bucket)); > + bucket =3D table->buckets[i]; > + update_dist(count_entries(bucket)); > } > for (i =3D 0; i < DIST_LIMIT; i++) { > - if (i !=3D DIST_LIMIT-1) printf("%5d %10d\n", i, dist[i]); > - else printf("other %10d\n", dist[i]); > + if (i !=3D DIST_LIMIT-1) > + printf("%5d %10d\n", i, dist[i]); > + else > + printf("other %10d\n", dist[i]); > } > } > =20 > static void check_table(HashTablePtr table, > - unsigned long key, unsigned long value) > + unsigned long key, unsigned long value) > { > unsigned long *retval; > int retcode =3D drmHashLookup(table, key, (void **)&retval= ); > =20 > switch (retcode) { > case -1: > - printf("Bad magic =3D 0x%08lx:" > - " key =3D %lu, expected =3D %lu, returned =3D %lu\n", > - table->magic, key, value, *retval); > - break; > + printf("Bad magic =3D 0x%08lx:" > + " key =3D %lu, expected =3D %lu, returned =3D %lu\n", > + table->magic, key, value, *retval); > + break; > case 1: > - printf("Not found: key =3D %lu, expected =3D %lu, returned =3D %lu\n", > - key, value, *retval); > - break; > + printf("Not found: key =3D %lu, expected =3D %lu, returned =3D %= lu\n", > + key, value, *retval); > + break; > case 0: > - if (value !=3D *retval) > - printf("Bad value: key =3D %lu, expected =3D %lu, returned =3D %lu\= n", > - key, value, *retval); > - break; > + if (value !=3D *retval) > + printf("Bad value: key =3D %lu, expected =3D %lu, returned = =3D %lu\n", > + key, value, *retval); > + break; > default: > - printf("Bad retcode =3D %d: key =3D %lu, expected =3D %lu, returned =3D= %lu\n", > - retcode, key, value, *retval); > - break; > + printf("Bad retcode =3D %d: key =3D %lu, expected =3D %lu, retur= ned =3D %lu\n", > + retcode, key, value, *retval); > + break; > } > } > =20 > @@ -171,44 +177,56 @@ int main(void) > =20 > printf("\n***** 256 consecutive integers ****\n"); > table =3D drmHashCreate(); > - for (i =3D 0; i < 256; i++) drmHashInsert(table, i, (void *)&i); > - for (i =3D 0; i < 256; i++) check_table(table, i, i); > + for (i =3D 0; i < 256; i++) > + drmHashInsert(table, i, (void *)&i); > + for (i =3D 0; i < 256; i++) > + check_table(table, i, i); > compute_dist(table); > drmHashDestroy(table); > =20 > printf("\n***** 1024 consecutive integers ****\n"); > table =3D drmHashCreate(); > - for (i =3D 0; i < 1024; i++) drmHashInsert(table, i, (void *)&i); > - for (i =3D 0; i < 1024; i++) check_table(table, i, i); > + for (i =3D 0; i < 1024; i++) > + drmHashInsert(table, i, (void *)&i); > + for (i =3D 0; i < 1024; i++) > + check_table(table, i, i); > compute_dist(table); > drmHashDestroy(table); > =20 > printf("\n***** 1024 consecutive page addresses (4k pages) ****\n"); > table =3D drmHashCreate(); > - for (i =3D 0; i < 1024; i++) drmHashInsert(table, i*4096, (void *)&i= ); > - for (i =3D 0; i < 1024; i++) check_table(table, i*4096, i); > + for (i =3D 0; i < 1024; i++) > + drmHashInsert(table, i*4096, (void *)&i); > + for (i =3D 0; i < 1024; i++) > + check_table(table, i*4096, i); > compute_dist(table); > drmHashDestroy(table); > =20 > printf("\n***** 1024 random integers ****\n"); > table =3D drmHashCreate(); > srandom(0xbeefbeef); > - for (i =3D 0; i < 1024; i++) drmHashInsert(table, random(), (void *)= &i); > + for (i =3D 0; i < 1024; i++) > + drmHashInsert(table, random(), (void *)&i); > srandom(0xbeefbeef); > - for (i =3D 0; i < 1024; i++) check_table(table, random(), i); > + for (i =3D 0; i < 1024; i++) > + check_table(table, random(), i); > srandom(0xbeefbeef); > - for (i =3D 0; i < 1024; i++) check_table(table, random(), i); > + for (i =3D 0; i < 1024; i++) > + check_table(table, random(), i); > compute_dist(table); > drmHashDestroy(table); > =20 > printf("\n***** 5000 random integers ****\n"); > table =3D drmHashCreate(); > srandom(0xbeefbeef); > - for (i =3D 0; i < 5000; i++) drmHashInsert(table, random(), (void *)= &i); > + for (i =3D 0; i < 5000; i++) > + drmHashInsert(table, random(), (void *)&i); > srandom(0xbeefbeef); > - for (i =3D 0; i < 5000; i++) check_table(table, random(), i); > + for (i =3D 0; i < 5000; i++) > + check_table(table, random(), i); > srandom(0xbeefbeef); > - for (i =3D 0; i < 5000; i++) check_table(table, random(), i); > + for (i =3D 0; i < 5000; i++) > + check_table(table, random(), i); > compute_dist(table); > drmHashDestroy(table); > =20 --=20 Jan Vesely --=-T9sIFKyUmI0ntazLv7Uy Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAABCgAGBQJVEJfJAAoJEDhUsXb6ZiH/X0sP/jKmdHyjhc649w77R9omtMVk tLepazA5pYxlB/OTVXbbIFBfQO19Z3JfAGolSxkTSakJRbdTuFRv9GV80EUUL5GV XrKouwOqyhG7Im2WJSVM6PCLYeUvO1Sb8D/u63ghFHPPwL+j8rgvMEtBpYB/WZg5 EucYqArshJ9yl3Fy2Ms8AJEvFQUcXK9oe5fPuo0J3S9SVdBXUxoON1v3OjKk5B0i XZSQWEk0ELa4UWVTvaeatlGbszpvX/WL3mcmjxTMDBCe9w4PtNAvWHOPkWGZNHx9 PoynRLvQV4y8RE6EMVoiNQL9RA2lKE7GImY+E308l0jjy4WLGYyK5ND4N6yGGIlq 9b4I3BbRFwbuVaCCLRG+Aio8qnUuOoSzD2AOjxR5PBv9WdqXuQr0foDkIOcxAz7M UzrajkMB8Aa9n7Y9VqyH/OMtRcIXPod0KIb5DRxFv6v34AJSOYvEuCNo77gtIZu4 ZvbjH03F8nBSWoRFxFoAndXZMomCEgHHm1puuk/kG84kx7Ca1X1800bLugb1vUIJ 0CRbRhn8zD+H+lkZM9hUNuDEUm+FQpYxZA3CAtbmXXj3kItTG4yBy9i5yQf7LruG KDwwmKZF5xQzwo3q/QFZLs22Y/AN64kSgc19CBbK69qSl+aG+Cj9+oqLZLS3PIzs DjtKfezM3HpnLJn4gvKG =c852 -----END PGP SIGNATURE----- --=-T9sIFKyUmI0ntazLv7Uy-- --===============1140635061== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHA6Ly9saXN0 cy5mcmVlZGVza3RvcC5vcmcvbWFpbG1hbi9saXN0aW5mby9kcmktZGV2ZWwK --===============1140635061==--