Changeset 266fb28cd7fdd0db6926f807bf4f9bcdd1b29010
- Timestamp:
- 19/10/06 23:00:14 (2 years ago)
- git-parent:
- Files:
-
- include/vlc_arrays.h (added)
- include/vlc_common.h (modified) (1 diff)
- test/NativeAlgoTest.py (modified) (1 diff)
- test/native/algo.c (modified) (2 diffs)
- test/native/init.c (modified) (1 diff)
- test/native/tests.h (modified) (1 diff)
- test/test.sh (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
include/vlc_common.h
r62fffad r266fb28 634 634 #define FREE(a) if( a ) { free( a ); } 635 635 636 /* Dynamic array handling: realloc array, move data, increment position */ 637 #if defined( _MSC_VER ) && _MSC_VER < 1300 && !defined( UNDER_CE ) 638 # define VLCCVP (void**) /* Work-around for broken compiler */ 639 #else 640 # define VLCCVP 641 #endif 642 #define INSERT_ELEM( p_ar, i_oldsize, i_pos, elem ) \ 643 do \ 644 { \ 645 if( !i_oldsize ) (p_ar) = NULL; \ 646 (p_ar) = VLCCVP realloc( p_ar, ((i_oldsize) + 1) * sizeof(*(p_ar)) ); \ 647 if( (i_oldsize) - (i_pos) ) \ 648 { \ 649 memmove( (p_ar) + (i_pos) + 1, (p_ar) + (i_pos), \ 650 ((i_oldsize) - (i_pos)) * sizeof( *(p_ar) ) ); \ 651 } \ 652 (p_ar)[i_pos] = elem; \ 653 (i_oldsize)++; \ 654 } \ 655 while( 0 ) 656 657 #define REMOVE_ELEM( p_ar, i_oldsize, i_pos ) \ 658 do \ 659 { \ 660 if( (i_oldsize) - (i_pos) - 1 ) \ 661 { \ 662 memmove( (p_ar) + (i_pos), \ 663 (p_ar) + (i_pos) + 1, \ 664 ((i_oldsize) - (i_pos) - 1) * sizeof( *(p_ar) ) ); \ 665 } \ 666 if( i_oldsize > 1 ) \ 667 { \ 668 (p_ar) = realloc( p_ar, ((i_oldsize) - 1) * sizeof( *(p_ar) ) ); \ 669 } \ 670 else \ 671 { \ 672 free( p_ar ); \ 673 (p_ar) = NULL; \ 674 } \ 675 (i_oldsize)--; \ 676 } \ 677 while( 0 ) 678 679 680 #define TAB_APPEND( count, tab, p ) \ 681 if( (count) > 0 ) \ 682 { \ 683 (tab) = realloc( tab, sizeof( void ** ) * ( (count) + 1 ) ); \ 684 } \ 685 else \ 686 { \ 687 (tab) = malloc( sizeof( void ** ) ); \ 688 } \ 689 (tab)[count] = (p); \ 690 (count)++ 691 692 #define TAB_FIND( count, tab, p, index ) \ 693 { \ 694 int _i_; \ 695 (index) = -1; \ 696 for( _i_ = 0; _i_ < (count); _i_++ ) \ 697 { \ 698 if( (tab)[_i_] == (p) ) \ 699 { \ 700 (index) = _i_; \ 701 break; \ 702 } \ 703 } \ 704 } 705 706 #define TAB_REMOVE( count, tab, p ) \ 707 { \ 708 int _i_index_; \ 709 TAB_FIND( count, tab, p, _i_index_ ); \ 710 if( _i_index_ >= 0 ) \ 711 { \ 712 if( (count) > 1 ) \ 713 { \ 714 memmove( ((void**)(tab) + _i_index_), \ 715 ((void**)(tab) + _i_index_+1), \ 716 ( (count) - _i_index_ - 1 ) * sizeof( void* ) );\ 717 } \ 718 (count)--; \ 719 if( (count) == 0 ) \ 720 { \ 721 free( tab ); \ 722 (tab) = NULL; \ 723 } \ 724 } \ 725 } 726 727 /* Binary search in an array */ 728 #define BSEARCH( entries, count, elem, zetype, key, answer ) { \ 729 int low = 0, high = count - 1; \ 730 answer = -1; \ 731 while( low <= high ) {\ 732 int mid = (low + high ) / 2; /* Just don't care about 2^30 tables */ \ 733 zetype mid_val = entries[mid] elem;\ 734 if( mid_val < key ) \ 735 low = mid + 1; \ 736 else if ( mid_val > key ) \ 737 high = mid -1; \ 738 else \ 739 { \ 740 answer = mid; break; \ 741 }\ 742 } \ 743 } 744 745 /* Dictionnary handling */ 746 struct dict_entry_t 747 { 748 int i_int; 749 char *psz_string; 750 uint64_t i_hash; 751 void *p_data; 752 }; 753 754 struct dict_t 755 { 756 dict_entry_t *p_entries; 757 int i_entries; 758 }; 759 760 VLC_EXPORT( dict_t *, vlc_DictNew, (void) ); 761 VLC_EXPORT( void, vlc_DictClear, (dict_t * ) ); 762 VLC_EXPORT( void, vlc_DictInsert, (dict_t *, int, const char *, void * ) ); 763 VLC_EXPORT( void*, vlc_DictGet, (dict_t *, int, const char * ) ); 764 VLC_EXPORT( int, vlc_DictLookup, (dict_t *, int, const char * ) ); 636 #include <vlc_arrays.h> 765 637 766 638 /* MSB (big endian)/LSB (little endian) conversions - network order is always test/NativeAlgoTest.py
r0fbf13c r266fb28 4 4 5 5 class NativeAlgoTestCase( unittest.TestCase ): 6 def test_arrays( self ): 7 """[Algo] Check dynamic arrays""" 8 native_libvlc_test.arrays_test() 6 9 def test_bsearch_direct( self ): 7 10 """[Algo] Check Bsearch with simple types""" test/native/algo.c
r0fbf13c r266fb28 24 24 25 25 /********************************************************************** 26 * Arrays 27 *********************************************************************/ 28 29 TYPEDEF_ARRAY(long,long_array_t); 30 31 PyObject *arrays_test( PyObject *self, PyObject *args ) 32 { 33 mtime_t one, two; 34 int number = 1000000; 35 int number2 = 50000; /* For slow with memmove */ 36 printf("\n"); 37 { 38 int i_items = 0; 39 int *p_items = NULL; 40 int i; 41 one = mdate(); 42 for( i = 0 ; i<number;i++) { 43 INSERT_ELEM(p_items,i_items, i_items, i+50); 44 } 45 two = mdate(); 46 printf( " Std array %i items appended in "I64Fi" µs\n", number, 47 (two-one) ); 48 for( i = number-1 ; i>=0; i--) { 49 REMOVE_ELEM( p_items, i_items, i ); 50 } 51 one = mdate(); 52 printf( " Std array %i items removed in "I64Fi" µs\n", number, 53 (one-two) ); 54 55 for( i = 0 ; i<number2;i++) { 56 int pos = i_items == 0 ? 0 : rand() % i_items; 57 INSERT_ELEM(p_items, i_items, pos, pos + 50); 58 } 59 two = mdate(); 60 printf( " Std array %i items inserted in "I64Fi" µs\n", number2, 61 (two-one) ); 62 } 63 { 64 DECL_ARRAY(int) int_array; 65 int i = 0; 66 ARRAY_INIT(int_array); 67 ASSERT(int_array.i_size == 0, "" ); 68 ASSERT(int_array.i_alloc == 0, "" ); 69 ASSERT(int_array.p_elems == 0, "" ); 70 71 ARRAY_APPEND(int_array, 42 ); 72 ASSERT(int_array.i_size == 1, "" ); 73 ASSERT(int_array.i_alloc > 1, "" ); 74 ASSERT(int_array.p_elems[0] == 42, "" ); 75 ARRAY_REMOVE(int_array,0); 76 ASSERT(int_array.i_size == 0, "" ); 77 78 one = mdate(); 79 for( i = 0 ; i<number;i++) { 80 ARRAY_APPEND(int_array, i+50); 81 } 82 two = mdate(); 83 printf( " New array %i items appended in "I64Fi" µs\n", number, 84 (two-one) ); 85 ASSERT(int_array.p_elems[1242] == 1292 , ""); 86 for( i = number-1 ; i>=0; i--) { 87 ARRAY_REMOVE(int_array,i); 88 } 89 one = mdate(); 90 printf( " New array %i items removed in "I64Fi" µs\n", number, 91 (one-two) ); 92 93 /* Now random inserts */ 94 for( i = 0 ; i<number2;i++) { 95 int pos = int_array.i_size == 0 ? 0 : rand() % int_array.i_size; 96 ARRAY_INSERT(int_array, pos+50, pos); 97 } 98 two = mdate(); 99 printf( " New array %i items inserted in "I64Fi" µs\n", number2, 100 (two-one) ); 101 } 102 { 103 long_array_t larray; 104 ARRAY_INIT(larray); 105 } 106 Py_INCREF( Py_None); 107 return Py_None; 108 } 109 110 /********************************************************************** 26 111 * Binary search 27 112 *********************************************************************/ … … 67 152 struct bsearch_tester array[] = 68 153 { 69 { 0, 12 }, { 1, 22 } , { 2, 33 } , { 3, 68 } , { 4, 56 } 154 { 0, 12 }, { 1, 22 } , { 2, 33 } , { 3, 68 } , { 4, 56 } 70 155 }; 71 156 #define MEMBCHECK( checked, expected ) { \ test/native/init.c
rf834305 r266fb28 21 21 DEF_METHOD( gui_chains_test, "Test interactions between chains and GUI" ) 22 22 DEF_METHOD( psz_chains_test, "Test building of chain strings" ) 23 DEF_METHOD( arrays_test, "Test arrays") 23 24 DEF_METHOD( bsearch_direct_test, "Test Bsearch without structure" ) 24 25 DEF_METHOD( bsearch_member_test, "Test Bsearch with structure" ) test/native/tests.h
rf834305 r266fb28 20 20 21 21 /* Algo */ 22 PyObject *arrays_test( PyObject *self, PyObject *args ); 22 23 PyObject *bsearch_direct_test( PyObject *self, PyObject *args ); 23 24 PyObject *bsearch_member_test( PyObject *self, PyObject *args ); test/test.sh
re85a5a6 r266fb28 13 13 ulimit -c unlimited 14 14 15 python test/test.py -v 2>&1|perl -e \ 15 if [ "x$1" = "xdebug" ] 16 then 17 gdb python "test/test.sh" 18 else 19 python test/test.py -v 2>&1|perl -e \ 16 20 '$bold = "\033[1m"; 17 21 $grey = "\033[37m"; … … 43 47 } 44 48 }' 45 49 fi
