2015-04-05 20:27:02 +02:00
|
|
|
|
|
|
|
#include "strheap.h"
|
|
|
|
|
|
|
|
|
|
|
|
static int cmp(const void *v1,const void*v2)
|
|
|
|
{
|
2018-03-17 19:32:44 +01:00
|
|
|
return ((struct cw_StrListElem *)v1)->id - ((struct cw_StrListElem *)v2)->id;
|
2015-04-05 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void del(void* d)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cw_strheap_t cw_strheap_create()
|
|
|
|
{
|
2018-03-11 00:56:41 +01:00
|
|
|
return mavl_create(cmp,del,1312);
|
2015-04-05 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
const char * cw_strheap_add(cw_strheap_t t, struct cw_StrListElem *s)
|
2015-04-05 20:27:02 +02:00
|
|
|
{
|
2015-04-21 08:24:59 +02:00
|
|
|
mavl_del(t,s);
|
2022-07-18 01:15:17 +02:00
|
|
|
return mavl_insert(t,s,NULL);
|
2015-04-05 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
int cw_strheap_register_strings(cw_strheap_t h, struct cw_StrListElem *s)
|
2015-04-05 20:27:02 +02:00
|
|
|
{
|
|
|
|
int n=0;
|
2015-04-21 08:24:59 +02:00
|
|
|
while ( s->id!=CW_STR_STOP){
|
2015-04-05 20:27:02 +02:00
|
|
|
cw_strheap_add(h,s);
|
|
|
|
s++;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
cw_strheap_add(h,s);
|
|
|
|
return n+1;
|
|
|
|
}
|
|
|
|
|
2018-03-02 13:36:03 +01:00
|
|
|
|
|
|
|
const char * cw_strheap_get(cw_strheap_t h, int id) {
|
2018-03-25 10:07:39 +02:00
|
|
|
struct cw_StrListElem *r;
|
2018-03-17 19:32:44 +01:00
|
|
|
struct cw_StrListElem s;
|
2018-03-02 13:36:03 +01:00
|
|
|
s.id=id;
|
2018-03-25 10:07:39 +02:00
|
|
|
r = mavl_get(h,&s);
|
2018-03-02 13:36:03 +01:00
|
|
|
if (r)
|
|
|
|
return r->str;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|