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 | |
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>
-rw-r--r-- | dix/resource.c | 37 | ||||
-rw-r--r-- | include/resource.h | 13 |
2 files changed, 34 insertions, 16 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) { diff --git a/include/resource.h b/include/resource.h index 663fac4f6..e8f263705 100644 --- a/include/resource.h +++ b/include/resource.h @@ -272,4 +272,15 @@ extern _X_EXPORT unsigned int GetXIDList(ClientPtr /*client */ , extern _X_EXPORT RESTYPE lastResourceType; extern _X_EXPORT RESTYPE TypeMask; -#endif /* RESOURCE_H */ +/** @brief A hashing function to be used for hashing resource IDs + + @param id The resource ID to hash + @param numBits The number of bits in the resulting hash + + @note This function can only handle INITHASHSIZE..MAXHASHSIZE bit + hashes and will return -1 if numBits is not within those bounds. +*/ +extern _X_EXPORT int HashResourceID(XID id, + int numBits); + +#endif /* RESOURCE_H */ |