35static inline void *
realloc_down(
void *ptr,
size_t size )
37 void *ret = realloc( ptr, size );
38 return ret ? ret : ptr;
50 void *n = realloc(
p,sz);
56#define TAB_INIT( count, tab ) \
62#define TAB_CLEAN( count, tab ) \
69#define TAB_APPEND_CAST( cast, count, tab, p ) \
72 (tab) = cast realloc( tab, sizeof( *(tab) ) * ( (count) + 1 ) ); \
74 (tab) = cast malloc( sizeof( *(tab) ) ); \
75 if( !(tab) ) abort(); \
80#define TAB_APPEND( count, tab, p ) \
81 TAB_APPEND_CAST( , count, tab, p )
83#define TAB_FIND( count, tab, p, idx ) \
85 for( (idx) = 0; (idx) < (count); (idx)++ ) \
86 if( (tab)[(idx)] == (p) ) \
88 if( (idx) >= (count) ) \
93#define TAB_ERASE( count, tab, index ) \
96 memmove( (tab) + (index), \
97 (tab) + (index) + 1, \
98 ((count) - (index) - 1 ) * sizeof( *(tab) ) );\
107#define TAB_REMOVE( count, tab, p ) \
110 TAB_FIND( count, tab, p, i_index ); \
112 TAB_ERASE( count, tab, i_index ); \
115#define TAB_INSERT_CAST( cast, count, tab, p, index ) do { \
117 (tab) = cast realloc( tab, sizeof( *(tab) ) * ( (count) + 1 ) ); \
119 (tab) = cast malloc( sizeof( *(tab) ) ); \
120 if( !(tab) ) abort(); \
121 if( (count) - (index) > 0 ) \
122 memmove( (tab) + (index) + 1, \
124 ((count) - (index)) * sizeof( *(tab) ) );\
125 (tab)[(index)] = (p); \
129#define TAB_INSERT( count, tab, p, index ) \
130 TAB_INSERT_CAST( , count, tab, p, index )
141#define BSEARCH( entries, count, elem, zetype, key, answer ) \
143 int low = 0, high = count - 1; \
145 while( low <= high ) {\
146 int mid = ((unsigned int)low + (unsigned int)high) >> 1;\
147 zetype mid_val = entries[mid] elem;\
148 if( mid_val < key ) \
150 else if ( mid_val > key ) \
154 answer = mid; break; \
165#define _ARRAY_ALLOC(array, newsize) { \
166 (array).i_alloc = newsize; \
167 (array).p_elems = vlc_reallocarray( (array).p_elems, (array).i_alloc, \
168 sizeof(*(array).p_elems) ); \
169 if( !(array).p_elems ) abort(); \
172#define _ARRAY_GROW1(array) { \
173 if( (array).i_alloc < 10 ) \
174 _ARRAY_ALLOC(array, 10 ) \
175 else if( (array).i_alloc == (array).i_size ) \
176 _ARRAY_ALLOC(array, (int)((array).i_alloc * 1.5) ) \
180#define DECL_ARRAY(type) struct { \
186#define TYPEDEF_ARRAY(type, name) typedef DECL_ARRAY(type) name;
188#define ARRAY_INIT(array) \
190 (array).i_alloc = 0; \
191 (array).i_size = 0; \
192 (array).p_elems = NULL; \
195#define ARRAY_RESET(array) \
197 (array).i_alloc = 0; \
198 (array).i_size = 0; \
199 free( (array).p_elems ); (array).p_elems = NULL; \
202#define ARRAY_APPEND(array, elem) \
204 _ARRAY_GROW1(array); \
205 (array).p_elems[(array).i_size] = elem; \
209#define ARRAY_INSERT(array,elem,pos) \
211 _ARRAY_GROW1(array); \
212 if( (array).i_size - (pos) ) { \
213 memmove( (array).p_elems + (pos) + 1, (array).p_elems + (pos), \
214 ((array).i_size-(pos)) * sizeof(*(array).p_elems) ); \
216 (array).p_elems[pos] = elem; \
220#define _ARRAY_SHRINK(array) { \
221 if( (array).i_size > 10 && (array).i_size < (int)((array).i_alloc / 1.5) ) { \
222 _ARRAY_ALLOC(array, (array).i_size + 5); \
226#define ARRAY_FIND(array, p, idx) \
227 TAB_FIND((array).i_size, (array).p_elems, p, idx)
229#define ARRAY_REMOVE(array,pos) \
231 if( (array).i_size - (pos) - 1 ) \
233 memmove( (array).p_elems + (pos), (array).p_elems + (pos) + 1, \
234 ( (array).i_size - (pos) - 1 ) *sizeof(*(array).p_elems) );\
237 _ARRAY_SHRINK(array); \
240#define ARRAY_VAL(array, pos) array.p_elems[pos]
242#define ARRAY_BSEARCH(array, elem, zetype, key, answer) \
243 BSEARCH( (array).p_elems, (array).i_size, elem, zetype, key, answer)
247#define ARRAY_FOREACH(item, array) \
248 for (int array_index_##item = 0; \
249 array_index_##item < (array).i_size && \
250 ((item) = (array).p_elems[array_index_##item], 1); \
251 ++array_index_##item)
282# define vlc_array_item_at_index(ar, idx) \
284 const vlc_array_t *: ((ar)->pp_elems[idx]), \
285 vlc_array_t *: ((ar)->pp_elems[idx]))
302 for(
size_t i = 0; i < ar->
i_count; i++ )
313 void **pp = (
void **)realloc( ar->
pp_elems,
314 sizeof(
void * ) * (ar->
i_count + 1) );
318 size_t tail = ar->
i_count - idx;
320 memmove( pp + idx + 1, pp + idx,
sizeof(
void * ) * tail );
336 void **pp = (
void **)realloc( ar->
pp_elems,
337 sizeof(
void * ) * (ar->
i_count + 1) );
355 size_t tail = ar->
i_count - idx - 1;
358 memmove( pp + idx, pp + idx + 1,
sizeof(
void * ) * tail );
364 pp = (
void **)realloc( pp,
sizeof(
void * ) * ar->
i_count );
384static inline uint64_t
DictHash(
const char *psz_string,
int hashsize )
391 i_hash += *psz_string++;
392 i_hash += i_hash << 10;
393 i_hash ^= i_hash >> 8;
396 return i_hash % hashsize;
428 void ( * pf_free )(
void * p_data,
void * p_obj ),
433 for(
int i = 0; i < p_dict->
i_size; i++ )
439 p_next = p_current->
p_next;
440 if( pf_free != NULL )
441 ( * pf_free )( p_current->
p_value, p_obj );
461 for( ; p_entry != NULL; p_entry = p_entry->
p_next )
463 if( !strcmp( psz_key, p_entry->
psz_key ) )
466 return p_entry != NULL;
483 if( !strcmp( psz_key, p_entry->
psz_key ) )
485 p_entry = p_entry->
p_next;
500 for( i = 0; i < p_dict->
i_size; i++ )
511 for(
int i = 0; i < p_dict->
i_size; i++ )
524 ppsz_ret = (
char**)malloc(
sizeof(
char *) * (
count + 1));
529 for( i = 0; i < p_dict->
i_size; i++ )
531 for( p_entry = p_dict->
p_entries[i]; p_entry; p_entry = p_entry->
p_next )
534 ppsz_ret[
count] = NULL;
540 void * p_value,
bool rebuild )
558 p_entry = p_entry->
p_next;
563 int i_new_size = ( (p_dict->
i_size+2) * 3) / 2;
566 for( i = 0; i < p_dict->
i_size; i++ )
574 p_entry = p_entry->
p_next;
593 void ( * pf_free )(
void * p_data,
void * p_obj ),
609 if( !strcmp( psz_key, p_entry->
psz_key ) )
611 if( pf_free != NULL )
612 ( * pf_free )( p_entry->
p_value, p_obj );
622 p_entry = p_entry->
p_next;
631void vlc_delete_all( T &container )
633 typename T::iterator it = container.begin();
634 while ( it != container.end() )
size_t count
Definition core.c:403
#define unlikely(p)
Predicted false condition.
Definition vlc_common.h:246
#define likely(p)
Predicted true condition.
Definition vlc_common.h:237
Definition vlc_arrays.h:259
size_t i_count
Definition vlc_arrays.h:260
void ** pp_elems
Definition vlc_arrays.h:261
Definition vlc_arrays.h:401
void * p_value
Definition vlc_arrays.h:403
struct vlc_dictionary_entry_t * p_next
Definition vlc_arrays.h:404
char * psz_key
Definition vlc_arrays.h:402
Definition vlc_arrays.h:408
int i_size
Definition vlc_arrays.h:409
vlc_dictionary_entry_t ** p_entries
Definition vlc_arrays.h:410
static void * realloc_or_free(void *p, size_t sz)
This wrapper around realloc() will free the input pointer when realloc() returns NULL.
Definition vlc_arrays.h:49
static char ** vlc_dictionary_all_keys(const vlc_dictionary_t *p_dict)
Definition vlc_arrays.h:519
static int vlc_array_append(vlc_array_t *ar, void *elem)
Definition vlc_arrays.h:335
static void vlc_dictionary_remove_value_for_key(const vlc_dictionary_t *p_dict, const char *psz_key, void(*pf_free)(void *p_data, void *p_obj), void *p_obj)
Definition vlc_arrays.h:593
static void vlc_array_insert_or_abort(vlc_array_t *ar, void *elem, int idx)
Definition vlc_arrays.h:329
static void *const kVLCDictionaryNotFound
Definition vlc_arrays.h:413
static void * vlc_dictionary_value_for_key(const vlc_dictionary_t *p_dict, const char *psz_key)
Definition vlc_arrays.h:471
static void vlc_dictionary_clear(vlc_dictionary_t *p_dict, void(*pf_free)(void *p_data, void *p_obj), void *p_obj)
Definition vlc_arrays.h:428
static void vlc_array_init(vlc_array_t *p_array)
Definition vlc_arrays.h:264
static bool vlc_dictionary_is_empty(const vlc_dictionary_t *p_dict)
Definition vlc_arrays.h:509
static void vlc_array_clear(vlc_array_t *p_array)
Definition vlc_arrays.h:270
#define vlc_array_item_at_index(ar, idx)
Definition vlc_arrays.h:283
static void vlc_array_remove(vlc_array_t *ar, size_t idx)
Definition vlc_arrays.h:353
static void vlc_array_append_or_abort(vlc_array_t *ar, void *elem)
Definition vlc_arrays.h:347
static ssize_t vlc_array_index_of_item(const vlc_array_t *ar, const void *elem)
Definition vlc_arrays.h:300
static int vlc_dictionary_has_key(const vlc_dictionary_t *p_dict, const char *psz_key)
Definition vlc_arrays.h:455
static size_t vlc_array_count(const vlc_array_t *p_array)
Definition vlc_arrays.h:277
static int vlc_dictionary_keys_count(const vlc_dictionary_t *p_dict)
Definition vlc_arrays.h:493
static void * realloc_down(void *ptr, size_t size)
Definition vlc_arrays.h:36
static int vlc_array_insert(vlc_array_t *ar, void *elem, int idx)
Definition vlc_arrays.h:312
static void vlc_dictionary_init(vlc_dictionary_t *p_dict, int i_size)
Definition vlc_arrays.h:415
static void vlc_dictionary_insert_impl_(vlc_dictionary_t *p_dict, const char *psz_key, void *p_value, bool rebuild)
Definition vlc_arrays.h:540
static uint64_t DictHash(const char *psz_string, int hashsize)
Definition vlc_arrays.h:385
static void vlc_dictionary_insert(vlc_dictionary_t *p_dict, const char *psz_key, void *p_value)
Definition vlc_arrays.h:587
This file is a collection of common definitions and types.
char * strdup(const char *)