simclist.h

Go to the documentation of this file.
00001 
00002 #ifndef SIMCLIST_H
00003 #define SIMCLIST_H
00004 
00005 #ifdef __cplusplus
00006 extern "C" {
00007 #endif
00008 
00009 #include <inttypes.h>
00010 #include <errno.h>
00011 #include <sys/types.h>
00012 
00018 typedef int32_t list_hash_t;
00019 
00020 typedef struct {
00021     uint16_t version;       /* dump version */
00022     int64_t timestamp;      /* when the list has been dumped, microseconds from UNIX epoch */
00023     uint32_t list_size;
00024     uint32_t list_numels;
00025     list_hash_t list_hash;       /* hash of the list when dumped, or 0 if invalid */
00026     uint32_t dumpsize;
00027     int consistent;         /* 1 if the dump is verified complete/consistent; 0 otherwise */
00028 } list_dump_info_t;
00029 
00039 typedef int (*element_comparator)(const void *a, const void *b);
00040 
00052 typedef int (*element_seeker)(const void *el, const void *indicator);
00053 
00063 typedef size_t (*element_meter)(const void *el);
00064 
00074 typedef list_hash_t (*element_hash_computer)(const void *el);
00075 
00094 typedef void *(*element_serializer)(const void *restrict el, uint32_t *restrict serializ_len);
00095 
00111 typedef void *(*element_unserializer)(const void *restrict data, uint32_t *restrict data_len);
00112 
00113 /* [private-use] list entry -- olds actual user datum */
00114 struct list_entry_s {
00115     void *data;
00116 
00117     /* doubly-linked list service references */
00118     struct list_entry_s *next;
00119     struct list_entry_s *prev;
00120 };
00121 
00122 /* [private-use] list attributes */
00123 struct list_attributes_s {
00124     /* user-set routine for comparing list elements */
00125     element_comparator comparator;
00126     /* user-set routing for seeking elements */
00127     element_seeker seeker;
00128     /* user-set routine for determining the length of an element */
00129     element_meter meter;
00130     int copy_data;
00131     /* user-set routine for computing the hash of an element */
00132     element_hash_computer hasher;
00133     /* user-set routine for serializing an element */
00134     element_serializer serializer;
00135     /* user-set routine for unserializing an element */
00136     element_unserializer unserializer;
00137 };
00138 
00140 typedef struct {
00141     struct list_entry_s *head_sentinel;
00142     struct list_entry_s *tail_sentinel;
00143     struct list_entry_s *mid;
00144 
00145     unsigned int numels;
00146 
00147     /* array of spare elements */
00148     struct list_entry_s **spareels;
00149     unsigned int spareelsnum;
00150 
00151 #ifdef SIMCLIST_WITH_THREADS
00152     /* how many threads are currently running */
00153     unsigned int threadcount;
00154 #endif
00155 
00156     /* service variables for list iteration */
00157     int iter_active;
00158     unsigned int iter_pos;
00159     struct list_entry_s *iter_curentry;
00160 
00161     /* list attributes */
00162     struct list_attributes_s attrs;
00163 } list_t;
00164 
00171 int list_init(list_t *restrict l);
00172 
00182 void list_destroy(list_t *restrict l);
00183 
00196 int list_attributes_comparator(list_t *restrict l, element_comparator comparator_fun);
00197 
00210 int list_attributes_seeker(list_t *restrict l, element_seeker seeker_fun);
00211 
00242 int list_attributes_copy(list_t *restrict l, element_meter metric_fun, int copy_data);
00243 
00262 int list_attributes_hash_computer(list_t *restrict l, element_hash_computer hash_computer_fun);
00263 
00283 int list_attributes_serializer(list_t *restrict l, element_serializer serializer_fun);
00284 
00305 int list_attributes_unserializer(list_t *restrict l, element_unserializer unserializer_fun);
00306 
00317 int list_append(list_t *restrict l, const void *data);
00318 
00329 int list_prepend(list_t *restrict l, const void *restrict data);
00330 
00339 void *list_fetch(list_t *restrict l);
00340 
00348 void *list_get_at(const list_t *restrict l, unsigned int pos);
00349 
00362 void *list_get_max(const list_t *restrict l);
00363 
00376 void *list_get_min(const list_t *restrict l);
00377 
00385 void *list_extract_at(list_t *restrict l, unsigned int pos);
00386 
00395 int list_insert_at(list_t *restrict l, const void *data, unsigned int pos);
00396 
00404 int list_delete_at(list_t *restrict l, unsigned int pos);
00405 
00414 int list_delete_range(list_t *restrict l, unsigned int posstart, unsigned int posend);
00415 
00427 int list_clear(list_t *restrict l);
00428 
00435 unsigned int list_size(const list_t *restrict l);
00436 
00445 int list_empty(const list_t *restrict l);
00446 
00464 int list_locate(const list_t *restrict l, const void *data);
00465 
00479 void *list_seek(list_t *restrict l, const void *indicator);
00480 
00500 int list_contains(const list_t *restrict l, const void *data);
00501 
00519 int list_concat(const list_t *l1, const list_t *l2, list_t *restrict dest);
00520 
00536 int list_sort(list_t *restrict l, int versus);
00537 
00548 int list_iterator_start(list_t *restrict l);
00549 
00556 void *list_iterator_next(list_t *restrict l);
00557 
00564 int list_iterator_hasnext(const list_t *restrict l);
00565 
00572 int list_iterator_stop(list_t *restrict l);
00573 
00580 list_hash_t list_hash(const list_t *restrict l);
00581 
00597 int list_dump_getinfo_filedescriptor(int fd, list_dump_info_t *restrict info);
00598 
00612 int list_dump_getinfo_file(const char *restrict filename, list_dump_info_t *restrict info);
00613 
00648 int list_dump_filedescriptor(const list_t *restrict l, int fd, size_t *restrict len);
00649 
00671 int list_dump_file(const list_t *restrict l, const char *restrict filename, size_t *restrict len);
00672 
00691 int list_restore_filedescriptor(list_t *restrict l, int fd, size_t *restrict len);
00692 
00709 int list_restore_file(list_t *restrict l, const char *restrict filename, size_t *len);
00710 
00711 /* ready-made comparators, meters and hash computers */
00712                                 /* comparator functions */
00717 int list_comparator_int8_t(const void *a, const void *b);
00718 
00723 int list_comparator_int16_t(const void *a, const void *b);
00724 
00729 int list_comparator_int32_t(const void *a, const void *b);
00730 
00735 int list_comparator_int64_t(const void *a, const void *b);
00736 
00741 int list_comparator_uint8_t(const void *a, const void *b);
00742 
00747 int list_comparator_uint16_t(const void *a, const void *b);
00748 
00753 int list_comparator_uint32_t(const void *a, const void *b);
00754 
00759 int list_comparator_uint64_t(const void *a, const void *b);
00760 
00765 int list_comparator_float(const void *a, const void *b);
00766 
00771 int list_comparator_double(const void *a, const void *b);
00772 
00777 int list_comparator_string(const void *a, const void *b);
00778 
00779                                 /*          metric functions        */
00784 size_t list_meter_int8_t(const void *el);
00785 
00790 size_t list_meter_int16_t(const void *el);
00791 
00796 size_t list_meter_int32_t(const void *el);
00797 
00802 size_t list_meter_int64_t(const void *el);
00803 
00808 size_t list_meter_uint8_t(const void *el);
00809 
00814 size_t list_meter_uint16_t(const void *el);
00815 
00820 size_t list_meter_uint32_t(const void *el);
00821 
00826 size_t list_meter_uint64_t(const void *el);
00827 
00832 size_t list_meter_float(const void *el);
00833 
00838 size_t list_meter_double(const void *el);
00839 
00844 size_t list_meter_string(const void *el);
00845 
00846                                 /*          hash functions          */
00851 list_hash_t list_hashcomputer_int8_t(const void *el);
00852 
00857 list_hash_t list_hashcomputer_int16_t(const void *el);
00858 
00863 list_hash_t list_hashcomputer_int32_t(const void *el);
00864 
00869 list_hash_t list_hashcomputer_int64_t(const void *el);
00870 
00875 list_hash_t list_hashcomputer_uint8_t(const void *el);
00876 
00881 list_hash_t list_hashcomputer_uint16_t(const void *el);
00882 
00887 list_hash_t list_hashcomputer_uint32_t(const void *el);
00888 
00893 list_hash_t list_hashcomputer_uint64_t(const void *el);
00894 
00899 list_hash_t list_hashcomputer_float(const void *el);
00900 
00905 list_hash_t list_hashcomputer_double(const void *el);
00906 
00911 list_hash_t list_hashcomputer_string(const void *el);
00912 
00913 #ifdef __cplusplus
00914 }
00915 #endif
00916 
00917 #endif
00918 

Generated on Tue Dec 2 16:01:42 2008 for simclist by  doxygen 1.5.7