Inital commit.
FossilOrigin-Name: a900bac6da52d3267ac5e6610c80141e8d3f7bda8df5f310c72c7571c927bbd6
This commit is contained in:
parent
a3f9db9d46
commit
ab8128a20f
37
src/capwap/strheap.c
Normal file
37
src/capwap/strheap.c
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
#include "strheap.h"
|
||||
|
||||
|
||||
static int cmp(const void *v1,const void*v2)
|
||||
{
|
||||
return ((struct cw_str *)v1)->id - ((struct cw_str *)v2)->id;
|
||||
}
|
||||
|
||||
static void del(void* d)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cw_strheap_t cw_strheap_create()
|
||||
{
|
||||
return avltree_create(cmp,del);
|
||||
}
|
||||
|
||||
const char * cw_strheap_add(cw_strheap_t t, struct cw_str *s)
|
||||
{
|
||||
avltree_del(t,s);
|
||||
return avltree_add(t,s);
|
||||
}
|
||||
|
||||
int cw_strheap_register_strings(cw_strheap_t h, struct cw_str *s)
|
||||
{
|
||||
int n=0;
|
||||
while ( s->id!=0){
|
||||
cw_strheap_add(h,s);
|
||||
s++;
|
||||
n++;
|
||||
}
|
||||
cw_strheap_add(h,s);
|
||||
return n+1;
|
||||
}
|
||||
|
30
src/capwap/strheap.h
Normal file
30
src/capwap/strheap.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef __STRHEAP_H
|
||||
#define __STRHEAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "avltree.h"
|
||||
|
||||
|
||||
typedef struct avltree * cw_strheap_t;
|
||||
|
||||
struct cw_str {
|
||||
uint32_t id;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
extern cw_strheap_t cw_strheap_create();
|
||||
extern int cw_strheap_register_strings(cw_strheap_t h, struct cw_str *s);
|
||||
|
||||
static inline const char * cw_strheap_get(cw_strheap_t h, int id) {
|
||||
struct cw_str s, *rc;
|
||||
s.id=id;
|
||||
rc = avltree_get(h,&s);
|
||||
if (rc)
|
||||
return rc->str;
|
||||
return cw_strheap_get(h,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user