From a59ea96ac0938d88051ac578eaabaa3900690dcc Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 13 Jul 2000 21:35:14 +0000 Subject: [PATCH] Recalculate directory position when cascading splits. --- lib/db.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/db.c b/lib/db.c index 8ccd3533..03c28e1d 100644 --- a/lib/db.c +++ b/lib/db.c @@ -364,12 +364,22 @@ sdbm_split_dir(struct sdbm *d, uns dirpos, uns count, uns pos) } } +static inline uns +sdbm_dirpos(struct sdbm *d, uns hash) +{ + if (d->dir_shift != 32) /* avoid shifting by 32 bits */ + return (hash >> d->dir_shift) << 2; /* offset in the directory */ + else + return 0; +} + static struct page * -sdbm_split_page(struct sdbm *d, struct page *b, u32 hash, uns dirpos) +sdbm_split_page(struct sdbm *d, struct page *b, u32 hash) { struct page *p[2]; - uns i, rank, sigbit, rank_log; + uns i, rank, sigbit, rank_log, dirpos; + dirpos = sdbm_dirpos(d, hash); rank = sdbm_page_rank(d, dirpos); /* rank = # of pointers to this page */ if (rank == 1) { @@ -421,10 +431,7 @@ sdbm_access(struct sdbm *d, byte *key, uns keylen, byte *val, uns *vallen, uns m if (!mode && !(d->flags & SDBM_WRITE)) return SDBM_ERROR_READ_ONLY; hash = sdbm_hash(key, keylen); - if (d->dir_shift != 32) /* avoid shifting by 32 bits */ - h = (hash >> d->dir_shift) << 2; /* offset in the directory */ - else - h = 0; + h = sdbm_dirpos(d, hash); p = pgc_read(d->cache, d->fd, d->root->dir_start + (h & ~d->page_mask)); pos = GET32(p->data, h & d->page_mask); pgc_put(d->cache, p); @@ -475,7 +482,7 @@ insert: pgc_put(d->cache, q); return SDBM_ERROR_GIANT; } - q = sdbm_split_page(d, q, hash, h); + q = sdbm_split_page(d, q, hash); b = (void *) q->data; } sdbm_store_entry(d, b->data + b->used, key, keylen, val, *vallen); -- 2.39.5