]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4util/include/slmap.h
c8a05665964d3bb82cc33fa829173201a56d64e0
[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 static inline void
56 map_free(slmap_t** list);
57
58 L4_CV static inline unsigned char
59 map_is_empty(slmap_t* list);
60
61 L4_CV slmap_t*
62 map_get_at(slmap_t* list, int n);
63
64 L4_CV slmap_t*
65 map_add(slmap_t* list, slmap_t* new_entry);
66
67 L4_CV void
68 map_insert_after(slmap_t* after, slmap_t* new_entry);
69
70 L4_CV static inline int
71 map_elements(slmap_t* list);
72
73 L4_CV slmap_t*
74 map_find(slmap_t* list, void* key, unsigned key_size);
75
76 L4_CV slmap_t*
77 map_sfind(slmap_t* list, const char* key);
78
79 /*
80  * implementatic of static inline
81  */
82
83 static inline unsigned char
84 map_is_empty(slmap_t* list)
85 {
86   return (list) ? 0 : 1;
87 }
88
89 static inline void
90 map_free(slmap_t **list)
91 {
92   while (*list)
93     *list = map_remove(*list, *list);
94 }
95
96 static inline int
97 map_elements(slmap_t* list)
98 {
99   register int n;
100   for (n=0; list; list=list->next) 
101       n++;
102   return n;
103 }
104
105 EXTERN_C_END
106
107 #endif /* SLMAP_H */
108