00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00037 #ifndef _DSLIB_H
00038 #define _DSLIB_H
00039
00040 typedef struct list_t list_t;
00041 typedef struct list_array_t list_array_t;
00042 typedef struct list_linked_element_t list_linked_element_t;
00043 typedef struct list_linked_t list_linked_t;
00044 typedef struct table_t table_t;
00045
00046 #include "bstr.h"
00047
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051
00052
00053
00054
00055
00056
00057
00058 #define list_push(L, E) (L)->push(L, E)
00059 #define list_pop(L) (L)->pop(L)
00060 #define list_empty(L) (L)->empty(L)
00061 #define list_get(L, N) (L)->get((list_t *)L, N)
00062 #define list_replace(L, N, E) (L)->replace((list_t *)L, N, E)
00063 #define list_add(L, N) (L)->push(L, N)
00064 #define list_size(L) (L)->size(L)
00065 #define list_iterator_reset(L) (L)->iterator_reset(L)
00066 #define list_iterator_next(L) (L)->iterator_next(L)
00067 #define list_destroy(L) (*(L))->destroy(L)
00068 #define list_shift(L) (L)->shift(L)
00069
00070 #define LIST_COMMON \
00071 int (*push)(list_t *, void *); \
00072 void *(*pop)(list_t *); \
00073 int (*empty)(const list_t *); \
00074 void *(*get)(const list_t *, size_t index); \
00075 int (*replace)(list_t *, size_t index, void *); \
00076 size_t (*size)(const list_t *); \
00077 void (*iterator_reset)(list_t *); \
00078 void *(*iterator_next)(list_t *); \
00079 void (*destroy)(list_t **); \
00080 void *(*shift)(list_t *)
00081
00082 struct list_t {
00083 LIST_COMMON;
00084 };
00085
00086 struct list_linked_element_t {
00087 void *data;
00088 list_linked_element_t *next;
00089 };
00090
00091 struct list_linked_t {
00092 LIST_COMMON;
00093
00094 list_linked_element_t *first;
00095 list_linked_element_t *last;
00096 };
00097
00098 struct list_array_t {
00099 LIST_COMMON;
00100
00101 size_t first;
00102 size_t last;
00103 size_t max_size;
00104 size_t current_size;
00105 void **elements;
00106
00107 size_t iterator_index;
00108 };
00109
00110 list_t *list_linked_create(void);
00111 void list_linked_destroy(list_linked_t **_l);
00112
00113 list_t *list_array_create(size_t size);
00114 void list_array_iterator_reset(list_array_t *l);
00115 void *list_array_iterator_next(list_array_t *l);
00116 void list_array_destroy(list_array_t **_l);
00117
00118
00119
00120
00121 struct table_t {
00122 list_t *list;
00123 };
00124
00125 table_t *table_create(size_t size);
00126 int table_add(table_t *, bstr *, void *);
00127 int table_addn(table_t *, bstr *, void *);
00128 void table_set(table_t *, bstr *, void *);
00129 void *table_get(const table_t *, const bstr *);
00130 void *table_get_c(const table_t *, const char *);
00131 void table_iterator_reset(table_t *);
00132 bstr *table_iterator_next(table_t *, void **);
00133 size_t table_size(const table_t *t);
00134 void table_destroy(table_t **);
00135 void table_clear(table_t *);
00136
00137 #ifdef __cplusplus
00138 }
00139 #endif
00140
00141 #endif
00142