Go to the documentation of this file.
36 void *ret = realloc( ptr, size );
37 return ret ? ret : ptr;
40 #define TAB_INIT( count, tab ) \
46 #define TAB_CLEAN( count, tab ) \
53 #define TAB_APPEND_CAST( cast, count, tab, p ) \
56 (tab) = cast realloc( tab, sizeof( *(tab) ) * ( (count) + 1 ) ); \
58 (tab) = cast malloc( sizeof( *(tab) ) ); \
59 if( !(tab) ) abort(); \
64 #define TAB_APPEND( count, tab, p ) \
65 TAB_APPEND_CAST( , count, tab, p )
67 #define TAB_FIND( count, tab, p, idx ) \
69 for( (idx) = 0; (idx) < (count); (idx)++ ) \
70 if( (tab)[(idx)] == (p) ) \
72 if( (idx) >= (count) ) \
77 #define TAB_ERASE( count, tab, index ) \
80 memmove( (tab) + (index), \
81 (tab) + (index) + 1, \
82 ((count) - (index) - 1 ) * sizeof( *(tab) ) );\
91 #define TAB_REMOVE( count, tab, p ) \
94 TAB_FIND( count, tab, p, i_index ); \
96 TAB_ERASE( count, tab, i_index ); \
99 #define TAB_INSERT_CAST( cast, count, tab, p, index ) do { \
101 (tab) = cast realloc( tab, sizeof( *(tab) ) * ( (count) + 1 ) ); \
103 (tab) = cast malloc( sizeof( *(tab) ) ); \
104 if( !(tab) ) abort(); \
105 if( (count) - (index) > 0 ) \
106 memmove( (tab) + (index) + 1, \
108 ((count) - (index)) * sizeof( *(tab) ) );\
109 (tab)[(index)] = (p); \
113 #define TAB_INSERT( count, tab, p, index ) \
114 TAB_INSERT_CAST( , count, tab, p, index )
125 #define BSEARCH( entries, count, elem, zetype, key, answer ) \
127 int low = 0, high = count - 1; \
129 while( low <= high ) {\
130 int mid = ((unsigned int)low + (unsigned int)high) >> 1;\
131 zetype mid_val = entries[mid] elem;\
132 if( mid_val < key ) \
134 else if ( mid_val > key ) \
138 answer = mid; break; \
149 #define _ARRAY_ALLOC(array, newsize) { \
150 (array).i_alloc = newsize; \
151 (array).p_elems = realloc( (array).p_elems, (array).i_alloc * \
152 sizeof(*(array).p_elems) ); \
153 if( !(array).p_elems ) abort(); \
156 #define _ARRAY_GROW1(array) { \
157 if( (array).i_alloc < 10 ) \
158 _ARRAY_ALLOC(array, 10 ) \
159 else if( (array).i_alloc == (array).i_size ) \
160 _ARRAY_ALLOC(array, (int)((array).i_alloc * 1.5) ) \
163 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
166 #define DECL_ARRAY(type) struct { \
172 #define TYPEDEF_ARRAY(type, name) typedef DECL_ARRAY(type) name;
174 #define ARRAY_INIT(array) \
176 (array).i_alloc = 0; \
177 (array).i_size = 0; \
178 (array).p_elems = NULL; \
181 #define ARRAY_RESET(array) \
183 (array).i_alloc = 0; \
184 (array).i_size = 0; \
185 free( (array).p_elems ); (array).p_elems = NULL; \
188 #define ARRAY_APPEND(array, elem) \
190 _ARRAY_GROW1(array); \
191 (array).p_elems[(array).i_size] = elem; \
195 #define ARRAY_INSERT(array,elem,pos) \
197 _ARRAY_GROW1(array); \
198 if( (array).i_size - pos ) { \
199 memmove( (array).p_elems + pos + 1, (array).p_elems + pos, \
200 ((array).i_size-pos) * sizeof(*(array).p_elems) ); \
202 (array).p_elems[pos] = elem; \
206 #define _ARRAY_SHRINK(array) { \
207 if( (array).i_size > 10 && (array).i_size < (int)((array).i_alloc / 1.5) ) { \
208 _ARRAY_ALLOC(array, (array).i_size + 5); \
212 #define ARRAY_REMOVE(array,pos) \
214 if( (array).i_size - (pos) - 1 ) \
216 memmove( (array).p_elems + pos, (array).p_elems + pos + 1, \
217 ( (array).i_size - pos - 1 ) *sizeof(*(array).p_elems) ); \
220 _ARRAY_SHRINK(array); \
223 #define ARRAY_VAL(array, pos) array.p_elems[pos]
225 #define ARRAY_BSEARCH(array, elem, zetype, key, answer) \
226 BSEARCH( (array).p_elems, (array).i_size, elem, zetype, key, answer)
228 #define FOREACH_ARRAY( item, array ) { \
230 for( fe_idx = 0 ; fe_idx < (array).i_size ; fe_idx++ ) \
232 item = (array).p_elems[fe_idx];
234 #define FOREACH_END() } }
265 # define vlc_array_item_at_index(ar, idx) \
267 const vlc_array_t *: ((ar)->pp_elems[idx]), \
268 vlc_array_t *: ((ar)->pp_elems[idx]))
285 for(
size_t i = 0; i < ar->
i_count; i++ )
296 void **pp = (
void **)realloc( ar->
pp_elems,
297 sizeof(
void * ) * (ar->
i_count + 1) );
301 size_t tail = ar->
i_count - idx;
303 memmove( pp + idx + 1, pp + idx,
sizeof(
void * ) * tail );
319 void **pp = (
void **)realloc( ar->
pp_elems,
320 sizeof(
void * ) * (ar->
i_count + 1) );
338 size_t tail = ar->
i_count - idx - 1;
341 memmove( pp + idx, pp + idx + 1,
sizeof(
void * ) * tail );
347 pp = (
void **)realloc( pp,
sizeof(
void * ) * ar->
i_count );
367 static inline uint64_t
DictHash(
const char *psz_string,
int hashsize )
374 i_hash += *psz_string++;
375 i_hash += i_hash << 10;
376 i_hash ^= i_hash >> 8;
379 return i_hash % hashsize;
411 void ( * pf_free )(
void * p_data,
void * p_obj ),
416 for(
int i = 0; i < p_dict->
i_size; i++ )
422 p_next = p_current->
p_next;
423 if( pf_free != NULL )
424 ( * pf_free )( p_current->
p_value, p_obj );
444 for( ; p_entry != NULL; p_entry = p_entry->
p_next )
446 if( !strcmp( psz_key, p_entry->
psz_key ) )
449 return p_entry != NULL;
466 if( !strcmp( psz_key, p_entry->
psz_key ) )
468 p_entry = p_entry->
p_next;
483 for( i = 0; i < p_dict->
i_size; i++ )
494 for(
int i = 0; i < p_dict->
i_size; i++ )
500 static inline char **
507 ppsz_ret = (
char**)malloc(
sizeof(
char *) * (
count + 1));
512 for( i = 0; i < p_dict->
i_size; i++ )
514 for( p_entry = p_dict->
p_entries[i]; p_entry; p_entry = p_entry->
p_next )
517 ppsz_ret[
count] = NULL;
523 void * p_value,
bool rebuild )
541 p_entry = p_entry->
p_next;
546 int i_new_size = ( (p_dict->
i_size+2) * 3) / 2;
549 for( i = 0; i < p_dict->
i_size; i++ )
557 p_entry = p_entry->
p_next;
576 void ( * pf_free )(
void * p_data,
void * p_obj ),
592 if( !strcmp( psz_key, p_entry->
psz_key ) )
594 if( pf_free != NULL )
595 ( * pf_free )( p_entry->
p_value, p_obj );
605 p_entry = p_entry->
p_next;
613 template <
typename T>
614 void vlc_delete_all( T &container )
616 typename T::iterator it = container.begin();
617 while ( it != container.end() )
static void vlc_dictionary_insert(vlc_dictionary_t *p_dict, const char *psz_key, void *p_value)
Definition: vlc_arrays.h:566
static void vlc_array_append_or_abort(vlc_array_t *ar, void *elem)
Definition: vlc_arrays.h:327
int i_size
Definition: vlc_arrays.h:388
size_t count
Definition: core.c:461
struct vlc_dictionary_entry_t * p_next
Definition: vlc_arrays.h:383
vlc_dictionary_entry_t ** p_entries
Definition: vlc_arrays.h:389
void * p_value
Definition: vlc_arrays.h:382
static void vlc_array_insert_or_abort(vlc_array_t *ar, void *elem, int idx)
Definition: vlc_arrays.h:309
static void vlc_array_remove(vlc_array_t *ar, size_t idx)
Definition: vlc_arrays.h:333
size_t i_count
Definition: vlc_arrays.h:241
static int vlc_dictionary_keys_count(const vlc_dictionary_t *p_dict)
Definition: vlc_arrays.h:472
Definition: vlc_arrays.h:386
static void * realloc_down(void *ptr, size_t size)
Definition: vlc_arrays.h:34
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:407
struct vlc_array_t vlc_array_t
static void vlc_dictionary_insert_impl_(vlc_dictionary_t *p_dict, const char *psz_key, void *p_value, bool rebuild)
Definition: vlc_arrays.h:519
static int vlc_array_append(vlc_array_t *ar, void *elem)
Definition: vlc_arrays.h:315
static int vlc_array_insert(vlc_array_t *ar, void *elem, int idx)
Definition: vlc_arrays.h:292
struct vlc_dictionary_entry_t vlc_dictionary_entry_t
Definition: vlc_arrays.h:379
static bool vlc_dictionary_is_empty(const vlc_dictionary_t *p_dict)
Definition: vlc_arrays.h:488
static uint64_t DictHash(const char *psz_string, int hashsize)
Definition: vlc_arrays.h:364
Definition: vlc_arrays.h:238
char * psz_key
Definition: vlc_arrays.h:381
static size_t vlc_array_count(vlc_array_t *p_array)
Definition: vlc_arrays.h:257
static char ** vlc_dictionary_all_keys(const vlc_dictionary_t *p_dict)
Definition: vlc_arrays.h:498
static void * vlc_dictionary_value_for_key(const vlc_dictionary_t *p_dict, const char *psz_key)
Definition: vlc_arrays.h:450
static int vlc_dictionary_has_key(const vlc_dictionary_t *p_dict, const char *psz_key)
Definition: vlc_arrays.h:434
#define likely(p)
Definition: vlc_common.h:113
static void vlc_array_init(vlc_array_t *p_array)
Definition: vlc_arrays.h:244
static void vlc_array_clear(vlc_array_t *p_array)
Definition: vlc_arrays.h:250
char * strdup(const char *)
struct vlc_dictionary_t vlc_dictionary_t
#define vlc_array_item_at_index(ar, idx)
Definition: vlc_arrays.h:263
#define unlikely(p)
Definition: vlc_common.h:114
static void *const kVLCDictionaryNotFound
Definition: vlc_arrays.h:392
static void vlc_dictionary_init(vlc_dictionary_t *p_dict, int i_size)
Definition: vlc_arrays.h:394
void ** pp_elems
Definition: vlc_arrays.h:242
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:572
static ssize_t vlc_array_index_of_item(const vlc_array_t *ar, const void *elem)
Definition: vlc_arrays.h:280