comparison array.h @ 92:4d723e81b685

Same thing for parray
author David Demelier <markand@malikania.fr>
date Tue, 03 Jan 2012 17:54:35 +0100
parents b3ba5f5df3b9
children 9ebea85c7765
comparison
equal deleted inserted replaced
91:b3ba5f5df3b9 92:4d723e81b685
39 void *data; /* array of data */ 39 void *data; /* array of data */
40 int length; /* number of element inside */ 40 int length; /* number of element inside */
41 size_t size; /* current buffer size (allocated memory) */ 41 size_t size; /* current buffer size (allocated memory) */
42 size_t unit; /* unit size (sizeof the object) */ 42 size_t unit; /* unit size (sizeof the object) */
43 int bsize; /* block size (used when growing array) */ 43 int bsize; /* block size (used when growing array) */
44 int i; /* only for ARRAY_FOREACH(_R) */ 44 int i; /* only for ARRAY_FOREACH */
45 45
46 /* Own alloc function */ 46 /* Own allocation functions */
47 void * (*malloc)(size_t); 47 void * (*malloc)(size_t);
48 void * (*realloc)(void *, size_t); 48 void * (*realloc)(void *, size_t);
49 }; 49 };
50 50
51 typedef void (*array_map_fn)(void *, void *); 51 typedef void (*array_map_fn)(void *, void *);
52 typedef int (*array_cmp_fn)(void *, void *); 52 typedef int (*array_cmp_fn)(void *, void *);
53 53
54 int array_new(struct array *, size_t); 54 int array_new(struct array *, size_t);
55 void array_set(struct array *arr, const char *fmt, ...); 55 void array_set(struct array *, const char *, ...);
56 int array_push(struct array *, const void *); 56 int array_push(struct array *, const void *);
57 int array_insert(struct array *, const void *, int); 57 int array_insert(struct array *, const void *, int);
58 int array_append(struct array *, const void *); 58 int array_append(struct array *, const void *);
59 void array_pop(struct array *); 59 void array_pop(struct array *);
60 void array_unqueue(struct array *); 60 void array_unqueue(struct array *);
61 void array_remove(struct array *, int); 61 void array_remove(struct array *, int);
62 void array_unref(struct array *, const void *); 62 void array_unref(struct array *, const void *);
63 int array_iswap(struct array *, int, int); 63 int array_iswap(struct array *, int, int);
64 int array_pswap(struct array *, const void *, const void *); 64 int array_pswap(struct array *, const void *, const void *);
65 void array_map(const struct array *, array_map_fn, void *); 65 void array_map(const struct array *, array_map_fn, void *);
66 int array_find(const struct array *, array_cmp_fn, void *, void *); 66 int array_find(const struct array *, array_cmp_fn, void *, void *);
67 void array_clear(struct array *); 67 void array_clear(struct array *);
68 void array_free(struct array *); 68 void array_free(struct array *);
69 69
70 #define ARRAY_HEAD(a, type) \ 70 #define ARRAY_HEAD(a, type) \
71 (((type *)a->data)[0]) 71 (((type *)a->data)[0])
72 #define ARRAY_TAIL(a, type) \ 72 #define ARRAY_TAIL(a, type) \
73 (((type *)a->data)[(a->length == 0) ? 0 : a->length - 1]) 73 (((type *)a->data)[(a->length == 0) ? 0 : a->length - 1])