Skip to content

Instantly share code, notes, and snippets.

@delamonpansie
Created August 29, 2011 07:41
Show Gist options
  • Save delamonpansie/1177952 to your computer and use it in GitHub Desktop.
Save delamonpansie/1177952 to your computer and use it in GitHub Desktop.
put
static uint32_t
_mh(put_slot)(struct _mh(t) *h, mh_key_t key)
{
uint32_t inc, k, i, p = h->n_buckets;
k = mh_hash(key);
i = k % h->n_buckets;
inc = 1 + k % (h->n_buckets - 1);
for (;;) {
if (mh_exist(h, i)) {
if (mh_eq(h->p[i].key, key))
return i;
if (p == h->n_buckets)
mh_setdirty(h, i);
} else {
if (p == h->n_buckets)
p = i;
if (!mh_dirty(h, i))
return p;
}
i += inc;
if (i >= h->n_buckets)
i -= h->n_buckets;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment