]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4util/include/slmap.h
update
[l4.git] / l4 / pkg / l4util / include / slmap.h
1 /**
2  * \file
3  * \brief Map implementation
4  */
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7  *               Ronald Aigner <ra3@os.inf.tu-dresden.de>
8  *     economic rights: Technische Universität Dresden (Germany)
9  * This file is part of TUD:OS and distributed under the terms of the
10  * GNU Lesser General Public License 2.1.
11  * Please see the COPYING-LGPL-2.1 file for details.
12  */
13 #ifndef SLMAP_H
14 #define SLMAP_H
15
16 #include <stdlib.h>
17
18 #include <l4/sys/compiler.h>
19
20 EXTERN_C_BEGIN
21
22 /*
23  * the map structure
24  *
25  * its basically a single linked list with a
26  * key and a data entry
27  */
28 typedef struct slmap_t
29 {
30   struct slmap_t* next;    /* pointer to next entry */
31   void *key;             /* the key of the map entry */
32   unsigned key_size;     /* the size of the key entry */
33   void *data;            /* the data of the map entry */
34 } slmap_t;
35
36 /*
37  * function prototypes
38  */
39
40 L4_CV slmap_t*
41 map_new_entry(void* key, unsigned key_size, void *data);
42
43 L4_CV slmap_t*
44 map_new_sentry(char* key, void* data);
45
46 L4_CV slmap_t*
47 map_append(slmap_t* list, slmap_t* new_entry);
48
49 L4_CV slmap_t*
50 map_remove(slmap_t* list, slmap_t* entry);
51
52 L4_CV void
53 map_free_entry(slmap_t** entry);
54
55 L4_CV slmap_t*
56 map_get_at(slmap_t* list, int n);
57
58 L4_CV slmap_t*
59 map_add(slmap_t* list, slmap_t* new_entry);
60
61 L4_CV void
62 map_insert_after(slmap_t* after, slmap_t* new_entry);
63
64 L4_CV slmap_t*
65 map_find(slmap_t* list, void* key, unsigned key_size);
66
67 L4_CV slmap_t*
68 map_sfind(slmap_t* list, const char* key);
69
70 /*
71  * implementatic of static inline
72  */
73
74 static inline unsigned char
75 map_is_empty(slmap_t* list)
76 {
77   return (list) ? 0 : 1;
78 }
79
80 static inline void
81 map_free(slmap_t **list)
82 {
83   while (*list)
84     *list = map_remove(*list, *list);
85 }
86
87 static inline int
88 map_elements(slmap_t* list)
89 {
90   register int n;
91   for (n=0; list; list=list->next) 
92       n++;
93   return n;
94 }
95
96 EXTERN_C_END
97
98 #endif /* SLMAP_H */
99