Re: [PATCH v4] hashtable: introduce a small and naive hashtable

From: Sasha Levin
Date: Mon Sep 10 2012 - 08:18:21 EST


On 09/10/2012 04:48 AM, Mathieu Desnoyers wrote:
> * Sasha Levin (levinsasha928@xxxxxxxxx) wrote:
>> +#define hash_init(hashtable) \
>> +({ \
>> + int __i; \
>> + \
>> + for (__i = 0; __i < HASH_BITS(hashtable); __i++) \
>> + INIT_HLIST_HEAD(hashtable + __i); \
>
> I suspect that hashtable will be a pointer, and you use the "+" operator
> to do an offset on this pointer. Any thought on using:
>
> INIT_HLIST_HEAD(&hashtable[__i]);
>
> instead ? It would provide the same result, but would ensure that the
> user is indeed passing a pointer, and not an integer.

It also looks nicer :)

> Also, why isn't it a static inline ? I'm probably missing something. If
> there is a reason why it needs to stay a #define, please document it in
> the comment.

It's a define because it needs to get the size of the hashtable.

I'll document that.


Thanks,
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/