diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-02-21 10:47:21 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-02-21 10:47:21 -0800 |
commit | 2206e221bd58b19141872c062012b6a9db0d73a2 (patch) | |
tree | 93e489e678065902ac2b527cb9bdbe42f9d2f67f /util.cpp | |
parent | d9bb9b73adc32b91df31ceec299e3194b49710e2 (diff) |
Removed array_list_t (!)
Diffstat (limited to 'util.cpp')
-rw-r--r-- | util.cpp | 251 |
1 files changed, 0 insertions, 251 deletions
@@ -95,257 +95,6 @@ int maxi( int a, return a>b?a:b; } -/** - Real implementation of all al_push_* versions. Pushes arbitrary - element to end of list. - */ -static int al_push_generic( array_list_t *l, anything_t o ) -{ - if( l->pos >= l->size ) - { - int new_size = l->pos == 0 ? MIN_SIZE : 2 * l->pos; - void *tmp = realloc( l->arr, sizeof( anything_t )*new_size ); - if( tmp == 0 ) - { - oom_handler( l ); - return 0; - } - l->arr = (anything_t *)tmp; - l->size = new_size; - } - l->arr[l->pos++] = o; - return 1; -} - -int al_push( array_list_t *l, const void *o ) -{ - anything_t v; - v.ptr_val = (void *)o; - return al_push_generic( l, v ); -} - -int al_push_long( array_list_t *l, long val ) -{ - anything_t v; - v.long_val = val; - return al_push_generic( l, v ); -} - -int al_push_func( array_list_t *l, func_ptr_t f ) -{ - anything_t v; - v.func_val = f; - return al_push_generic( l, v ); -} - - -int al_push_all( array_list_t *a, array_list_t *b ) -{ - int k; - for( k=0; k<al_get_count( b ); k++ ) - { - if( !al_push( a, al_get( b, k ) ) ) - return 0; - } - return 1; -} - -/** - Real implementation of all al_set_* versions. Sets arbitrary - element of list. - */ - -static int al_set_generic( array_list_t *l, int pos, anything_t v ) -{ - int old_pos; - - if( pos < 0 ) - return 0; - if( pos < l->pos ) - { - l->arr[pos]=v; - return 1; - } - old_pos=l->pos; - - l->pos = pos; - if( al_push_generic( l, v ) ) - { - memset( &l->arr[old_pos], - 0, - sizeof(anything_t) * (pos - old_pos) ); - return 1; - } - return 0; -} - -int al_set( array_list_t *l, int pos, const void *o ) -{ - anything_t v; - v.ptr_val = (void *)o; - return al_set_generic( l, pos, v ); -} - -int al_set_long( array_list_t *l, int pos, long o ) -{ - anything_t v; - v.long_val = o; - return al_set_generic( l, pos, v ); -} - -int al_set_func( array_list_t *l, int pos, func_ptr_t f ) -{ - anything_t v; - v.func_val = f; - return al_set_generic( l, pos, v ); -} - -/** - Real implementation of all al_get_* versions. Returns element from list. - */ -static anything_t al_get_generic( array_list_t *l, int pos ) -{ - anything_t res; - res.ptr_val=0; - - if( (pos >= 0) && ((size_t)pos < l->pos) ) - res = l->arr[pos]; - - return res; -} - -void *al_get( array_list_t *l, int pos ) -{ - return al_get_generic(l,pos).ptr_val; -} - -long al_get_long( array_list_t *l, int pos ) -{ - return al_get_generic(l,pos).long_val; -} - -func_ptr_t al_get_func( array_list_t *l, int pos ) -{ - return al_get_generic(l,pos).func_val; -} - - - -void al_truncate( array_list_t *l, int new_sz ) -{ - CHECK( l, ); - l->pos = new_sz; -} - -/** - Real implementation of all al_pop_* versions. Pops arbitrary - element from end of list. - */ -static anything_t al_pop_generic( array_list_t *l ) -{ - anything_t e; - - if( l->pos <= 0 ) - { - memset( &e, 0, sizeof(anything_t ) ); - return e; - } - - - e = l->arr[--l->pos]; - if( (l->pos*3 < l->size) && (l->size < MIN_SIZE) ) - { - anything_t *old_arr = l->arr; - int old_size = l->size; - l->size = l->size/2; - l->arr = (anything_t *)realloc( l->arr, sizeof(anything_t)*l->size ); - if( l->arr == 0 ) - { - l->arr = old_arr; - l->size = old_size; - /* - We are _shrinking_ the list here, so if the allocation - fails (it never should, but hey) then we can keep using - the old list - no need to flag any error... - */ - } - } - return e; -} - -void *al_pop( array_list_t *l ) -{ - return al_pop_generic(l).ptr_val; -} - -long al_pop_long( array_list_t *l ) -{ - return al_pop_generic(l).long_val; -} - -func_ptr_t al_pop_func( array_list_t *l ) -{ - return al_pop_generic(l).func_val; -} - -/** - Real implementation of all al_peek_* versions. Peeks last element - of list. - */ -static anything_t al_peek_generic( array_list_t *l ) -{ - anything_t res; - res.ptr_val=0; - if( l->pos>0) - res = l->arr[l->pos-1]; - return res; -} - -void *al_peek( array_list_t *l ) -{ - return al_peek_generic(l).ptr_val; -} - -long al_peek_long( array_list_t *l ) -{ - return al_peek_generic(l).long_val; -} - -func_ptr_t al_peek_func( array_list_t *l ) -{ - return al_peek_generic(l).func_val; -} - - -int al_get_count( array_list_t *l ) - -{ - CHECK( l, 0 ); - return l->pos; -} - -void al_foreach( array_list_t *l, void (*func)( void * )) -{ - size_t i; - - CHECK( l, ); - CHECK( func, ); - - for( i=0; i<l->pos; i++ ) - func( l->arr[i].ptr_val ); -} - -void al_foreach2( array_list_t *l, void (*func)( void *, void *), void *aux) -{ - size_t i; - - CHECK( l, ); - CHECK( func, ); - - for( i=0; i<l->pos; i++ ) - func( l->arr[i].ptr_val, aux ); -} - int wcsfilecmp( const wchar_t *a, const wchar_t *b ) { CHECK( a, 0 ); |