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>
This commit is contained in:
Erkki Seppälä 2010-12-20 12:58:37 +02:00
parent 3ba0decb4b
commit a0b0fb83f9
2 changed files with 35 additions and 17 deletions

View File

@ -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

View File

@ -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 */