8 /* Collection of primitive data structures that for some reason are still
9 * not available as C library. Since this is only a header file, all functions
10 * have to be defined as inline.
14 #define MD_DECL static inline
18 const char *key
; /* Needs to be first, so that strcmp() works */
25 struct MD_LUT_ENTRY
*start
;
29 MD_DECL int _md_lut_compare(struct MD_LUT_ENTRY *k1, struct MD_LUT_ENTRY *k2) {
30 return strcmp(k1->key, k2->key);
34 MD_DECL
struct MD_LUT_ENTRY
*md_lut_find(struct MD_LUT
*t
, const char *key
) {
35 struct MD_LUT_ENTRY ref
= {key
, NULL
};
37 return lfind(&ref
, t
->start
, &t
->n
, sizeof(struct MD_LUT_ENTRY
),
38 (int (*)(const void *, const void *)) strcmp
);
41 MD_DECL
void md_lut_insert(struct MD_LUT
*t
, const char *key
, void *data
) {
42 if (t
->n
== t
->size
) {
44 t
->start
= realloc(t
->start
, t
->size
* sizeof(*t
->start
));
47 t
->start
[t
->n
].key
= key
;
48 t
->start
[t
->n
].data
= data
;
52 MD_DECL
void md_lut_init(struct MD_LUT
*t
) {
55 t
->start
= malloc(8 * sizeof(*t
->start
));