lib/hmap.c
/* Returns the next node in 'hmap' in hash order, or NULL if no nodes remain in
 * 'hmap'.  Uses '*pos' to determine where to begin iteration, and updates
 * '*pos' to pass on the next iteration into them before returning.
 *
 * It's better to use plain HMAP_FOR_EACH and related functions, since they are
 * faster and better at dealing with hmaps that change during iteration.
 *
 * Before beginning iteration, set '*pos' to all zeros. */
Returns the next node in 'hmap' in hash order, or NULL if no nodes remain in
'hmap'.  Uses '*pos' to determine where to begin iteration, and updates
'*pos' to pass on the next iteration into them before returning.

It's better to use plain HMAP_FOR_EACH and related functions, since they are
faster and better at dealing with hmaps that change during iteration.

Before beginning iteration, set '*pos' to all zeros.
Returns the next node in ' hmap ' in hash order or NULL if no nodes remain in ' hmap ' . Uses ' * pos ' to determine where to begin iteration and updates ' * pos ' to pass on the next iteration into them before returning . It ' s better to use plain HMAP_FOR_EACH and related functions since they are faster and better at dealing with hmaps that change during iteration . Before beginning iteration set ' * pos ' to all zeros .
struct hmap_node *
hmap_at_position(const struct hmap *hmap,
                 struct hmap_position *pos)
{
    size_t offset;
    size_t b_idx;
    offset = pos->offset;
    for (b_idx = pos->bucket; b_idx <= hmap->mask; b_idx++) {
        struct hmap_node *node;
        size_t n_idx;
        for (n_idx = 0, node = hmap->buckets[b_idx]; node != NULL;
             n_idx++, node = node->next) {
            if (n_idx == offset) {
                if (node->next) {
                    pos->bucket = node->hash & hmap->mask;
                    pos->offset = offset + 1;
                } else {
                    pos->bucket = (node->hash & hmap->mask) + 1;
                    pos->offset = 0;
                }
                return node;
            }
        }
        offset = 0;
    }
    pos->bucket = 0;
    pos->offset = 0;
    return NULL;
}
struct hmap_node * hmap_at_position ( const struct hmap * hmap , struct hmap_position * pos ) { size_t offset ; size_t b_idx ; offset = pos -> offset ; for ( b_idx = pos -> bucket ; b_idx <= hmap -> mask ; b_idx ++ ) { struct hmap_node * node ; size_t n_idx ; for ( n_idx = 0 , node = hmap -> buckets [ b_idx ] ; node != NULL ; n_idx ++ , node = node -> next ) { if ( n_idx == offset ) { if ( node -> next ) { pos -> bucket = node -> hash & hmap -> mask ; pos -> offset = offset + 1 ; } else { pos -> bucket = ( node -> hash & hmap -> mask ) + 1 ; pos -> offset = 0 ; } return node ; } } offset = 0 ; } pos -> bucket = 0 ; pos -> offset = 0 ; return NULL ; }
Returns the next node in 'hmap' in hash order, or NULL if no nodes remain in
 'hmap'.
Returns the next node in ' hmap ' in hash order or NULL if no nodes remain in ' hmap ' .