X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fhashtable.h;h=c2c3c42d0869d73052cdc299b7867f5dfb6bbf9e;hb=2a64fd8ad0419220eccfcde539ed1791138ef942;hp=17b6d08e1799d43a7ced814da9653e9b37215e2d;hpb=4a220521e7b46263b156a6c784856a996997df76;p=libucw.git diff --git a/lib/hashtable.h b/lib/hashtable.h index 17b6d08e..c2c3c42d 100644 --- a/lib/hashtable.h +++ b/lib/hashtable.h @@ -2,6 +2,10 @@ * Sherlock Library -- Universal Hash Table * * (c) 2002 Martin Mares + * (c) 2002 Robert Spalek + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ /* @@ -41,8 +45,10 @@ * * init() -- initialize the hash table. * HASH_WANT_CLEANUP cleanup() -- deallocate the hash table. - * HASH_WANT_FIND node *find(key) -- find node with the specified + * HASH_WANT_FIND node *find(key) -- find first node with the specified * key, return NULL if no such node exists. + * HASH_WANT_FIND_NEXT node *find(node *start) -- find next node with the + * specified key, return NULL if no such node exists. * HASH_WANT_NEW node *new(key) -- create new node with given key. * Doesn't check whether it already exists. * HASH_WANT_LOOKUP node *lookup(key) -- find node with given key, @@ -381,6 +387,27 @@ static P(node) * P(find) (HASH_KEY_DECL) } #endif +#ifdef HASH_WANT_FIND_NEXT +static P(node) * P(find_next) (P(node) *start) +{ +#ifndef HASH_CONSERVE_SPACE + uns h0 = P(hash) (HASH_KEY(start->)); +#endif + P(bucket) *b = SKIP_BACK(P(bucket), n, start); + + for (b=b->next; b; b=b->next) + { + if ( +#ifndef HASH_CONSERVE_SPACE + b->hash == h0 && +#endif + P(eq)(HASH_KEY(start->), HASH_KEY(b->n.))) + return &b->n; + } + return NULL; +} +#endif + #ifdef HASH_WANT_NEW static P(node) * P(new) (HASH_KEY_DECL) { @@ -526,6 +553,7 @@ do { \ #undef HASH_WANT_CLEANUP #undef HASH_WANT_DELETE #undef HASH_WANT_FIND +#undef HASH_WANT_FIND_NEXT #undef HASH_WANT_LOOKUP #undef HASH_WANT_NEW #undef HASH_WANT_REMOVE