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