More WTP functions.

FossilOrigin-Name: d911169da02fad41102ebdbd34b7533d78a39bb3c452d4174269ba7e3c825c53
This commit is contained in:
7u83@mail.ru
2015-04-26 06:41:12 +00:00
parent f1feb4bc0d
commit 2ac7210734
28 changed files with 980 additions and 385 deletions

View File

@ -17,8 +17,6 @@ const struct mbag_typedef mbag_type_const_data = {
NULL
};
const struct mbag_typedef mbag_type_bstr = {
free
};
@ -77,6 +75,21 @@ static void mbag_del_fun(void *e)
}
static void strmbag_del_fun(void *e)
{
mbag_del_data(e);
free(e);
}
static int strmbag_cmp_fun(const void *x1, const void *x2)
{
return strcmp(( (struct mbag_item *) x1)->name , ((struct mbag_item *) x2)->name );
}
static int mbag_cmp_fun(const void *x1, const void *x2)
{
return ((struct mbag_item *) x1)->id - ((struct mbag_item *) x2)->id;
@ -87,11 +100,19 @@ mbag_t mbag_create()
return mavl_create(mbag_cmp_fun, mbag_del_fun);
}
mbag_t strmbag_create()
{
return mavl_create(strmbag_cmp_fun, strmbag_del_fun);
}
struct mbag_item *mbag_item_create(mbag_t s, uint32_t id)
{
struct mbag_item is;
is.id = id;
struct mbag_item *i = mavl_get(s, &is);
if (i) {
mbag_del_data(i);
@ -106,5 +127,23 @@ struct mbag_item *mbag_item_create(mbag_t s, uint32_t id)
}
struct mbag_item *strmbag_item_create(mbag_t s, char *name)
{
struct mbag_item is;
is.name = name;
struct mbag_item *i = mavl_get(s, &is);
if (i) {
mbag_del_data(i);
return i;
}
i = malloc(sizeof(struct mbag_item));
if (!i)
return NULL;
i->name = name;
return mavl_add(s, i);
}