diff options
Diffstat (limited to 'ctrl/facemgr/src/util/set.h')
-rw-r--r-- | ctrl/facemgr/src/util/set.h | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/ctrl/facemgr/src/util/set.h b/ctrl/facemgr/src/util/set.h index 61df209ab..0dad17423 100644 --- a/ctrl/facemgr/src/util/set.h +++ b/ctrl/facemgr/src/util/set.h @@ -24,7 +24,6 @@ //#else #define thread_local _Thread_local //#endif /* ! __ANDROID__ */ -#include "../common.h" #define ERR_SET_EXISTS -2 #define ERR_SET_NOT_FOUND -3 @@ -34,6 +33,13 @@ static inline int +int_cmp(const int x, const int y) +{ + return x - y; +} + +static inline +int int_snprintf(char * buf, size_t size, int value) { return snprintf(buf, size, "%d", value); } @@ -50,6 +56,8 @@ generic_snprintf(char * buf, size_t size, const void * value) { return snprintf(buf, BUFSIZE, "%p", value); } +typedef int(*cmp_t)(const void * x, const void * y); + #define TYPEDEF_SET_H(NAME, T) \ \ typedef struct { \ @@ -87,8 +95,33 @@ NAME ## _initialize(NAME ## _t * set) \ return 0; \ } \ \ -NO_FINALIZE(NAME); \ -AUTOGENERATE_CREATE_FREE(NAME); \ +int \ +NAME ## _finalize(NAME ## _t * set) { return 0; } \ + \ +NAME ## _t * \ +NAME ## _create() \ +{ \ + NAME ## _t * set = malloc(sizeof(NAME ## _t)); \ + if (!set) \ + goto ERR_MALLOC; \ + \ + if (NAME ## _initialize(set) < 0) \ + goto ERR_INITIALIZE; \ + \ + return set; \ + \ +ERR_INITIALIZE: \ + free(set); \ +ERR_MALLOC: \ + return NULL; \ +} \ + \ +void \ +NAME ## _free(NAME ## _t * set) \ +{ \ + NAME ## _finalize(set); \ + free(set); \ +} \ \ int \ NAME ## _add(NAME ## _t * set, const T element) \ |