00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SIMCLIST_H
00024 #define SIMCLIST_H
00025
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029
00030 #include <inttypes.h>
00031 #include <errno.h>
00032 #include <sys/types.h>
00033
00034
00035 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
00036
00037 #else
00038 # define inline
00039 # define restrict
00040 #endif
00041
00042
00048 typedef int32_t list_hash_t;
00049
00050 #ifndef SIMCLIST_NO_DUMPRESTORE
00051 typedef struct {
00052 uint16_t version;
00053 int64_t timestamp;
00054 uint32_t list_size;
00055 uint32_t list_numels;
00056 list_hash_t list_hash;
00057 uint32_t dumpsize;
00058 int consistent;
00059 } list_dump_info_t;
00060 #endif
00061
00071 typedef int (*element_comparator)(const void *a, const void *b);
00072
00084 typedef int (*element_seeker)(const void *el, const void *indicator);
00085
00095 typedef size_t (*element_meter)(const void *el);
00096
00106 typedef list_hash_t (*element_hash_computer)(const void *el);
00107
00126 typedef void *(*element_serializer)(const void *restrict el, uint32_t *restrict serializ_len);
00127
00143 typedef void *(*element_unserializer)(const void *restrict data, uint32_t *restrict data_len);
00144
00145
00146 struct list_entry_s {
00147 void *data;
00148
00149
00150 struct list_entry_s *next;
00151 struct list_entry_s *prev;
00152 };
00153
00154
00155 struct list_attributes_s {
00156
00157 element_comparator comparator;
00158
00159 element_seeker seeker;
00160
00161 element_meter meter;
00162 int copy_data;
00163
00164 element_hash_computer hasher;
00165
00166 element_serializer serializer;
00167
00168 element_unserializer unserializer;
00169 };
00170
00172 typedef struct {
00173 struct list_entry_s *head_sentinel;
00174 struct list_entry_s *tail_sentinel;
00175 struct list_entry_s *mid;
00176
00177 unsigned int numels;
00178
00179
00180 struct list_entry_s **spareels;
00181 unsigned int spareelsnum;
00182
00183 #ifdef SIMCLIST_WITH_THREADS
00184
00185 unsigned int threadcount;
00186 #endif
00187
00188
00189 int iter_active;
00190 unsigned int iter_pos;
00191 struct list_entry_s *iter_curentry;
00192
00193
00194 struct list_attributes_s attrs;
00195 } list_t;
00196
00203 int list_init(list_t *restrict l);
00204
00214 void list_destroy(list_t *restrict l);
00215
00228 int list_attributes_comparator(list_t *restrict l, element_comparator comparator_fun);
00229
00242 int list_attributes_seeker(list_t *restrict l, element_seeker seeker_fun);
00243
00274 int list_attributes_copy(list_t *restrict l, element_meter metric_fun, int copy_data);
00275
00294 int list_attributes_hash_computer(list_t *restrict l, element_hash_computer hash_computer_fun);
00295
00315 int list_attributes_serializer(list_t *restrict l, element_serializer serializer_fun);
00316
00337 int list_attributes_unserializer(list_t *restrict l, element_unserializer unserializer_fun);
00338
00349 int list_append(list_t *restrict l, const void *data);
00350
00361 int list_prepend(list_t *restrict l, const void *restrict data);
00362
00371 void *list_fetch(list_t *restrict l);
00372
00380 void *list_get_at(const list_t *restrict l, unsigned int pos);
00381
00394 void *list_get_max(const list_t *restrict l);
00395
00408 void *list_get_min(const list_t *restrict l);
00409
00417 void *list_extract_at(list_t *restrict l, unsigned int pos);
00418
00427 int list_insert_at(list_t *restrict l, const void *data, unsigned int pos);
00428
00443 int list_delete(list_t *restrict l, const void *data);
00444
00452 int list_delete_at(list_t *restrict l, unsigned int pos);
00453
00462 int list_delete_range(list_t *restrict l, unsigned int posstart, unsigned int posend);
00463
00475 int list_clear(list_t *restrict l);
00476
00483 unsigned int list_size(const list_t *restrict l);
00484
00493 int list_empty(const list_t *restrict l);
00494
00512 int list_locate(const list_t *restrict l, const void *data);
00513
00527 void *list_seek(list_t *restrict l, const void *indicator);
00528
00548 int list_contains(const list_t *restrict l, const void *data);
00549
00567 int list_concat(const list_t *l1, const list_t *l2, list_t *restrict dest);
00568
00584 int list_sort(list_t *restrict l, int versus);
00585
00596 int list_iterator_start(list_t *restrict l);
00597
00604 void *list_iterator_next(list_t *restrict l);
00605
00612 int list_iterator_hasnext(const list_t *restrict l);
00613
00620 int list_iterator_stop(list_t *restrict l);
00621
00630 int list_hash(const list_t *restrict l, list_hash_t *restrict hash);
00631
00632 #ifndef SIMCLIST_NO_DUMPRESTORE
00633
00648 int list_dump_getinfo_filedescriptor(int fd, list_dump_info_t *restrict info);
00649
00663 int list_dump_getinfo_file(const char *restrict filename, list_dump_info_t *restrict info);
00664
00699 int list_dump_filedescriptor(const list_t *restrict l, int fd, size_t *restrict len);
00700
00722 int list_dump_file(const list_t *restrict l, const char *restrict filename, size_t *restrict len);
00723
00742 int list_restore_filedescriptor(list_t *restrict l, int fd, size_t *restrict len);
00743
00760 int list_restore_file(list_t *restrict l, const char *restrict filename, size_t *len);
00761 #endif
00762
00763
00764
00769 int list_comparator_int8_t(const void *a, const void *b);
00770
00775 int list_comparator_int16_t(const void *a, const void *b);
00776
00781 int list_comparator_int32_t(const void *a, const void *b);
00782
00787 int list_comparator_int64_t(const void *a, const void *b);
00788
00793 int list_comparator_uint8_t(const void *a, const void *b);
00794
00799 int list_comparator_uint16_t(const void *a, const void *b);
00800
00805 int list_comparator_uint32_t(const void *a, const void *b);
00806
00811 int list_comparator_uint64_t(const void *a, const void *b);
00812
00817 int list_comparator_float(const void *a, const void *b);
00818
00823 int list_comparator_double(const void *a, const void *b);
00824
00829 int list_comparator_string(const void *a, const void *b);
00830
00831
00836 size_t list_meter_int8_t(const void *el);
00837
00842 size_t list_meter_int16_t(const void *el);
00843
00848 size_t list_meter_int32_t(const void *el);
00849
00854 size_t list_meter_int64_t(const void *el);
00855
00860 size_t list_meter_uint8_t(const void *el);
00861
00866 size_t list_meter_uint16_t(const void *el);
00867
00872 size_t list_meter_uint32_t(const void *el);
00873
00878 size_t list_meter_uint64_t(const void *el);
00879
00884 size_t list_meter_float(const void *el);
00885
00890 size_t list_meter_double(const void *el);
00891
00896 size_t list_meter_string(const void *el);
00897
00898
00903 list_hash_t list_hashcomputer_int8_t(const void *el);
00904
00909 list_hash_t list_hashcomputer_int16_t(const void *el);
00910
00915 list_hash_t list_hashcomputer_int32_t(const void *el);
00916
00921 list_hash_t list_hashcomputer_int64_t(const void *el);
00922
00927 list_hash_t list_hashcomputer_uint8_t(const void *el);
00928
00933 list_hash_t list_hashcomputer_uint16_t(const void *el);
00934
00939 list_hash_t list_hashcomputer_uint32_t(const void *el);
00940
00945 list_hash_t list_hashcomputer_uint64_t(const void *el);
00946
00951 list_hash_t list_hashcomputer_float(const void *el);
00952
00957 list_hash_t list_hashcomputer_double(const void *el);
00958
00963 list_hash_t list_hashcomputer_string(const void *el);
00964
00965 #ifdef __cplusplus
00966 }
00967 #endif
00968
00969 #endif
00970