lkml.org 
[lkml]   [2012]   [Sep]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v6] hashtable: introduce a small and naive hashtable
* David Laight (David.Laight@ACULAB.COM) wrote:
> Amazing how something simple gets lots of comments and versions :-)
>
> > ...
> > + * This has to be a macro since HASH_BITS() will not work on pointers since
> > + * it calculates the size during preprocessing.
> > + */
> > +#define hash_empty(hashtable) \
> > +({ \
> > + int __i; \
> > + bool __ret = true; \
> > + \
> > + for (__i = 0; __i < HASH_SIZE(hashtable); __i++) \
> > + if (!hlist_empty(&hashtable[__i])) \
> > + __ret = false; \
> > + \
> > + __ret; \
> > +})
>
> Actually you could have a #define that calls a function
> passing in the address and size.
> Also, should the loop have a 'break' in it?

+1 Removing unnecessary variables defined within a
statement-expression is indeed something we want, and your suggestion of
a macro calling a static inline is, IMHO, spot-on.

The same should be done for hash_init().

And yes, a break would be welcome in that loop: no need to continue if
we encounter a non-empty hlist.

Thanks,

Mathieu

--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com


\
 
 \ /
  Last update: 2012-09-26 17:01    [W:0.482 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site