On 07/31/2012 08:23 PM, Tejun Heo wrote:
> Hello, Sasha.
> 
> On Tue, Jul 31, 2012 at 08:05:17PM +0200, Sasha Levin wrote:
>> +#define HASH_INIT(name)                                                     
>> \
>> +({                                                                  \
>> +    int __i;                                                        \
>> +    for (__i = 0 ; __i < HASH_SIZE(name) ; __i++)                   \
>> +            INIT_HLIST_HEAD(&name[__i]);                            \
>> +})
> 
> Why use macro?
> 
>> +#define HASH_ADD(name, obj, key)                                    \
>> +    hlist_add_head(obj, &name[                                      \
>> +            hash_long((unsigned long)key, HASH_BITS(name))]);
> 
> Ditto.

Oh, yes, I've started working on this and remembered why it's macro in the 
first place.

Notice that we don't store hashtable size anywhere, this is because we can get 
it directly from the size of the hashtable array itself.

If we switch to using functions, we could no longer hide it anywhere (we'd need 
to either turn the buckets into a struct, or have the user pass it around to 
all functions).
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to