From a0b0fb83f91bb82534a0d83fdd6c0222567b098d Mon Sep 17 00:00:00 2001 From: Erkki Seppälä Date: Mon, 20 Dec 2010 12:58:37 +0200 Subject: dix: add hashing functions to resource.h for others to use. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The public hashing function HashResourceID uses the same hashing hashing algorithm as resource.c uses internally, but it provides an interface that will is usable by external modules. It provides a parameter for the number of bits for the hash, instead of finding the size from its internal hash table. Signed-off-by: Erkki Seppälä --- dix/resource.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'dix/resource.c') diff --git a/dix/resource.c b/dix/resource.c index 5691b1608..9714061b8 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -636,27 +636,34 @@ InitClientResources(ClientPtr client) return TRUE; } -static int -Hash(int client, XID id) +int +HashResourceID(XID id, int numBits) { id &= RESOURCE_ID_MASK; - switch (clientTable[client].hashsize) { - case 6: - return ((int) (0x03F & (id ^ (id >> 6) ^ (id >> 12)))); - case 7: - return ((int) (0x07F & (id ^ (id >> 7) ^ (id >> 13)))); - case 8: - return ((int) (0x0FF & (id ^ (id >> 8) ^ (id >> 16)))); - case 9: - return ((int) (0x1FF & (id ^ (id >> 9)))); - case 10: - return ((int) (0x3FF & (id ^ (id >> 10)))); - case 11: - return ((int) (0x7FF & (id ^ (id >> 11)))); + switch (numBits) + { + case 6: + return ((int)(0x03F & (id ^ (id>>6) ^ (id>>12)))); + case 7: + return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13)))); + case 8: + return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16)))); + case 9: + return ((int)(0x1FF & (id ^ (id>>9)))); + case 10: + return ((int)(0x3FF & (id ^ (id>>10)))); + case 11: + return ((int)(0x7FF & (id ^ (id>>11)))); } return -1; } +static int +Hash(int client, XID id) +{ + return HashResourceID(id, clientTable[client].hashsize); +} + static XID AvailableID(int client, XID id, XID maxid, XID goodid) { -- cgit v1.2.3