According to hash.h, hash_ptr() looks like this:

static inline unsigned long hash_ptr(const void *ptr, unsigned int bits)

I'm just a little confused on what the parameters do. Obviously, the void *ptr points to the data to be hashed. My question is that how does the function know where the data ends? If it was assuming cstrings (ie. looking for the NULL byte), then why make it a void pointer?

This is where the next parameter comes in: does the int bits parameter tell you how long the data goes on for? I thought that the int bits parameter specifies the return value, for example, if my hash array has only 63 slots, then I may specify 5 as the number of bits. I'm just a little confused as to how this functions works and there aren't any man pages or anything...

Edit: OK since hash_ptr only hashes the pointer address, how would one go about hashing an array of bytes, or a c string within the kernel programming space?

有帮助吗?

解决方案

It doesn’t hash the value at the pointer; it hashes the pointer itself, in a platform- (size-) independant way.

Mine looks like this:

static inline unsigned long hash_ptr(const void *ptr, unsigned int bits)
{
    return hash_long((unsigned long)ptr, bits);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top