2020-04-30 16:20:31 +00:00
|
|
|
/*
|
2020-05-04 08:40:05 +00:00
|
|
|
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
#include <hio-htb.h>
|
|
|
|
#include "hio-prv.h"
|
|
|
|
|
|
|
|
#define pair_t hio_htb_pair_t
|
|
|
|
#define copier_t hio_htb_copier_t
|
|
|
|
#define freeer_t hio_htb_freeer_t
|
|
|
|
#define hasher_t hio_htb_hasher_t
|
|
|
|
#define comper_t hio_htb_comper_t
|
|
|
|
#define keeper_t hio_htb_keeper_t
|
|
|
|
#define sizer_t hio_htb_sizer_t
|
|
|
|
#define walker_t hio_htb_walker_t
|
|
|
|
#define cbserter_t hio_htb_cbserter_t
|
|
|
|
#define style_t hio_htb_style_t
|
|
|
|
#define style_kind_t hio_htb_style_kind_t
|
|
|
|
|
|
|
|
#define KPTR(p) HIO_HTB_KPTR(p)
|
|
|
|
#define KLEN(p) HIO_HTB_KLEN(p)
|
|
|
|
#define VPTR(p) HIO_HTB_VPTR(p)
|
|
|
|
#define VLEN(p) HIO_HTB_VLEN(p)
|
|
|
|
#define NEXT(p) HIO_HTB_NEXT(p)
|
|
|
|
|
|
|
|
#define KTOB(htb,len) ((len)*(htb)->scale[HIO_HTB_KEY])
|
|
|
|
#define VTOB(htb,len) ((len)*(htb)->scale[HIO_HTB_VAL])
|
|
|
|
|
|
|
|
HIO_INLINE pair_t* hio_htb_allocpair (hio_htb_t* htb, void* kptr, hio_oow_t klen, void* vptr, hio_oow_t vlen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
pair_t* n;
|
|
|
|
copier_t kcop, vcop;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t as;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
kcop = htb->style->copier[HIO_HTB_KEY];
|
|
|
|
vcop = htb->style->copier[HIO_HTB_VAL];
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
as = HIO_SIZEOF(pair_t);
|
|
|
|
if (kcop == HIO_HTB_COPIER_INLINE) as += HIO_ALIGN_POW2(KTOB(htb,klen), HIO_SIZEOF_VOID_P);
|
|
|
|
if (vcop == HIO_HTB_COPIER_INLINE) as += VTOB(htb,vlen);
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
n = (pair_t*) hio_allocmem(htb->hio, as);
|
|
|
|
if (HIO_UNLIKELY(!n)) return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
NEXT(n) = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
KLEN(n) = klen;
|
2021-07-22 07:30:20 +00:00
|
|
|
if (kcop == HIO_HTB_COPIER_SIMPLE)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
KPTR(n) = kptr;
|
|
|
|
}
|
2021-07-22 07:30:20 +00:00
|
|
|
else if (kcop == HIO_HTB_COPIER_INLINE)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
KPTR(n) = n + 1;
|
2021-07-22 07:30:20 +00:00
|
|
|
/* if kptr is HIO_NULL, the inline copier does not fill
|
2020-04-30 16:20:31 +00:00
|
|
|
* the actual key area */
|
2021-07-22 07:30:20 +00:00
|
|
|
if (kptr) HIO_MEMCPY (KPTR(n), kptr, KTOB(htb,klen));
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
2023-01-11 14:59:41 +00:00
|
|
|
else
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
KPTR(n) = kcop(htb, kptr, klen);
|
2021-07-22 07:30:20 +00:00
|
|
|
if (KPTR(n) == HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_freemem (htb->hio, n);
|
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VLEN(n) = vlen;
|
2021-07-22 07:30:20 +00:00
|
|
|
if (vcop == HIO_HTB_COPIER_SIMPLE)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
VPTR(n) = vptr;
|
|
|
|
}
|
2021-07-22 07:30:20 +00:00
|
|
|
else if (vcop == HIO_HTB_COPIER_INLINE)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
VPTR(n) = n + 1;
|
2023-01-11 14:59:41 +00:00
|
|
|
if (kcop == HIO_HTB_COPIER_INLINE)
|
2021-07-22 07:30:20 +00:00
|
|
|
VPTR(n) = (hio_uint8_t*)VPTR(n) + HIO_ALIGN_POW2(KTOB(htb,klen), HIO_SIZEOF_VOID_P);
|
|
|
|
/* if vptr is HIO_NULL, the inline copier does not fill
|
2020-04-30 16:20:31 +00:00
|
|
|
* the actual value area */
|
2021-07-22 07:30:20 +00:00
|
|
|
if (vptr) HIO_MEMCPY (VPTR(n), vptr, VTOB(htb,vlen));
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
2023-01-11 14:59:41 +00:00
|
|
|
else
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
VPTR(n) = vcop (htb, vptr, vlen);
|
2021-07-22 07:30:20 +00:00
|
|
|
if (VPTR(n) != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
if (htb->style->freeer[HIO_HTB_KEY] != HIO_NULL)
|
|
|
|
htb->style->freeer[HIO_HTB_KEY] (htb, KPTR(n), KLEN(n));
|
|
|
|
hio_freemem (htb->hio, n);
|
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_INLINE void hio_htb_freepair (hio_htb_t* htb, pair_t* pair)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2023-01-11 14:59:41 +00:00
|
|
|
if (htb->style->freeer[HIO_HTB_KEY] != HIO_NULL)
|
2021-07-22 07:30:20 +00:00
|
|
|
htb->style->freeer[HIO_HTB_KEY] (htb, KPTR(pair), KLEN(pair));
|
|
|
|
if (htb->style->freeer[HIO_HTB_VAL] != HIO_NULL)
|
|
|
|
htb->style->freeer[HIO_HTB_VAL] (htb, VPTR(pair), VLEN(pair));
|
2023-01-11 14:59:41 +00:00
|
|
|
hio_freemem (htb->hio, pair);
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
static HIO_INLINE pair_t* change_pair_val (hio_htb_t* htb, pair_t* pair, void* vptr, hio_oow_t vlen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2023-01-11 14:59:41 +00:00
|
|
|
if (VPTR(pair) == vptr && VLEN(pair) == vlen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* if the old value and the new value are the same,
|
2023-01-11 14:59:41 +00:00
|
|
|
* it just calls the handler for this condition.
|
2020-04-30 16:20:31 +00:00
|
|
|
* No value replacement occurs. */
|
2021-07-22 07:30:20 +00:00
|
|
|
if (htb->style->keeper != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
htb->style->keeper (htb, vptr, vlen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
copier_t vcop = htb->style->copier[HIO_HTB_VAL];
|
2020-04-30 16:20:31 +00:00
|
|
|
void* ovptr = VPTR(pair);
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t ovlen = VLEN(pair);
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
/* place the new value according to the copier */
|
2021-07-22 07:30:20 +00:00
|
|
|
if (vcop == HIO_HTB_COPIER_SIMPLE)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
VPTR(pair) = vptr;
|
|
|
|
VLEN(pair) = vlen;
|
|
|
|
}
|
2021-07-22 07:30:20 +00:00
|
|
|
else if (vcop == HIO_HTB_COPIER_INLINE)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
if (ovlen == vlen)
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
if (vptr) HIO_MEMCPY (VPTR(pair), vptr, VTOB(htb,vlen));
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* need to reconstruct the pair */
|
2021-07-22 07:30:20 +00:00
|
|
|
pair_t* p = hio_htb_allocpair(htb, KPTR(pair), KLEN(pair), vptr, vlen);
|
|
|
|
if (HIO_UNLIKELY(!p)) return HIO_NULL;
|
|
|
|
hio_htb_freepair (htb, pair);
|
2020-04-30 16:20:31 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
2023-01-11 14:59:41 +00:00
|
|
|
else
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
void* nvptr = vcop(htb, vptr, vlen);
|
2021-07-22 07:30:20 +00:00
|
|
|
if (HIO_UNLIKELY(!nvptr)) return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
VPTR(pair) = nvptr;
|
|
|
|
VLEN(pair) = vlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free up the old value */
|
2023-01-11 14:59:41 +00:00
|
|
|
if (htb->style->freeer[HIO_HTB_VAL] != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
htb->style->freeer[HIO_HTB_VAL] (htb, ovptr, ovlen);
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
|
|
|
|
static style_t style[] =
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
/* == HIO_HTB_STYLE_DEFAULT == */
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_COPIER_DEFAULT,
|
|
|
|
HIO_HTB_COPIER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_FREEER_DEFAULT,
|
|
|
|
HIO_HTB_FREEER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_COMPER_DEFAULT,
|
|
|
|
HIO_HTB_KEEPER_DEFAULT,
|
|
|
|
HIO_HTB_SIZER_DEFAULT,
|
|
|
|
HIO_HTB_HASHER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
/* == HIO_HTB_STYLE_INLINE_COPIERS == */
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_COPIER_INLINE,
|
|
|
|
HIO_HTB_COPIER_INLINE
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_FREEER_DEFAULT,
|
|
|
|
HIO_HTB_FREEER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_COMPER_DEFAULT,
|
|
|
|
HIO_HTB_KEEPER_DEFAULT,
|
|
|
|
HIO_HTB_SIZER_DEFAULT,
|
|
|
|
HIO_HTB_HASHER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
/* == HIO_HTB_STYLE_INLINE_KEY_COPIER == */
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_COPIER_INLINE,
|
|
|
|
HIO_HTB_COPIER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_FREEER_DEFAULT,
|
|
|
|
HIO_HTB_FREEER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_COMPER_DEFAULT,
|
|
|
|
HIO_HTB_KEEPER_DEFAULT,
|
|
|
|
HIO_HTB_SIZER_DEFAULT,
|
|
|
|
HIO_HTB_HASHER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
/* == HIO_HTB_STYLE_INLINE_VALUE_COPIER == */
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_COPIER_DEFAULT,
|
|
|
|
HIO_HTB_COPIER_INLINE
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_FREEER_DEFAULT,
|
|
|
|
HIO_HTB_FREEER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
},
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_HTB_COMPER_DEFAULT,
|
|
|
|
HIO_HTB_KEEPER_DEFAULT,
|
|
|
|
HIO_HTB_SIZER_DEFAULT,
|
|
|
|
HIO_HTB_HASHER_DEFAULT
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
const style_t* hio_get_htb_style (style_kind_t kind)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
return &style[kind];
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_htb_t* hio_htb_open (hio_t* hio, hio_oow_t xtnsize, hio_oow_t capa, int factor, int kscale, int vscale)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_htb_t* htb;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
htb = (hio_htb_t*)hio_allocmem(hio, HIO_SIZEOF(hio_htb_t) + xtnsize);
|
|
|
|
if (HIO_UNLIKELY(!htb)) return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
if (hio_htb_init(htb, hio, capa, factor, kscale, vscale) <= -1)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_freemem (hio, htb);
|
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_MEMSET (htb + 1, 0, xtnsize);
|
2020-04-30 16:20:31 +00:00
|
|
|
return htb;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
void hio_htb_close (hio_htb_t* htb)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_htb_fini (htb);
|
|
|
|
hio_freemem (htb->hio, htb);
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
int hio_htb_init (hio_htb_t* htb, hio_t* hio, hio_oow_t capa, int factor, int kscale, int vscale)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2023-01-11 14:59:41 +00:00
|
|
|
/* The initial capacity should be greater than 0.
|
2020-04-30 16:20:31 +00:00
|
|
|
* Otherwise, it is adjusted to 1 in the release mode */
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_ASSERT (hio, capa > 0);
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
/* The load factor should be between 0 and 100 inclusive.
|
2020-04-30 16:20:31 +00:00
|
|
|
* In the release mode, a value out of the range is adjusted to 100 */
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_ASSERT (hio, factor >= 0 && factor <= 100);
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_ASSERT (hio, kscale >= 0 && kscale <= HIO_TYPE_MAX(hio_uint8_t));
|
|
|
|
HIO_ASSERT (hio, vscale >= 0 && vscale <= HIO_TYPE_MAX(hio_uint8_t));
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
/* some initial adjustment */
|
|
|
|
if (capa <= 0) capa = 1;
|
|
|
|
if (factor > 100) factor = 100;
|
|
|
|
|
|
|
|
/* do not zero out the extension */
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_MEMSET (htb, 0, HIO_SIZEOF(*htb));
|
|
|
|
htb->hio = hio;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
htb->bucket = hio_allocmem(hio, capa * HIO_SIZEOF(pair_t*));
|
|
|
|
if (HIO_UNLIKELY(!htb->bucket)) return -1;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
/*for (i = 0; i < capa; i++) htb->bucket[i] = HIO_NULL;*/
|
|
|
|
HIO_MEMSET (htb->bucket, 0, capa * HIO_SIZEOF(pair_t*));
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
htb->factor = factor;
|
2021-07-22 07:30:20 +00:00
|
|
|
htb->scale[HIO_HTB_KEY] = (kscale < 1)? 1: kscale;
|
|
|
|
htb->scale[HIO_HTB_VAL] = (vscale < 1)? 1: vscale;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
htb->size = 0;
|
|
|
|
htb->capa = capa;
|
|
|
|
htb->threshold = htb->capa * htb->factor / 100;
|
|
|
|
if (htb->capa > 0 && htb->threshold <= 0) htb->threshold = 1;
|
|
|
|
|
|
|
|
htb->style = &style[0];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
void hio_htb_fini (hio_htb_t* htb)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_htb_clear (htb);
|
|
|
|
hio_freemem (htb->hio, htb->bucket);
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
const style_t* hio_htb_getstyle (const hio_htb_t* htb)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
return htb->style;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
void hio_htb_setstyle (hio_htb_t* htb, const style_t* style)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_ASSERT (htb->hio, style != HIO_NULL);
|
2020-04-30 16:20:31 +00:00
|
|
|
htb->style = style;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t hio_htb_getsize (const hio_htb_t* htb)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
return htb->size;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t hio_htb_getcapa (const hio_htb_t* htb)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
return htb->capa;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair_t* hio_htb_search (const hio_htb_t* htb, const void* kptr, hio_oow_t klen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
pair_t* pair;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t hc;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
|
|
|
|
pair = htb->bucket[hc];
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
while (pair != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
if (htb->style->comper(htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
|
|
|
|
{
|
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
|
|
|
|
pair = NEXT(pair);
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_seterrnum (htb->hio, HIO_ENOENT);
|
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
static HIO_INLINE int reorganize (hio_htb_t* htb)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t i, hc, new_capa;
|
2020-04-30 16:20:31 +00:00
|
|
|
pair_t** new_buck;
|
|
|
|
|
|
|
|
if (htb->style->sizer)
|
|
|
|
{
|
|
|
|
new_capa = htb->style->sizer (htb, htb->capa + 1);
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
/* if no change in capacity, return success
|
2020-04-30 16:20:31 +00:00
|
|
|
* without reorganization */
|
2023-01-11 14:59:41 +00:00
|
|
|
if (new_capa == htb->capa) return 0;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
/* adjust to 1 if the new capacity is not reasonable */
|
|
|
|
if (new_capa <= 0) new_capa = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* the bucket is doubled until it grows up to 65536 slots.
|
|
|
|
* once it has reached it, it grows by 65536 slots */
|
|
|
|
new_capa = (htb->capa >= 65536)? (htb->capa + 65536): (htb->capa << 1);
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
new_buck = (pair_t**)hio_allocmem(htb->hio, new_capa * HIO_SIZEOF(pair_t*));
|
2023-01-11 14:59:41 +00:00
|
|
|
if (HIO_UNLIKELY(!new_buck))
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* reorganization is disabled once it fails */
|
|
|
|
htb->threshold = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
/*for (i = 0; i < new_capa; i++) new_buck[i] = HIO_NULL;*/
|
|
|
|
HIO_MEMSET (new_buck, 0, new_capa * HIO_SIZEOF(pair_t*));
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
for (i = 0; i < htb->capa; i++)
|
|
|
|
{
|
|
|
|
pair_t* pair = htb->bucket[i];
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
while (pair != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
pair_t* next = NEXT(pair);
|
|
|
|
|
|
|
|
hc = htb->style->hasher(htb, KPTR(pair), KLEN(pair)) % new_capa;
|
|
|
|
|
|
|
|
NEXT(pair) = new_buck[hc];
|
|
|
|
new_buck[hc] = pair;
|
|
|
|
|
|
|
|
pair = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_freemem (htb->hio, htb->bucket);
|
2020-04-30 16:20:31 +00:00
|
|
|
htb->bucket = new_buck;
|
|
|
|
htb->capa = new_capa;
|
|
|
|
htb->threshold = htb->capa * htb->factor / 100;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* insert options */
|
|
|
|
#define UPSERT 1
|
|
|
|
#define UPDATE 2
|
|
|
|
#define ENSERT 3
|
|
|
|
#define INSERT 4
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
static HIO_INLINE pair_t* insert (hio_htb_t* htb, void* kptr, hio_oow_t klen, void* vptr, hio_oow_t vlen, int opt)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
pair_t* pair, * p, * prev, * next;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t hc;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
|
|
|
|
pair = htb->bucket[hc];
|
2021-07-22 07:30:20 +00:00
|
|
|
prev = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
while (pair != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
next = NEXT(pair);
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* found a pair with a matching key */
|
|
|
|
switch (opt)
|
|
|
|
{
|
|
|
|
case UPSERT:
|
|
|
|
case UPDATE:
|
|
|
|
p = change_pair_val (htb, pair, vptr, vlen);
|
2023-01-11 14:59:41 +00:00
|
|
|
if (p == HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* error in changing the value */
|
2023-01-11 14:59:41 +00:00
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
2023-01-11 14:59:41 +00:00
|
|
|
if (p != pair)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* old pair destroyed. new pair reallocated.
|
|
|
|
* relink to include the new pair but to drop
|
|
|
|
* the old pair. */
|
2021-07-22 07:30:20 +00:00
|
|
|
if (prev == HIO_NULL) htb->bucket[hc] = p;
|
2020-04-30 16:20:31 +00:00
|
|
|
else NEXT(prev) = p;
|
2023-01-11 14:59:41 +00:00
|
|
|
NEXT(p) = next;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
return p;
|
|
|
|
|
|
|
|
case ENSERT:
|
|
|
|
/* return existing pair */
|
2023-01-11 14:59:41 +00:00
|
|
|
return pair;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
case INSERT:
|
|
|
|
/* return failure */
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_seterrnum (htb->hio, HIO_EEXIST);
|
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = pair;
|
|
|
|
pair = next;
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
if (opt == UPDATE)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_seterrnum (htb->hio, HIO_ENOENT);
|
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (htb->threshold > 0 && htb->size >= htb->threshold)
|
|
|
|
{
|
|
|
|
/* ingore reorganization error as it simply means
|
|
|
|
* more bucket collision and performance penalty. */
|
2023-01-11 14:59:41 +00:00
|
|
|
if (reorganize(htb) == 0)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_ASSERT (htb->hio, pair == HIO_NULL);
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair = hio_htb_allocpair (htb, kptr, klen, vptr, vlen);
|
|
|
|
if (HIO_UNLIKELY(!pair)) return HIO_NULL; /* error */
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
NEXT(pair) = htb->bucket[hc];
|
|
|
|
htb->bucket[hc] = pair;
|
|
|
|
htb->size++;
|
|
|
|
|
|
|
|
return pair; /* new key added */
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair_t* hio_htb_upsert (hio_htb_t* htb, void* kptr, hio_oow_t klen, void* vptr, hio_oow_t vlen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
return insert (htb, kptr, klen, vptr, vlen, UPSERT);
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair_t* hio_htb_ensert (hio_htb_t* htb, void* kptr, hio_oow_t klen, void* vptr, hio_oow_t vlen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
return insert (htb, kptr, klen, vptr, vlen, ENSERT);
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair_t* hio_htb_insert (hio_htb_t* htb, void* kptr, hio_oow_t klen, void* vptr, hio_oow_t vlen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
return insert (htb, kptr, klen, vptr, vlen, INSERT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair_t* hio_htb_update (hio_htb_t* htb, void* kptr, hio_oow_t klen, void* vptr, hio_oow_t vlen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
return insert (htb, kptr, klen, vptr, vlen, UPDATE);
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair_t* hio_htb_cbsert (hio_htb_t* htb, void* kptr, hio_oow_t klen, cbserter_t cbserter, void* ctx)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
pair_t* pair, * p, * prev, * next;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t hc;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
|
|
|
|
pair = htb->bucket[hc];
|
2021-07-22 07:30:20 +00:00
|
|
|
prev = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
while (pair != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
next = NEXT(pair);
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
if (htb->style->comper(htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* found a pair with a matching key */
|
|
|
|
p = cbserter(htb, pair, kptr, klen, ctx);
|
2023-01-11 14:59:41 +00:00
|
|
|
if (p == HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* error returned by the callback function */
|
2023-01-11 14:59:41 +00:00
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
2023-01-11 14:59:41 +00:00
|
|
|
if (p != pair)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* old pair destroyed. new pair reallocated.
|
|
|
|
* relink to include the new pair but to drop
|
|
|
|
* the old pair. */
|
2021-07-22 07:30:20 +00:00
|
|
|
if (prev == HIO_NULL) htb->bucket[hc] = p;
|
2020-04-30 16:20:31 +00:00
|
|
|
else NEXT(prev) = p;
|
2023-01-11 14:59:41 +00:00
|
|
|
NEXT(p) = next;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = pair;
|
|
|
|
pair = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (htb->threshold > 0 && htb->size >= htb->threshold)
|
|
|
|
{
|
|
|
|
/* ingore reorganization error as it simply means
|
|
|
|
* more bucket collision and performance penalty. */
|
|
|
|
if (reorganize(htb) == 0)
|
|
|
|
{
|
|
|
|
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
HIO_ASSERT (htb->hio, pair == HIO_NULL);
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair = cbserter(htb, HIO_NULL, kptr, klen, ctx);
|
|
|
|
if (HIO_UNLIKELY(!pair)) return HIO_NULL; /* error */
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
NEXT(pair) = htb->bucket[hc];
|
|
|
|
htb->bucket[hc] = pair;
|
|
|
|
htb->size++;
|
|
|
|
|
|
|
|
return pair; /* new key added */
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
int hio_htb_delete (hio_htb_t* htb, const void* kptr, hio_oow_t klen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
pair_t* pair, * prev;
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t hc;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
|
|
|
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
|
|
|
|
pair = htb->bucket[hc];
|
2021-07-22 07:30:20 +00:00
|
|
|
prev = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
while (pair != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2023-01-11 14:59:41 +00:00
|
|
|
if (htb->style->comper(htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2023-01-11 14:59:41 +00:00
|
|
|
if (prev == HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
htb->bucket[hc] = NEXT(pair);
|
|
|
|
else NEXT(prev) = NEXT(pair);
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_htb_freepair (htb, pair);
|
2020-04-30 16:20:31 +00:00
|
|
|
htb->size--;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = pair;
|
|
|
|
pair = NEXT(pair);
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_seterrnum (htb->hio, HIO_ENOENT);
|
2020-04-30 16:20:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
void hio_htb_clear (hio_htb_t* htb)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t i;
|
2020-04-30 16:20:31 +00:00
|
|
|
pair_t* pair, * next;
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
for (i = 0; i < htb->capa; i++)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
pair = htb->bucket[i];
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
while (pair != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
next = NEXT(pair);
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_htb_freepair (htb, pair);
|
2020-04-30 16:20:31 +00:00
|
|
|
htb->size--;
|
|
|
|
pair = next;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
htb->bucket[i] = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
void hio_htb_walk (hio_htb_t* htb, walker_t walker, void* ctx)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t i;
|
2020-04-30 16:20:31 +00:00
|
|
|
pair_t* pair, * next;
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
for (i = 0; i < htb->capa; i++)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
pair = htb->bucket[i];
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
while (pair != HIO_NULL)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
next = NEXT(pair);
|
2021-07-22 07:30:20 +00:00
|
|
|
if (walker(htb, pair, ctx) == HIO_HTB_WALK_STOP) return;
|
2020-04-30 16:20:31 +00:00
|
|
|
pair = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
void hio_init_htb_itr (hio_htb_itr_t* itr)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
itr->pair = HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
itr->buckno = 0;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair_t* hio_htb_getfirstpair (hio_htb_t* htb, hio_htb_itr_t* itr)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t i;
|
2020-04-30 16:20:31 +00:00
|
|
|
pair_t* pair;
|
|
|
|
|
|
|
|
for (i = 0; i < htb->capa; i++)
|
|
|
|
{
|
|
|
|
pair = htb->bucket[i];
|
2023-01-11 14:59:41 +00:00
|
|
|
if (pair)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
itr->buckno = i;
|
|
|
|
itr->pair = pair;
|
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
pair_t* hio_htb_getnextpair (hio_htb_t* htb, hio_htb_itr_t* itr)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t i;
|
2020-04-30 16:20:31 +00:00
|
|
|
pair_t* pair;
|
|
|
|
|
|
|
|
pair = NEXT(itr->pair);
|
2023-01-11 14:59:41 +00:00
|
|
|
if (pair)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
/* no change in bucket number */
|
|
|
|
itr->pair = pair;
|
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = itr->buckno + 1; i < htb->capa; i++)
|
|
|
|
{
|
|
|
|
pair = htb->bucket[i];
|
2023-01-11 14:59:41 +00:00
|
|
|
if (pair)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
|
|
|
itr->buckno = i;
|
|
|
|
itr->pair = pair;
|
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
return HIO_NULL;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t hio_htb_dflhash (const hio_htb_t* htb, const void* kptr, hio_oow_t klen)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
hio_oow_t h;
|
|
|
|
HIO_HASH_BYTES (h, kptr, klen);
|
2023-01-11 14:59:41 +00:00
|
|
|
return h ;
|
2020-04-30 16:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:30:20 +00:00
|
|
|
int hio_htb_dflcomp (const hio_htb_t* htb, const void* kptr1, hio_oow_t klen1, const void* kptr2, hio_oow_t klen2)
|
2020-04-30 16:20:31 +00:00
|
|
|
{
|
2021-07-22 07:30:20 +00:00
|
|
|
if (klen1 == klen2) return HIO_MEMCMP (kptr1, kptr2, KTOB(htb,klen1));
|
2020-04-30 16:20:31 +00:00
|
|
|
/* it just returns 1 to indicate that they are different. */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|