lkml.org 
[lkml]   [2012]   [Aug]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC 1/4] hashtable: introduce a small and naive hashtable
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).


\
 
 \ /
  Last update: 2012-08-01 21:01    [W:0.152 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site