array: add a set of useful functions

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-09 17:16:39 +02:00
parent e145afec53
commit 87c3c02b72
1 changed files with 13 additions and 0 deletions

View File

@ -77,6 +77,19 @@
pfx##_array_splice(arr, pos, 1, NULL, 0); \ pfx##_array_splice(arr, pos, 1, NULL, 0); \
return res; \ return res; \
} \ } \
static inline int pfx##_array_indexof(pfx##_array_t *arr, type_t *e) \
{ \
return e - arr->tab; \
} \
static inline type_t pfx##_array_remove(pfx##_array_t *arr, type_t *e) \
{ \
return pfx##_array_take(arr, pfx##_array_indexof(arr, e)); \
} \
static inline void \
pfx##_array_push(pfx##_array_t *arr, type_t e) \
{ \
pfx##_array_splice(arr, 0, 0, &e, 1); \
} \
static inline void pfx##_array_append(pfx##_array_t *arr, type_t e) { \ static inline void pfx##_array_append(pfx##_array_t *arr, type_t e) { \
pfx##_array_splice(arr, arr->len, 0, &e, 1); \ pfx##_array_splice(arr, arr->len, 0, &e, 1); \
} }