diff --git a/dix/resource.c b/dix/resource.c index 5691b1608..9714061b8 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -636,25 +636,32 @@ InitClientResources(ClientPtr client) return TRUE; } +int +HashResourceID(XID id, int numBits) +{ + id &= RESOURCE_ID_MASK; + 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) { - 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)))); - } - return -1; + return HashResourceID(id, clientTable[client].hashsize); } static XID 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 */