From patchwork Sun Mar 22 22:03:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 6067811 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E647F9F6E8 for ; Sun, 22 Mar 2015 22:00:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD9BE2024D for ; Sun, 22 Mar 2015 22:00:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D1FF920220 for ; Sun, 22 Mar 2015 22:00:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ACEDD6E3C7; Sun, 22 Mar 2015 15:00:47 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D73A6E3C7 for ; Sun, 22 Mar 2015 15:00:45 -0700 (PDT) Received: by wibg7 with SMTP id g7so24347961wib.1 for ; Sun, 22 Mar 2015 15:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6wuGW7AE8yIZ/v5GNorS6qWvspVB1/EhVneS/FJstz8=; b=ioJGWDSew3ovtwd8OdEYN8ILaV5OIlATEDCP9C5Sh9/nJgVWSpmh7nKvVeqtc0s2cT ccD+bCFKdIpJvUjx9w+tflDS2K3hnGtM67wX0m4pFw4MJ69zmqy2FoKzftKiY9O0ya5a EANA0mkl6llBw2htQ18FZdj+H+MZZKcfXeucF2Ux0TPPJRwYarGpK6ahJtK2qVfeqlaM 4Xn8PuQ61EdbXzzvioFknrUfqDVvJf7sC6xYiz4waw0lNec4fo6v6EZzQ0Df7uTDsI/G kLGSECZAFIDVRvljXbQUfRp2UfDUhfwOnGoeemr+x2bMF1MnxC7OXrVKuIt9q3A+ag0T QGMA== X-Received: by 10.194.59.199 with SMTP id b7mr181461631wjr.26.1427061644280; Sun, 22 Mar 2015 15:00:44 -0700 (PDT) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by mx.google.com with ESMTPSA id dq8sm8281654wib.9.2015.03.22.15.00.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Mar 2015 15:00:43 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 4/9] tests/hash: style fixes Date: Sun, 22 Mar 2015 22:03:40 +0000 Message-Id: <1427061825-27470-5-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.3.1 In-Reply-To: <1427061825-27470-1-git-send-email-emil.l.velikov@gmail.com> References: <1427061825-27470-1-git-send-email-emil.l.velikov@gmail.com> Cc: emil.l.velikov@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Emil Velikov Reviewed-by: Jan Vesely --- tests/hash.c | 102 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 42 deletions(-) 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 @@ #include "xf86drm.h" -#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 probably have to change the HashHash hashing function! */ @@ -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; - 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; + int count; - for (; bucket; bucket = bucket->next) ++count; + for (count = 0; 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) @@ -124,43 +128,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, unsigned long value) + unsigned long key, unsigned long value) { unsigned long *retval; int retcode = drmHashLookup(table, key, (void **)&retval); switch (retcode) { case -1: - printf("Bad magic = 0x%08lx:" - " key = %lu, expected = %lu, returned = %lu\n", - table->magic, key, value, *retval); - break; + printf("Bad magic = 0x%08lx:" + " key = %lu, expected = %lu, returned = %lu\n", + table->magic, key, value, *retval); + break; case 1: - printf("Not found: key = %lu, expected = %lu, returned = %lu\n", - key, value, *retval); - break; + printf("Not found: key = %lu, expected = %lu, returned = %lu\n", + key, value, *retval); + break; case 0: - if (value != *retval) - printf("Bad value: key = %lu, expected = %lu, returned = %lu\n", - key, value, *retval); - break; + if (value != *retval) + printf("Bad value: key = %lu, expected = %lu, returned = %lu\n", + key, value, *retval); + break; default: - printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n", - retcode, key, value, *retval); - break; + printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n", + retcode, key, value, *retval); + break; } } @@ -171,44 +177,56 @@ int main(void) printf("\n***** 256 consecutive integers ****\n"); table = drmHashCreate(); - for (i = 0; i < 256; i++) drmHashInsert(table, i, (void *)&i); - for (i = 0; i < 256; i++) check_table(table, i, i); + for (i = 0; i < 256; i++) + drmHashInsert(table, i, (void *)&i); + for (i = 0; i < 256; i++) + check_table(table, i, 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); - for (i = 0; i < 1024; i++) check_table(table, i, i); + for (i = 0; i < 1024; i++) + drmHashInsert(table, i, (void *)&i); + for (i = 0; i < 1024; i++) + check_table(table, i, 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); - for (i = 0; i < 1024; i++) check_table(table, i*4096, i); + for (i = 0; i < 1024; i++) + drmHashInsert(table, i*4096, (void *)&i); + for (i = 0; i < 1024; i++) + check_table(table, i*4096, 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); + for (i = 0; i < 1024; i++) + drmHashInsert(table, random(), (void *)&i); srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) check_table(table, random(), i); + for (i = 0; i < 1024; i++) + check_table(table, random(), i); srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) check_table(table, random(), i); + for (i = 0; i < 1024; i++) + check_table(table, random(), 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); + for (i = 0; i < 5000; i++) + drmHashInsert(table, random(), (void *)&i); srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) check_table(table, random(), i); + for (i = 0; i < 5000; i++) + check_table(table, random(), i); srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) check_table(table, random(), i); + for (i = 0; i < 5000; i++) + check_table(table, random(), i); compute_dist(table); drmHashDestroy(table);