diff options
author | Erkki Seppälä <erkki.seppala@vincit.fi> | 2010-12-20 12:58:37 +0200 |
---|---|---|
committer | Erkki Seppälä <erkki.seppala@vincit.fi> | 2012-04-18 12:43:54 +0300 |
commit | a0b0fb83f91bb82534a0d83fdd6c0222567b098d (patch) | |
tree | a6deb4d671760eace8d58660a88f0122398121e3 /dix/resource.c | |
parent | 3ba0decb4b55a1fd122d269e15b2b2da8ced8624 (diff) |
dix: add hashing functions to resource.h for others to use.
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ä <erkki.seppala@vincit.fi>
Diffstat (limited to 'dix/resource.c')
-rw-r--r-- | dix/resource.c | 37 |
1 files changed, 22 insertions, 15 deletions
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) { |