summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-01-28 12:03:36 -0600
committerAllan McRae <allan@archlinux.org>2011-02-04 09:55:45 +1000
commitce5471511257ada996bfcb6ea4236cd89c0d6890 (patch)
treef8d66707046dcb64921db1ca90094c44110b4d53 /lib/libalpm
parentf8fdce6cb0da4d832ffa730e0dacb5544c1f8154 (diff)
downloadpacman-ce5471511257ada996bfcb6ea4236cd89c0d6890.tar.xz
Implement a quick and dirty rehash function
This allows us to get through the rehash required by smoke001 and pass all pactests. It is by no means the best or most efficient implementation but it does do the job. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/pkghash.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/libalpm/pkghash.c b/lib/libalpm/pkghash.c
index 3ed6453f..f2497070 100644
--- a/lib/libalpm/pkghash.c
+++ b/lib/libalpm/pkghash.c
@@ -77,9 +77,9 @@ pmpkghash_t *_alpm_pkghash_create(size_t size)
/* Expand the hash table size to the next increment and rebin the entries */
static pmpkghash_t *rehash(pmpkghash_t *oldhash)
{
- //pmpkghash_t *newhash;
-
- /* TODO - calculate size of newhash */
+ pmpkghash_t *newhash;
+ alpm_list_t *ptr;
+ size_t newsize;
/* Hash tables will need resized in two cases:
* - adding packages to the local database
* - poor estimation of the number of packages in sync database
@@ -89,17 +89,22 @@ static pmpkghash_t *rehash(pmpkghash_t *oldhash)
* larger database sizes, this increase is reduced to avoid excess
* memory allocation as both scenarios requiring a rehash should not
* require a table size increase that large. */
+ if(oldhash->buckets < 500) {
+ newsize = oldhash->buckets * 2;
+ } else if(oldhash->buckets < 3500) {
+ newsize = oldhash->buckets * 3 / 2;
+ } else {
+ newsize = oldhash->buckets * 4 / 3;
+ }
- //newhash = _alpm_pkghash_create(oldhash->buckets);
-
- /* TODO - rebin entries */
-
- //_alpm_pkghash_free(oldhash);
+ newhash = _alpm_pkghash_create(newsize);
+ for(ptr = oldhash->list; ptr != NULL; ptr = ptr->next) {
+ newhash = _alpm_pkghash_add(newhash, ptr->data);
+ }
- //return newhash;
+ _alpm_pkghash_free(oldhash);
- printf("rehash needed!!!\n");
- return(oldhash);
+ return(newhash);
}
pmpkghash_t *_alpm_pkghash_add(pmpkghash_t *hash, pmpkg_t *pkg)