From 87c3c02b727ca18dceeb33b0b00c2f911c47023b Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 9 Apr 2009 17:16:39 +0200 Subject: [PATCH] array: add a set of useful functions Signed-off-by: Julien Danjou --- common/array.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/array.h b/common/array.h index 39479017..edca49c3 100644 --- a/common/array.h +++ b/common/array.h @@ -77,6 +77,19 @@ pfx##_array_splice(arr, pos, 1, NULL, 0); \ 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) { \ pfx##_array_splice(arr, arr->len, 0, &e, 1); \ }