Messages in this thread | | | Date | Wed, 01 Aug 2012 20:19:52 +0200 | From | Sasha Levin <> | Subject | Re: [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).
| |