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 __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
00436 int list_delete_at(list_t *restrict l, unsigned int pos);
00437
00446 int list_delete_range(list_t *restrict l, unsigned int posstart, unsigned int posend);
00447
00459 int list_clear(list_t *restrict l);
00460
00467 unsigned int list_size(const list_t *restrict l);
00468
00477 int list_empty(const list_t *restrict l);
00478
00496 int list_locate(const list_t *restrict l, const void *data);
00497
00511 void *list_seek(list_t *restrict l, const void *indicator);
00512
00532 int list_contains(const list_t *restrict l, const void *data);
00533
00551 int list_concat(const list_t *l1, const list_t *l2, list_t *restrict dest);
00552
00568 int list_sort(list_t *restrict l, int versus);
00569
00580 int list_iterator_start(list_t *restrict l);
00581
00588 void *list_iterator_next(list_t *restrict l);
00589
00596 int list_iterator_hasnext(const list_t *restrict l);
00597
00604 int list_iterator_stop(list_t *restrict l);
00605
00614 int list_hash(const list_t *restrict l, list_hash_t *restrict hash);
00615
00616 #ifndef SIMCLIST_NO_DUMPRESTORE
00617
00632 int list_dump_getinfo_filedescriptor(int fd, list_dump_info_t *restrict info);
00633
00647 int list_dump_getinfo_file(const char *restrict filename, list_dump_info_t *restrict info);
00648
00683 int list_dump_filedescriptor(const list_t *restrict l, int fd, size_t *restrict len);
00684
00706 int list_dump_file(const list_t *restrict l, const char *restrict filename, size_t *restrict len);
00707
00726 int list_restore_filedescriptor(list_t *restrict l, int fd, size_t *restrict len);
00727
00744 int list_restore_file(list_t *restrict l, const char *restrict filename, size_t *len);
00745 #endif
00746
00747
00748
00753 int list_comparator_int8_t(const void *a, const void *b);
00754
00759 int list_comparator_int16_t(const void *a, const void *b);
00760
00765 int list_comparator_int32_t(const void *a, const void *b);
00766
00771 int list_comparator_int64_t(const void *a, const void *b);
00772
00777 int list_comparator_uint8_t(const void *a, const void *b);
00778
00783 int list_comparator_uint16_t(const void *a, const void *b);
00784
00789 int list_comparator_uint32_t(const void *a, const void *b);
00790
00795 int list_comparator_uint64_t(const void *a, const void *b);
00796
00801 int list_comparator_float(const void *a, const void *b);
00802
00807 int list_comparator_double(const void *a, const void *b);
00808
00813 int list_comparator_string(const void *a, const void *b);
00814
00815
00820 size_t list_meter_int8_t(const void *el);
00821
00826 size_t list_meter_int16_t(const void *el);
00827
00832 size_t list_meter_int32_t(const void *el);
00833
00838 size_t list_meter_int64_t(const void *el);
00839
00844 size_t list_meter_uint8_t(const void *el);
00845
00850 size_t list_meter_uint16_t(const void *el);
00851
00856 size_t list_meter_uint32_t(const void *el);
00857
00862 size_t list_meter_uint64_t(const void *el);
00863
00868 size_t list_meter_float(const void *el);
00869
00874 size_t list_meter_double(const void *el);
00875
00880 size_t list_meter_string(const void *el);
00881
00882
00887 list_hash_t list_hashcomputer_int8_t(const void *el);
00888
00893 list_hash_t list_hashcomputer_int16_t(const void *el);
00894
00899 list_hash_t list_hashcomputer_int32_t(const void *el);
00900
00905 list_hash_t list_hashcomputer_int64_t(const void *el);
00906
00911 list_hash_t list_hashcomputer_uint8_t(const void *el);
00912
00917 list_hash_t list_hashcomputer_uint16_t(const void *el);
00918
00923 list_hash_t list_hashcomputer_uint32_t(const void *el);
00924
00929 list_hash_t list_hashcomputer_uint64_t(const void *el);
00930
00935 list_hash_t list_hashcomputer_float(const void *el);
00936
00941 list_hash_t list_hashcomputer_double(const void *el);
00942
00947 list_hash_t list_hashcomputer_string(const void *el);
00948
00949 #ifdef __cplusplus
00950 }
00951 #endif
00952
00953 #endif
00954