changed htb to use 'gem' instead of 'hawk'
This commit is contained in:
parent
cd5dfcd504
commit
0d558ca900
@ -242,7 +242,7 @@ typedef enum hawk_htb_style_kind_t hawk_htb_style_kind_t;
|
||||
*/
|
||||
struct hawk_htb_t
|
||||
{
|
||||
hawk_t* hawk;
|
||||
hawk_gem_t* gem;
|
||||
|
||||
const hawk_htb_style_t* style;
|
||||
|
||||
@ -325,7 +325,7 @@ HAWK_EXPORT const hawk_htb_style_t* hawk_get_htb_style (
|
||||
* @return #hawk_htb_t pointer on success, #HAWK_NULL on failure.
|
||||
*/
|
||||
HAWK_EXPORT hawk_htb_t* hawk_htb_open (
|
||||
hawk_t* hawk, /**< awk object */
|
||||
hawk_gem_t* gem,
|
||||
hawk_oow_t xtnsize, /**< extension size in bytes */
|
||||
hawk_oow_t capa, /**< initial capacity */
|
||||
int factor, /**< load factor */
|
||||
@ -346,7 +346,7 @@ HAWK_EXPORT void hawk_htb_close (
|
||||
*/
|
||||
HAWK_EXPORT int hawk_htb_init (
|
||||
hawk_htb_t* htb, /**< hash table */
|
||||
hawk_t* hawk, /**< awk object */
|
||||
hawk_gem_t* gem,
|
||||
hawk_oow_t capa, /**< initial capacity */
|
||||
int factor, /**< load factor */
|
||||
int kscale, /**< key scale */
|
||||
|
@ -195,16 +195,16 @@ int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm
|
||||
awk->tree.chain_size = 0;
|
||||
|
||||
/* TODO: initial map size?? */
|
||||
awk->tree.funs = hawk_htb_open(awk, HAWK_SIZEOF(awk), 512, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
|
||||
awk->parse.funs = hawk_htb_open(awk, HAWK_SIZEOF(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
|
||||
awk->parse.named = hawk_htb_open(awk, HAWK_SIZEOF(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
|
||||
awk->tree.funs = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 512, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
|
||||
awk->parse.funs = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
|
||||
awk->parse.named = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
|
||||
|
||||
awk->parse.gbls = hawk_arr_open(awk, HAWK_SIZEOF(awk), 128);
|
||||
awk->parse.lcls = hawk_arr_open(awk, HAWK_SIZEOF(awk), 64);
|
||||
awk->parse.params = hawk_arr_open(awk, HAWK_SIZEOF(awk), 32);
|
||||
|
||||
awk->fnc.sys = HAWK_NULL;
|
||||
awk->fnc.user = hawk_htb_open(awk, HAWK_SIZEOF(awk), 512, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
|
||||
awk->fnc.user = hawk_htb_open(hawk_getgem(awk), HAWK_SIZEOF(awk), 512, 70, HAWK_SIZEOF(hawk_ooch_t), 1);
|
||||
awk->modtab = hawk_rbt_open(awk, 0, HAWK_SIZEOF(hawk_ooch_t), 1);
|
||||
|
||||
if (awk->tree.funs == HAWK_NULL ||
|
||||
@ -246,12 +246,7 @@ int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm
|
||||
|
||||
hawk_rbt_setstyle (awk->modtab, hawk_get_rbt_style(HAWK_RBT_STYLE_INLINE_COPIERS));
|
||||
|
||||
if (hawk_initgbls(awk) <= -1)
|
||||
{
|
||||
hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (hawk_initgbls(awk) <= -1) goto oops;
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
|
@ -61,7 +61,7 @@ HAWK_INLINE pair_t* hawk_htb_allocpair (hawk_htb_t* htb, void* kptr, hawk_oow_t
|
||||
if (kcop == HAWK_HTB_COPIER_INLINE) as += HAWK_ALIGN_POW2(KTOB(htb,klen), HAWK_SIZEOF_VOID_P);
|
||||
if (vcop == HAWK_HTB_COPIER_INLINE) as += VTOB(htb,vlen);
|
||||
|
||||
n = (pair_t*) hawk_allocmem(htb->hawk, as);
|
||||
n = (pair_t*) hawk_gem_allocmem(htb->gem, as);
|
||||
if (n == HAWK_NULL) return HAWK_NULL;
|
||||
|
||||
NEXT(n) = HAWK_NULL;
|
||||
@ -83,7 +83,7 @@ HAWK_INLINE pair_t* hawk_htb_allocpair (hawk_htb_t* htb, void* kptr, hawk_oow_t
|
||||
KPTR(n) = kcop (htb, kptr, klen);
|
||||
if (KPTR(n) == HAWK_NULL)
|
||||
{
|
||||
hawk_freemem (htb->hawk, n);
|
||||
hawk_gem_freemem (htb->gem, n);
|
||||
return HAWK_NULL;
|
||||
}
|
||||
}
|
||||
@ -109,7 +109,7 @@ HAWK_INLINE pair_t* hawk_htb_allocpair (hawk_htb_t* htb, void* kptr, hawk_oow_t
|
||||
{
|
||||
if (htb->style->freeer[HAWK_HTB_KEY] != HAWK_NULL)
|
||||
htb->style->freeer[HAWK_HTB_KEY] (htb, KPTR(n), KLEN(n));
|
||||
hawk_freemem (htb->hawk, n);
|
||||
hawk_gem_freemem (htb->gem, n);
|
||||
return HAWK_NULL;
|
||||
}
|
||||
}
|
||||
@ -123,7 +123,7 @@ HAWK_INLINE void hawk_htb_freepair (hawk_htb_t* htb, pair_t* pair)
|
||||
htb->style->freeer[HAWK_HTB_KEY] (htb, KPTR(pair), KLEN(pair));
|
||||
if (htb->style->freeer[HAWK_HTB_VAL] != HAWK_NULL)
|
||||
htb->style->freeer[HAWK_HTB_VAL] (htb, VPTR(pair), VLEN(pair));
|
||||
hawk_freemem (htb->hawk, pair);
|
||||
hawk_gem_freemem (htb->gem, pair);
|
||||
}
|
||||
|
||||
static HAWK_INLINE pair_t* change_pair_val (
|
||||
@ -259,16 +259,16 @@ const style_t* hawk_get_htb_style (style_kind_t kind)
|
||||
return &style[kind];
|
||||
}
|
||||
|
||||
hawk_htb_t* hawk_htb_open (hawk_t* hawk, hawk_oow_t xtnsize, hawk_oow_t capa, int factor, int kscale, int vscale)
|
||||
hawk_htb_t* hawk_htb_open (hawk_gem_t* gem, hawk_oow_t xtnsize, hawk_oow_t capa, int factor, int kscale, int vscale)
|
||||
{
|
||||
hawk_htb_t* htb;
|
||||
|
||||
htb = (hawk_htb_t*)hawk_allocmem(hawk, HAWK_SIZEOF(hawk_htb_t) + xtnsize);
|
||||
htb = (hawk_htb_t*)hawk_gem_allocmem(gem, HAWK_SIZEOF(hawk_htb_t) + xtnsize);
|
||||
if (!htb) return HAWK_NULL;
|
||||
|
||||
if (hawk_htb_init(htb, hawk, capa, factor, kscale, vscale) <= -1)
|
||||
if (hawk_htb_init(htb, gem, capa, factor, kscale, vscale) <= -1)
|
||||
{
|
||||
hawk_freemem (hawk, htb);
|
||||
hawk_gem_freemem (gem, htb);
|
||||
return HAWK_NULL;
|
||||
}
|
||||
|
||||
@ -279,10 +279,10 @@ hawk_htb_t* hawk_htb_open (hawk_t* hawk, hawk_oow_t xtnsize, hawk_oow_t capa, in
|
||||
void hawk_htb_close (hawk_htb_t* htb)
|
||||
{
|
||||
hawk_htb_fini (htb);
|
||||
hawk_freemem (htb->hawk, htb);
|
||||
hawk_gem_freemem (htb->gem, htb);
|
||||
}
|
||||
|
||||
int hawk_htb_init (hawk_htb_t* htb, hawk_t* hawk, hawk_oow_t capa, int factor, int kscale, int vscale)
|
||||
int hawk_htb_init (hawk_htb_t* htb, hawk_gem_t* gem, hawk_oow_t capa, int factor, int kscale, int vscale)
|
||||
{
|
||||
/* The initial capacity should be greater than 0.
|
||||
* Otherwise, it is adjusted to 1 in the release mode */
|
||||
@ -301,9 +301,9 @@ int hawk_htb_init (hawk_htb_t* htb, hawk_t* hawk, hawk_oow_t capa, int factor, i
|
||||
|
||||
/* do not zero out the extension */
|
||||
HAWK_MEMSET (htb, 0, HAWK_SIZEOF(*htb));
|
||||
htb->hawk = hawk;
|
||||
htb->gem = gem;
|
||||
|
||||
htb->bucket = hawk_allocmem(hawk, capa * HAWK_SIZEOF(pair_t*));
|
||||
htb->bucket = hawk_gem_allocmem(gem, capa * HAWK_SIZEOF(pair_t*));
|
||||
if (htb->bucket == HAWK_NULL) return -1;
|
||||
|
||||
/*for (i = 0; i < capa; i++) htb->bucket[i] = HAWK_NULL;*/
|
||||
@ -325,7 +325,7 @@ int hawk_htb_init (hawk_htb_t* htb, hawk_t* hawk, hawk_oow_t capa, int factor, i
|
||||
void hawk_htb_fini (hawk_htb_t* htb)
|
||||
{
|
||||
hawk_htb_clear (htb);
|
||||
hawk_freemem (htb->hawk, htb->bucket);
|
||||
hawk_gem_freemem (htb->gem, htb->bucket);
|
||||
}
|
||||
|
||||
const style_t* hawk_htb_getstyle (const hawk_htb_t* htb)
|
||||
@ -335,7 +335,7 @@ const style_t* hawk_htb_getstyle (const hawk_htb_t* htb)
|
||||
|
||||
void hawk_htb_setstyle (hawk_htb_t* htb, const style_t* style)
|
||||
{
|
||||
HAWK_ASSERT (htb->hawk, style != HAWK_NULL);
|
||||
HAWK_ASSERT (htb->gem, style != HAWK_NULL);
|
||||
htb->style = style;
|
||||
}
|
||||
|
||||
@ -393,7 +393,7 @@ static HAWK_INLINE int reorganize (hawk_htb_t* htb)
|
||||
new_capa = (htb->capa >= 65536)? (htb->capa + 65536): (htb->capa << 1);
|
||||
}
|
||||
|
||||
new_buck = (pair_t**)hawk_allocmem(htb->hawk, new_capa * HAWK_SIZEOF(pair_t*));
|
||||
new_buck = (pair_t**)hawk_gem_allocmem(htb->gem, new_capa * HAWK_SIZEOF(pair_t*));
|
||||
if (new_buck == HAWK_NULL)
|
||||
{
|
||||
/* reorganization is disabled once it fails */
|
||||
@ -402,7 +402,7 @@ static HAWK_INLINE int reorganize (hawk_htb_t* htb)
|
||||
}
|
||||
|
||||
/*for (i = 0; i < new_capa; i++) new_buck[i] = HAWK_NULL;*/
|
||||
HAWK_MEMSET (new_buck, 0, new_capa*HAWK_SIZEOF(pair_t*));
|
||||
HAWK_MEMSET (new_buck, 0, new_capa * HAWK_SIZEOF(pair_t*));
|
||||
|
||||
for (i = 0; i < htb->capa; i++)
|
||||
{
|
||||
@ -421,7 +421,7 @@ static HAWK_INLINE int reorganize (hawk_htb_t* htb)
|
||||
}
|
||||
}
|
||||
|
||||
hawk_freemem (htb->hawk, htb->bucket);
|
||||
hawk_gem_freemem (htb->gem, htb->bucket);
|
||||
htb->bucket = new_buck;
|
||||
htb->capa = new_capa;
|
||||
htb->threshold = htb->capa * htb->factor / 100;
|
||||
@ -499,7 +499,7 @@ static HAWK_INLINE pair_t* insert (hawk_htb_t* htb, void* kptr, hawk_oow_t klen,
|
||||
}
|
||||
}
|
||||
|
||||
HAWK_ASSERT (htb->hawk, pair == HAWK_NULL);
|
||||
HAWK_ASSERT (htb->gem, pair == HAWK_NULL);
|
||||
|
||||
pair = hawk_htb_allocpair (htb, kptr, klen, vptr, vlen);
|
||||
if (pair == HAWK_NULL) return HAWK_NULL; /* error */
|
||||
@ -581,7 +581,7 @@ pair_t* hawk_htb_cbsert (hawk_htb_t* htb, void* kptr, hawk_oow_t klen, cbserter_
|
||||
}
|
||||
}
|
||||
|
||||
HAWK_ASSERT (htb->hawk, pair == HAWK_NULL);
|
||||
HAWK_ASSERT (htb->gem, pair == HAWK_NULL);
|
||||
|
||||
pair = cbserter (htb, HAWK_NULL, kptr, klen, ctx);
|
||||
if (pair == HAWK_NULL) return HAWK_NULL; /* error */
|
||||
|
@ -2260,10 +2260,9 @@ static hawk_rtx_t* open_rtx_std (
|
||||
|
||||
if (rtx->awk->opt.trait & HAWK_RIO)
|
||||
{
|
||||
if (hawk_htb_init(&rxtn->cmgrtab, awk, 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1) <= -1)
|
||||
if (hawk_htb_init(&rxtn->cmgrtab, hawk_getgem(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1) <= -1)
|
||||
{
|
||||
hawk_rtx_close (rtx);
|
||||
hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL);
|
||||
return HAWK_NULL;
|
||||
}
|
||||
hawk_htb_setstyle (&rxtn->cmgrtab, hawk_get_htb_style(HAWK_HTB_STYLE_INLINE_COPIERS));
|
||||
|
Loading…
Reference in New Issue
Block a user