/* Returns free_buckets + 1, or list number to search. */
static tdb_off_t find_free_head(struct tdb_context *tdb, tdb_off_t bucket)
{
- tdb_off_t b;
-
/* Speculatively search for a non-zero bucket. */
- b = tdb_find_nonzero_off(tdb, bucket_off(tdb->zone_off, bucket),
- BUCKETS_FOR_ZONE(tdb->zhdr.zone_bits) + 1
- - bucket);
- return bucket + b;
+ return tdb_find_nonzero_off(tdb, bucket_off(tdb->zone_off, 0),
+ bucket,
+ BUCKETS_FOR_ZONE(tdb->zhdr.zone_bits) + 1);
}
/* Remove from free bucket. */
{
uint64_t keybits = (fls64(keylen) + 1) / 2;
- /* Use top bits of hash, so it's independent of hash table size. */
+ /* Use bottom bits of hash, so it's independent of hash table size. */
rec->magic_and_meta
= zone_bits
- | ((hash >> 59) << 6)
+ | ((hash & ((1 << 5)-1)) << 6)
| ((actuallen - (keylen + datalen)) << 11)
| (keybits << 43)
| (TDB_MAGIC << 48);
tdb_len_t size, actual;
struct tdb_used_record rec;
- /* We don't want header to change during this! */
- assert(tdb->header_uptodate);
+ /* We can't hold pointers during this: we could unmap! */
+ assert(!tdb->direct_access);
size = adjust_size(keylen, datalen, growing);