added the sizer function to ase_map_t
This commit is contained in:
parent
2230fbd445
commit
2fbbff8139
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: map.h 354 2008-08-31 10:57:24Z baconevi $
|
* $Id: map.h 373 2008-09-23 11:27:24Z baconevi $
|
||||||
*
|
*
|
||||||
* {License}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -70,6 +70,7 @@ struct ase_map_t
|
|||||||
ase_map_freeer_t freeer[2];
|
ase_map_freeer_t freeer[2];
|
||||||
ase_map_hasher_t hasher;
|
ase_map_hasher_t hasher;
|
||||||
ase_map_comper_t comper;
|
ase_map_comper_t comper;
|
||||||
|
ase_sizer_t sizer;
|
||||||
|
|
||||||
ase_size_t size;
|
ase_size_t size;
|
||||||
ase_size_t capa;
|
ase_size_t capa;
|
||||||
@ -201,6 +202,16 @@ void ase_map_setcomper (
|
|||||||
ase_map_comper_t comper
|
ase_map_comper_t comper
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ase_sizer_t ase_map_getsizer (
|
||||||
|
ase_map_t* map
|
||||||
|
);
|
||||||
|
|
||||||
|
/* the sizer function is called with a map object and map->capa + 1 */
|
||||||
|
void ase_map_setsizer (
|
||||||
|
ase_map_t* map,
|
||||||
|
ase_sizer_t sizer
|
||||||
|
);
|
||||||
|
|
||||||
void* ase_map_getextension (
|
void* ase_map_getextension (
|
||||||
ase_map_t* map
|
ase_map_t* map
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: map.c 356 2008-08-31 11:16:52Z baconevi $
|
* $Id: map.c 373 2008-09-23 11:27:24Z baconevi $
|
||||||
*
|
*
|
||||||
* {License}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -315,6 +315,16 @@ void ase_map_setcomper (map_t* map, comper_t comper)
|
|||||||
map->comper = comper;
|
map->comper = comper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ase_sizer_t ase_map_getsizer (map_t* map)
|
||||||
|
{
|
||||||
|
return map->sizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ase_map_setsizer (map_t* map, ase_sizer_t sizer)
|
||||||
|
{
|
||||||
|
map->sizer = sizer;
|
||||||
|
}
|
||||||
|
|
||||||
void* ase_map_getextension (map_t* map)
|
void* ase_map_getextension (map_t* map)
|
||||||
{
|
{
|
||||||
return map + 1;
|
return map + 1;
|
||||||
@ -601,9 +611,20 @@ static int reorganize (map_t* map)
|
|||||||
size_t i, hc, new_capa;
|
size_t i, hc, new_capa;
|
||||||
pair_t** new_buck;
|
pair_t** new_buck;
|
||||||
|
|
||||||
/* the bucket is doubled until it grows up to 65536 slots.
|
if (map->sizer)
|
||||||
* once it has reached it, it grows by 65536 slots */
|
{
|
||||||
new_capa = (map->capa >= 65536)? (map->capa + 65536): (map->capa << 1);
|
new_capa = map->sizer (map, map->capa + 1);
|
||||||
|
|
||||||
|
/* if no change in capacity, return success
|
||||||
|
* without reorganization */
|
||||||
|
if (new_capa == map->capa) return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* the bucket is doubled until it grows up to 65536 slots.
|
||||||
|
* once it has reached it, it grows by 65536 slots */
|
||||||
|
new_capa = (map->capa >= 65536)? (map->capa + 65536): (map->capa << 1);
|
||||||
|
}
|
||||||
|
|
||||||
new_buck = (pair_t**) ASE_MMGR_ALLOC (
|
new_buck = (pair_t**) ASE_MMGR_ALLOC (
|
||||||
map->mmgr, SIZEOF(pair_t*) * new_capa);
|
map->mmgr, SIZEOF(pair_t*) * new_capa);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: str_dyn.c 372 2008-09-23 09:51:24Z baconevi $
|
* $Id: str_dyn.c 373 2008-09-23 11:27:24Z baconevi $
|
||||||
*
|
*
|
||||||
* {License}
|
* {License}
|
||||||
*/
|
*/
|
||||||
@ -213,6 +213,8 @@ ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len)
|
|||||||
/* let the user determine the new capacity.
|
/* let the user determine the new capacity.
|
||||||
* pass the minimum capacity required as a hint */
|
* pass the minimum capacity required as a hint */
|
||||||
ncapa = str->sizer (str, str->len + len);
|
ncapa = str->sizer (str, str->len + len);
|
||||||
|
/* if no change in capacity, return current length */
|
||||||
|
if (ncapa == str->capa) return str->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ase_str_setcapa (str, ncapa) == (ase_size_t)-1)
|
if (ase_str_setcapa (str, ncapa) == (ase_size_t)-1)
|
||||||
@ -223,7 +225,8 @@ ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len)
|
|||||||
|
|
||||||
if (len > str->capa - str->len)
|
if (len > str->capa - str->len)
|
||||||
{
|
{
|
||||||
/* copy as many characters as the number of cells available */
|
/* copy as many characters as the number of cells available.
|
||||||
|
* if the capacity has been decreased, len is adjusted here */
|
||||||
len = str->capa - str->len;
|
len = str->capa - str->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,6 +236,7 @@ ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len)
|
|||||||
str->len += len;
|
str->len += len;
|
||||||
str->ptr[str->len] = ASE_T('\0');
|
str->ptr[str->len] = ASE_T('\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
return str->len;
|
return str->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user