Main Page   File List  

slmap.h

00001 #ifndef SLMAP_H
00002 #define SLMAP_H
00003 
00004 #include <stdlib.h>
00005 
00006 #include <l4/sys/compiler.h>
00007 
00008 EXTERN_C_BEGIN
00009 
00010 /*
00011  * the map structure
00012  *
00013  * its basically a single linked list with a
00014  * key and a data entry
00015  */
00016 typedef struct slmap_t
00017 {
00018   struct slmap_t* next;    /* pointer to next entry */
00019   void *key;             /* the key of the map entry */
00020   unsigned key_size;     /* the size of the key entry */
00021   void *data;            /* the data of the map entry */
00022 } slmap_t;
00023 
00024 /*
00025  * function prototypes
00026  */
00027 
00028 L4_CV slmap_t*
00029 map_new_entry(void* key, unsigned key_size, void *data);
00030 
00031 L4_CV slmap_t*
00032 map_new_sentry(char* key, void* data);
00033 
00034 L4_CV slmap_t*
00035 map_append(slmap_t* list, slmap_t* new_entry);
00036 
00037 L4_CV slmap_t*
00038 map_remove(slmap_t* list, slmap_t* entry);
00039 
00040 L4_CV void
00041 map_free_entry(slmap_t** entry);
00042 
00043 L4_CV static inline void
00044 map_free(slmap_t** list);
00045 
00046 L4_CV static inline unsigned char
00047 map_is_empty(slmap_t* list);
00048 
00049 L4_CV slmap_t*
00050 map_get_at(slmap_t* list, int n);
00051 
00052 L4_CV slmap_t*
00053 map_add(slmap_t* list, slmap_t* new_entry);
00054 
00055 L4_CV void
00056 map_insert_after(slmap_t* after, slmap_t* new_entry);
00057 
00058 L4_CV static inline int
00059 map_elements(slmap_t* list);
00060 
00061 L4_CV slmap_t*
00062 map_find(slmap_t* list, void* key, unsigned key_size);
00063 
00064 L4_CV slmap_t*
00065 map_sfind(slmap_t* list, const char* key);
00066 
00067 /*
00068  * implementatic of static inline
00069  */
00070 
00071 static inline unsigned char
00072 map_is_empty(slmap_t* list)
00073 {
00074   return (list) ? 0 : 1;
00075 }
00076 
00077 static inline void
00078 map_free(slmap_t **list)
00079 {
00080   while (*list)
00081     *list = map_remove(*list, *list);
00082 }
00083 
00084 static inline int
00085 map_elements(slmap_t* list)
00086 {
00087   register int n;
00088   for (n=0; list; list=list->next) 
00089       n++;
00090   return n;
00091 }
00092 
00093 EXTERN_C_END
00094 
00095 #endif /* SLMAP_H */
00096 

L4 Utilities, part of DROPS  © 2000-2003