2007-05-02 01:07:00 +00:00
|
|
|
/*
|
2008-03-04 05:15:37 +00:00
|
|
|
* $Id: map.c 116 2008-03-03 11:15:37Z baconevi $
|
2007-05-02 01:07:00 +00:00
|
|
|
*
|
|
|
|
* {License}
|
|
|
|
*/
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
#include <ase/cmn/map.h>
|
|
|
|
#include <ase/cmn/str.h>
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
static ase_size_t hashkey (const ase_char_t* keyptr, ase_size_t keylen);
|
2008-02-13 01:39:56 +00:00
|
|
|
static int rehash (ase_map_t* map);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
#define FREE_PAIR(map,pair) \
|
|
|
|
do { \
|
|
|
|
if ((map)->freeval != ASE_NULL) \
|
2008-02-13 01:39:56 +00:00
|
|
|
(map)->freeval ((map)->owner, ASE_PAIR_VAL(pair)); \
|
|
|
|
ASE_FREE ((map)->mmgr, pair); \
|
2007-05-02 01:07:00 +00:00
|
|
|
} while (0)
|
|
|
|
|
2008-02-29 00:50:10 +00:00
|
|
|
#define RECYCLE_PAIR(map,pair) \
|
|
|
|
do { \
|
|
|
|
if ((map)->freeval != ASE_NULL) \
|
|
|
|
(map)->freeval ((map)->owner, ASE_PAIR_VAL(pair)); \
|
|
|
|
(pair)->next = (map)->fp; \
|
|
|
|
(map)->fp = (pair); \
|
|
|
|
} while (0)
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_map_t* ase_map_open (
|
2007-07-29 23:42:00 +00:00
|
|
|
void* owner, ase_size_t capa, unsigned int factor,
|
2007-12-07 19:57:10 +00:00
|
|
|
void(*freeval)(void*,void*), void(*sameval)(void*,void*),
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_mmgr_t* mmgr)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_map_t* map;
|
2007-05-06 19:44:00 +00:00
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
ASE_ASSERTX (capa > 0, "the initial capacity should be greater than 0");
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
map = (ase_map_t*) ASE_MALLOC (mmgr, ASE_SIZEOF(ase_map_t));
|
2007-05-06 19:44:00 +00:00
|
|
|
if (map == ASE_NULL) return ASE_NULL;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
map->mmgr = mmgr;
|
|
|
|
map->buck = (ase_pair_t**)
|
|
|
|
ASE_MALLOC (mmgr, ASE_SIZEOF(ase_pair_t*)*capa);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (map->buck == ASE_NULL)
|
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_FREE (mmgr, map);
|
2007-05-02 01:07:00 +00:00
|
|
|
return ASE_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
map->owner = owner;
|
|
|
|
map->capa = capa;
|
|
|
|
map->size = 0;
|
|
|
|
map->freeval = freeval;
|
2007-12-07 19:57:10 +00:00
|
|
|
map->sameval = sameval;
|
2007-05-02 01:07:00 +00:00
|
|
|
while (capa > 0) map->buck[--capa] = ASE_NULL;
|
|
|
|
|
2007-07-29 23:42:00 +00:00
|
|
|
map->factor = factor;
|
|
|
|
map->threshold = ((ase_size_t)map->factor) * map->capa / 100;
|
|
|
|
|
2008-02-29 00:50:10 +00:00
|
|
|
/*map->fp = ASE_NULL;*/
|
2007-05-02 01:07:00 +00:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
void ase_map_close (ase_map_t* map)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_map_clear (map);
|
|
|
|
ASE_FREE (map->mmgr, map->buck);
|
|
|
|
ASE_FREE (map->mmgr, map);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
void ase_map_clear (ase_map_t* map)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
ase_size_t i;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair, * next;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-02-29 00:50:10 +00:00
|
|
|
/*
|
|
|
|
while (map->fp != ASE_NULL)
|
|
|
|
{
|
|
|
|
next = ASE_PAIR_LNK(map->fp);
|
|
|
|
ASE_FREE (map->mmgr, map->fp);
|
|
|
|
map->fp = next;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
for (i = 0; i < map->capa; i++)
|
|
|
|
{
|
|
|
|
pair = map->buck[i];
|
|
|
|
|
|
|
|
while (pair != ASE_NULL)
|
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
next = ASE_PAIR_LNK(pair);
|
2007-05-02 01:07:00 +00:00
|
|
|
FREE_PAIR (map, pair);
|
|
|
|
map->size--;
|
|
|
|
pair = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
map->buck[i] = ASE_NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_size_t ase_map_getsize (ase_map_t* map)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
return map->size;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* ase_map_get (
|
|
|
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_size_t hc;
|
|
|
|
|
|
|
|
hc = hashkey(keyptr,keylen) % map->capa;
|
|
|
|
pair = map->buck[hc];
|
|
|
|
|
|
|
|
while (pair != ASE_NULL)
|
|
|
|
{
|
|
|
|
if (ase_strxncmp (
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair),
|
2007-05-02 01:07:00 +00:00
|
|
|
keyptr, keylen) == 0) return pair;
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ASE_PAIR_LNK(pair);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ASE_NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* ase_map_put (
|
2008-02-29 00:50:10 +00:00
|
|
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen, void* val)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
int n;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* px;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
n = ase_map_putx (map, keyptr, keylen, val, &px);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (n < 0) return ASE_NULL;
|
|
|
|
return px;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
int ase_map_putx (
|
|
|
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
|
|
|
void* val, ase_pair_t** px)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-02-29 00:50:10 +00:00
|
|
|
ase_pair_t* pair, * fp, * fp2;
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_size_t hc;
|
|
|
|
|
|
|
|
hc = hashkey(keyptr,keylen) % map->capa;
|
|
|
|
pair = map->buck[hc];
|
|
|
|
|
|
|
|
while (pair != ASE_NULL)
|
|
|
|
{
|
|
|
|
if (ase_strxncmp (
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair),
|
2007-05-02 01:07:00 +00:00
|
|
|
keyptr, keylen) == 0)
|
|
|
|
{
|
|
|
|
if (px != ASE_NULL)
|
2008-02-13 01:39:56 +00:00
|
|
|
*px = ase_map_setpair (map, pair, val);
|
2007-05-02 01:07:00 +00:00
|
|
|
else
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_map_setpair (map, pair, val);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
return 0; /* value changed for the existing key */
|
|
|
|
}
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ASE_PAIR_LNK(pair);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 23:42:00 +00:00
|
|
|
if (map->threshold > 0 &&
|
|
|
|
map->size >= map->threshold)
|
|
|
|
{
|
|
|
|
if (rehash(map) == 0) /* ignore the rehash error */
|
|
|
|
{
|
|
|
|
hc = hashkey(keyptr,keylen) % map->capa;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-29 00:50:10 +00:00
|
|
|
|
|
|
|
ASE_ASSERT (pair == ASE_NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
fp = map->fp; fp2 = ASE_NULL;
|
|
|
|
while (fp != ASE_NULL)
|
|
|
|
{
|
|
|
|
if (fp->key.len == keylen)
|
|
|
|
{
|
|
|
|
pair = fp;
|
|
|
|
if (fp2 == ASE_NULL) map->fp = fp->next;
|
|
|
|
else fp2->next = fp->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fp2 = fp;
|
|
|
|
fp = fp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pair == ASE_NULL)
|
|
|
|
{
|
|
|
|
*/
|
|
|
|
pair = (ase_pair_t*) ASE_MALLOC (map->mmgr,
|
|
|
|
ASE_SIZEOF(ase_pair_t) + ((keylen+1)*ASE_SIZEOF(*keyptr)));
|
|
|
|
if (pair == ASE_NULL) return -1; /* error */
|
|
|
|
/*}*/
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
/* duplicate the key if it is new */
|
2008-02-14 20:36:09 +00:00
|
|
|
ASE_PAIR_KEYPTR(pair) = (ase_char_t*)(pair + 1);
|
2008-02-14 20:33:19 +00:00
|
|
|
ase_strncpy (ASE_PAIR_KEYPTR(pair), keyptr, keylen);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_PAIR_KEYLEN(pair) = keylen;
|
|
|
|
ASE_PAIR_VAL(pair) = val;
|
|
|
|
ASE_PAIR_LNK(pair) = map->buck[hc];
|
2007-05-02 01:07:00 +00:00
|
|
|
map->buck[hc] = pair;
|
|
|
|
map->size++;
|
|
|
|
|
|
|
|
if (px != ASE_NULL) *px = pair;
|
|
|
|
return 1; /* new key added */
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* ase_map_set (
|
|
|
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
2007-05-07 01:05:00 +00:00
|
|
|
void* val)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_size_t hc;
|
|
|
|
|
|
|
|
hc = hashkey(keyptr,keylen) % map->capa;
|
|
|
|
pair = map->buck[hc];
|
|
|
|
|
|
|
|
while (pair != ASE_NULL)
|
|
|
|
{
|
|
|
|
if (ase_strxncmp (
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair),
|
2007-05-02 01:07:00 +00:00
|
|
|
keyptr, keylen) == 0)
|
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
return ase_map_setpair (map, pair, val);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ASE_PAIR_LNK(pair);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ASE_NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* ase_map_getpair (
|
|
|
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
|
2007-05-02 01:07:00 +00:00
|
|
|
void** val)
|
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ase_map_get (map, keyptr, keylen);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (pair == ASE_NULL) return ASE_NULL;
|
2008-02-13 01:39:56 +00:00
|
|
|
*val = ASE_PAIR_VAL(pair);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* ase_map_setpair (
|
|
|
|
ase_map_t* map, ase_pair_t* pair, void* val)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
/* use this function with care */
|
2008-02-13 01:39:56 +00:00
|
|
|
if (ASE_PAIR_VAL(pair) == val)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2007-12-07 19:57:10 +00:00
|
|
|
/* if the old value and the new value are the same,
|
|
|
|
* it just calls the handler for this condition.
|
|
|
|
* No value replacement occurs. */
|
|
|
|
if (map->sameval != ASE_NULL)
|
|
|
|
{
|
|
|
|
map->sameval (map->owner, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* frees the old value */
|
2007-05-02 01:07:00 +00:00
|
|
|
if (map->freeval != ASE_NULL)
|
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
map->freeval (map->owner, ASE_PAIR_VAL(pair));
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
2007-12-07 19:57:10 +00:00
|
|
|
|
|
|
|
/* the new value takes the place */
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_PAIR_VAL(pair) = val;
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
2007-12-07 19:57:10 +00:00
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
int ase_map_remove (
|
|
|
|
ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair, * prev;
|
2007-05-02 01:07:00 +00:00
|
|
|
ase_size_t hc;
|
|
|
|
|
|
|
|
hc = hashkey(keyptr,keylen) % map->capa;
|
|
|
|
pair = map->buck[hc];
|
|
|
|
prev = ASE_NULL;
|
|
|
|
|
|
|
|
while (pair != ASE_NULL)
|
|
|
|
{
|
|
|
|
if (ase_strxncmp (
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_PAIR_KEYPTR(pair), ASE_PAIR_KEYLEN(pair),
|
2007-05-02 01:07:00 +00:00
|
|
|
keyptr, keylen) == 0)
|
|
|
|
{
|
|
|
|
if (prev == ASE_NULL)
|
2008-02-13 01:39:56 +00:00
|
|
|
map->buck[hc] = ASE_PAIR_LNK(pair);
|
2008-02-29 00:50:10 +00:00
|
|
|
else ASE_PAIR_LNK(prev) = ASE_PAIR_LNK(pair);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2008-02-29 00:50:10 +00:00
|
|
|
/*RECYCLE_PAIR (map, pair);*/
|
2007-05-02 01:07:00 +00:00
|
|
|
FREE_PAIR (map, pair);
|
2008-02-29 00:50:10 +00:00
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
map->size--;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = pair;
|
2008-02-13 01:39:56 +00:00
|
|
|
pair = ASE_PAIR_LNK(pair);
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
int ase_map_walk (ase_map_t* map,
|
|
|
|
int (*walker) (ase_pair_t*,void*), void* arg)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
ase_size_t i;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair, * next;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
for (i = 0; i < map->capa; i++)
|
|
|
|
{
|
|
|
|
pair = map->buck[i];
|
|
|
|
|
|
|
|
while (pair != ASE_NULL)
|
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
next = ASE_PAIR_LNK(pair);
|
2007-05-02 01:07:00 +00:00
|
|
|
if (walker(pair,arg) == -1) return -1;
|
|
|
|
pair = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* ase_map_getfirstpair (
|
|
|
|
ase_map_t* map, ase_size_t* buckno)
|
2007-10-02 00:22:00 +00:00
|
|
|
{
|
|
|
|
ase_size_t i;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair;
|
2007-10-02 00:22:00 +00:00
|
|
|
|
|
|
|
for (i = 0; i < map->capa; i++)
|
|
|
|
{
|
|
|
|
pair = map->buck[i];
|
|
|
|
if (pair != ASE_NULL)
|
|
|
|
{
|
|
|
|
*buckno = i;
|
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ASE_NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* ase_map_getnextpair (
|
|
|
|
ase_map_t* map, ase_pair_t* pair, ase_size_t* buckno)
|
2007-10-02 00:22:00 +00:00
|
|
|
{
|
|
|
|
ase_size_t i;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* next;
|
2007-10-02 00:22:00 +00:00
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
next = ASE_PAIR_LNK(pair);
|
2007-10-02 00:22:00 +00:00
|
|
|
if (next != ASE_NULL)
|
|
|
|
{
|
|
|
|
/* no change in bucket number */
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = (*buckno)+1; i < map->capa; i++)
|
|
|
|
{
|
|
|
|
pair = map->buck[i];
|
|
|
|
if (pair != ASE_NULL)
|
|
|
|
{
|
|
|
|
*buckno = i;
|
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ASE_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
static ase_size_t hashkey (const ase_char_t* keyptr, ase_size_t keylen)
|
|
|
|
{
|
|
|
|
ase_size_t n = 0, i;
|
|
|
|
const ase_char_t* end = keyptr + keylen;
|
|
|
|
|
|
|
|
while (keyptr < end)
|
|
|
|
{
|
|
|
|
ase_byte_t* bp = (ase_byte_t*)keyptr;
|
|
|
|
for (i = 0; i < ASE_SIZEOF(*keyptr); i++) n = n * 31 + *bp++;
|
|
|
|
keyptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
2007-07-29 23:42:00 +00:00
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
static int rehash (ase_map_t* map)
|
2007-07-29 23:42:00 +00:00
|
|
|
{
|
|
|
|
ase_size_t i, hc, new_capa;
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t** new_buck;
|
2007-07-29 23:42:00 +00:00
|
|
|
|
|
|
|
new_capa = (map->capa >= 65536)? (map->capa + 65536): (map->capa << 1);
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
new_buck = (ase_pair_t**) ASE_MALLOC (
|
|
|
|
map->mmgr, ASE_SIZEOF(ase_pair_t*) * new_capa);
|
2007-07-29 23:42:00 +00:00
|
|
|
if (new_buck == ASE_NULL)
|
|
|
|
{
|
|
|
|
/* once rehash fails, the rehashing is disabled */
|
|
|
|
map->threshold = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < new_capa; i++) new_buck[i] = ASE_NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < map->capa; i++)
|
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* pair = map->buck[i];
|
2007-07-29 23:42:00 +00:00
|
|
|
|
|
|
|
while (pair != ASE_NULL)
|
|
|
|
{
|
2008-02-13 01:39:56 +00:00
|
|
|
ase_pair_t* next = ASE_PAIR_LNK(pair);
|
2007-07-29 23:42:00 +00:00
|
|
|
|
|
|
|
hc = hashkey(
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_PAIR_KEYPTR(pair),
|
|
|
|
ASE_PAIR_KEYLEN(pair)) % new_capa;
|
2007-07-29 23:42:00 +00:00
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_PAIR_LNK(pair) = new_buck[hc];
|
2007-07-29 23:42:00 +00:00
|
|
|
new_buck[hc] = pair;
|
|
|
|
|
|
|
|
pair = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-13 01:39:56 +00:00
|
|
|
ASE_FREE (map->mmgr, map->buck);
|
2007-07-29 23:42:00 +00:00
|
|
|
map->buck = new_buck;
|
|
|
|
map->capa = new_capa;
|
|
|
|
map->threshold = ((ase_size_t)map->factor) * map->capa / 100;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|