changed htb to use 'gem' instead of 'hawk'

This commit is contained in:
hyung-hwan 2019-12-14 08:05:06 +00:00
parent cd5dfcd504
commit 0d558ca900
4 changed files with 34 additions and 40 deletions

View File

@ -242,12 +242,12 @@ typedef enum hawk_htb_style_kind_t hawk_htb_style_kind_t;
*/ */
struct hawk_htb_t struct hawk_htb_t
{ {
hawk_t* hawk; hawk_gem_t* gem;
const hawk_htb_style_t* style; const hawk_htb_style_t* style;
hawk_uint8_t scale[2]; /**< length scale */ hawk_uint8_t scale[2]; /**< length scale */
hawk_uint8_t factor; /**< load factor in percentage */ hawk_uint8_t factor; /**< load factor in percentage */
hawk_oow_t size; hawk_oow_t size;
hawk_oow_t capa; hawk_oow_t capa;
@ -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. * @return #hawk_htb_t pointer on success, #HAWK_NULL on failure.
*/ */
HAWK_EXPORT hawk_htb_t* hawk_htb_open ( 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 xtnsize, /**< extension size in bytes */
hawk_oow_t capa, /**< initial capacity */ hawk_oow_t capa, /**< initial capacity */
int factor, /**< load factor */ int factor, /**< load factor */
@ -345,8 +345,8 @@ HAWK_EXPORT void hawk_htb_close (
* The hawk_htb_init() function initializes a hash table * The hawk_htb_init() function initializes a hash table
*/ */
HAWK_EXPORT int hawk_htb_init ( HAWK_EXPORT int hawk_htb_init (
hawk_htb_t* htb, /**< hash table */ hawk_htb_t* htb, /**< hash table */
hawk_t* hawk, /**< awk object */ hawk_gem_t* gem,
hawk_oow_t capa, /**< initial capacity */ hawk_oow_t capa, /**< initial capacity */
int factor, /**< load factor */ int factor, /**< load factor */
int kscale, /**< key scale */ int kscale, /**< key scale */
@ -563,10 +563,10 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_update (
*/ */
HAWK_EXPORT hawk_htb_pair_t* hawk_htb_cbsert ( HAWK_EXPORT hawk_htb_pair_t* hawk_htb_cbsert (
hawk_htb_t* htb, /**< hash table */ hawk_htb_t* htb, /**< hash table */
void* kptr, /**< key pointer */ void* kptr, /**< key pointer */
hawk_oow_t klen, /**< key length */ hawk_oow_t klen, /**< key length */
hawk_htb_cbserter_t cbserter, /**< callback function */ hawk_htb_cbserter_t cbserter, /**< callback function */
void* ctx /**< callback context */ void* ctx /**< callback context */
); );
/** /**

View File

@ -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; awk->tree.chain_size = 0;
/* TODO: initial map size?? */ /* TODO: initial map size?? */
awk->tree.funs = hawk_htb_open(awk, HAWK_SIZEOF(awk), 512, 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(awk, HAWK_SIZEOF(awk), 256, 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(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.gbls = hawk_arr_open(awk, HAWK_SIZEOF(awk), 128);
awk->parse.lcls = hawk_arr_open(awk, HAWK_SIZEOF(awk), 64); awk->parse.lcls = hawk_arr_open(awk, HAWK_SIZEOF(awk), 64);
awk->parse.params = hawk_arr_open(awk, HAWK_SIZEOF(awk), 32); awk->parse.params = hawk_arr_open(awk, HAWK_SIZEOF(awk), 32);
awk->fnc.sys = HAWK_NULL; 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); awk->modtab = hawk_rbt_open(awk, 0, HAWK_SIZEOF(hawk_ooch_t), 1);
if (awk->tree.funs == HAWK_NULL || 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)); hawk_rbt_setstyle (awk->modtab, hawk_get_rbt_style(HAWK_RBT_STYLE_INLINE_COPIERS));
if (hawk_initgbls(awk) <= -1) if (hawk_initgbls(awk) <= -1) goto oops;
{
hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL);
goto oops;
}
return 0; return 0;
oops: oops:

View File

@ -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 (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); 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; if (n == HAWK_NULL) return HAWK_NULL;
NEXT(n) = 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); KPTR(n) = kcop (htb, kptr, klen);
if (KPTR(n) == HAWK_NULL) if (KPTR(n) == HAWK_NULL)
{ {
hawk_freemem (htb->hawk, n); hawk_gem_freemem (htb->gem, n);
return HAWK_NULL; 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) if (htb->style->freeer[HAWK_HTB_KEY] != HAWK_NULL)
htb->style->freeer[HAWK_HTB_KEY] (htb, KPTR(n), KLEN(n)); 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; 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)); htb->style->freeer[HAWK_HTB_KEY] (htb, KPTR(pair), KLEN(pair));
if (htb->style->freeer[HAWK_HTB_VAL] != HAWK_NULL) if (htb->style->freeer[HAWK_HTB_VAL] != HAWK_NULL)
htb->style->freeer[HAWK_HTB_VAL] (htb, VPTR(pair), VLEN(pair)); 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 ( 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]; 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; 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 (!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; 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) void hawk_htb_close (hawk_htb_t* htb)
{ {
hawk_htb_fini (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. /* The initial capacity should be greater than 0.
* Otherwise, it is adjusted to 1 in the release mode */ * 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 */ /* do not zero out the extension */
HAWK_MEMSET (htb, 0, HAWK_SIZEOF(*htb)); 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; if (htb->bucket == HAWK_NULL) return -1;
/*for (i = 0; i < capa; i++) htb->bucket[i] = HAWK_NULL;*/ /*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) void hawk_htb_fini (hawk_htb_t* htb)
{ {
hawk_htb_clear (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) 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) 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; 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_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) if (new_buck == HAWK_NULL)
{ {
/* reorganization is disabled once it fails */ /* 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;*/ /*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++) 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->bucket = new_buck;
htb->capa = new_capa; htb->capa = new_capa;
htb->threshold = htb->capa * htb->factor / 100; 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); pair = hawk_htb_allocpair (htb, kptr, klen, vptr, vlen);
if (pair == HAWK_NULL) return HAWK_NULL; /* error */ 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); pair = cbserter (htb, HAWK_NULL, kptr, klen, ctx);
if (pair == HAWK_NULL) return HAWK_NULL; /* error */ if (pair == HAWK_NULL) return HAWK_NULL; /* error */

View File

@ -2260,10 +2260,9 @@ static hawk_rtx_t* open_rtx_std (
if (rtx->awk->opt.trait & HAWK_RIO) 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_rtx_close (rtx);
hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL);
return HAWK_NULL; return HAWK_NULL;
} }
hawk_htb_setstyle (&rxtn->cmgrtab, hawk_get_htb_style(HAWK_HTB_STYLE_INLINE_COPIERS)); hawk_htb_setstyle (&rxtn->cmgrtab, hawk_get_htb_style(HAWK_HTB_STYLE_INLINE_COPIERS));