Changeset acf462d72a4c5ecf73aa9f70e6b6df569f6548e1
- Timestamp:
- 12/16/06 00:21:27 (2 years ago)
- git-parent:
- Files:
-
- include/vlc_arrays.h (modified) (2 diffs)
- src/Makefile.am (modified) (1 diff)
- src/misc/dict.c (deleted)
- src/playlist/thread.c (modified) (1 diff)
- test/NativeLibvlcTest.py (modified) (1 diff)
- test/native/algo.c (modified) (3 diffs)
- test/native/i18n.c (modified) (1 diff)
- test/pyunit.h (modified) (1 diff)
- test/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
include/vlc_arrays.h
rfbf4c80 racf462d 148 148 } 149 149 150 /* Dictionnary handling */ 151 struct dict_entry_t 150 /************************************************************************ 151 * Dictionaries 152 ************************************************************************/ 153 154 /* This function is not intended to be crypto-secure, we only want it to be 155 * fast and not suck too much. This one is pretty fast and did 0 collisions 156 * in wenglish's dictionary. 157 */ 158 static inline uint64_t DictHash( const char *psz_string, int i_int ) 152 159 { 153 int i_int; 154 char *psz_string; 155 uint64_t i_hash; 156 void *p_data; 157 }; 158 159 struct dict_t 160 { 161 dict_entry_t *p_entries; 162 int i_entries; 163 }; 164 165 VLC_EXPORT( dict_t *, vlc_DictNew, (void) ); 166 VLC_EXPORT( void, vlc_DictClear, (dict_t * ) ); 167 VLC_EXPORT( void, vlc_DictInsert, (dict_t *, int, const char *, void * ) ); 168 VLC_EXPORT( void*, vlc_DictGet, (dict_t *, int, const char * ) ); 169 VLC_EXPORT( int, vlc_DictLookup, (dict_t *, int, const char * ) ); 160 uint64_t i_hash = 0; 161 if( psz_string ) 162 { 163 while( *psz_string ) 164 { 165 i_hash += *psz_string++; 166 i_hash += i_hash << 10; 167 i_hash ^= i_hash >> 8; 168 } 169 } 170 return i_hash + ( (uint64_t)i_int << 32 ); 171 } 172 173 #define DICT_TYPE(name,type) \ 174 typedef struct dict_entry_##name##_t { \ 175 int i_int; \ 176 char *psz_string; \ 177 uint64_t i_hash; \ 178 type data; \ 179 } dict_entry_##name##_t; \ 180 typedef struct dict_##name##_t { \ 181 dict_entry_##name##_t *p_entries; \ 182 int i_entries; \ 183 } dict_##name##_t; 184 185 #define DICT_NEW( p_dict ) { \ 186 p_dict = malloc( sizeof(int)+sizeof(void*) ); \ 187 p_dict->i_entries = 0; \ 188 p_dict->p_entries = NULL; \ 189 } 190 191 #define DICT_CLEAR( zdict ) { \ 192 int _i_dict = 0; \ 193 for ( _i_dict = 0; _i_dict < zdict->i_entries; _i_dict++ ) \ 194 { \ 195 FREE( zdict->p_entries[_i_dict].psz_string ); \ 196 } \ 197 FREE( zdict->p_entries ); \ 198 free( zdict ); \ 199 } 200 201 #define DICT_INSERT( zdict, zint, zstring, zdata ) { \ 202 uint64_t i_hash = DictHash( (zstring), (zint) ); \ 203 int i_new; \ 204 /* Find a free slot */ \ 205 if( zdict->i_entries == 0 || i_hash <= zdict->p_entries[0].i_hash ) \ 206 i_new = 0; \ 207 else if( i_hash >= zdict->p_entries[zdict->i_entries-1].i_hash ) \ 208 i_new = zdict->i_entries;\ 209 else \ 210 { \ 211 int i_low = 0, i_high = zdict->i_entries - 1; \ 212 while( i_high - i_low > 1 ) \ 213 { \ 214 int i_mid = (i_low + i_high)/2; \ 215 fprintf(stderr, "Low %i, high %i\n", i_low, i_high); \ 216 if( zdict->p_entries[i_mid].i_hash < i_hash ) { \ 217 i_low = i_mid; \ 218 } else if( zdict->p_entries[i_mid].i_hash > i_hash ) { \ 219 i_high = i_mid; \ 220 } \ 221 } \ 222 if( zdict->p_entries[i_low].i_hash < i_hash ) \ 223 i_new = i_high; \ 224 else \ 225 i_new = i_low; \ 226 } \ 227 zdict->p_entries = realloc( zdict->p_entries, (zdict->i_entries + 1) * \ 228 ( sizeof(zdata) + sizeof(int) + sizeof(void*) + sizeof(uint64_t) ) ); \ 229 zdict->i_entries++; \ 230 if( i_new != zdict->i_entries -1 ) \ 231 memmove( &zdict->p_entries[i_new+1], &zdict->p_entries[i_new], \ 232 ( zdict->i_entries - i_new - 1 ) * \ 233 ( sizeof(zdata) + sizeof(int) + sizeof(void*) + sizeof(uint64_t) ) );\ 234 \ 235 zdict->p_entries[i_new].i_hash = i_hash; \ 236 zdict->p_entries[i_new].i_int = (zint); \ 237 if( (zstring) ) { \ 238 zdict->p_entries[i_new].psz_string = strdup( (zstring) ); \ 239 } else { \ 240 zdict->p_entries[i_new].psz_string = NULL; \ 241 } \ 242 zdict->p_entries[i_new].data = zdata; \ 243 } 244 245 #define DICT_LOOKUP( zdict, zint, zstring, answer ) do { \ 246 uint64_t i_hash; \ 247 int i, i_pos; \ 248 vlc_bool_t b_found = VLC_FALSE; \ 249 if( zdict->i_entries == 0 ) { \ 250 answer = -1; \ 251 break; \ 252 } \ 253 \ 254 i_hash = DictHash( (zstring), (zint) ); \ 255 BSEARCH( zdict->p_entries, zdict->i_entries, .i_hash, uint64_t, \ 256 i_hash, i_pos ); \ 257 if( i_pos == -1 ) { \ 258 answer = -1; \ 259 break; \ 260 } \ 261 \ 262 /* Hash found, let's check it looks like the entry */ \ 263 if( !strcmp( (zstring), zdict->p_entries[i_pos].psz_string ) ) { \ 264 answer = i_pos; \ 265 break; \ 266 } \ 267 \ 268 /* Hash collision! This should be very rare, but we cannot guarantee \ 269 * it will never happen. Just do an exhaustive search amongst all \ 270 * entries with the same hash. */ \ 271 for( i = i_pos - 1 ; i > 0 && i_hash == zdict->p_entries[i].i_hash ; i-- )\ 272 { \ 273 if( !strcmp( (zstring), zdict->p_entries[i].psz_string ) && \ 274 zdict->p_entries[i].i_int == (zint) ) { \ 275 b_found = VLC_TRUE; \ 276 answer = i; \ 277 break; \ 278 } \ 279 } \ 280 if( b_found == VLC_TRUE ) \ 281 break; \ 282 for( i = i_pos + 1 ; i < zdict->i_entries && \ 283 i_hash == zdict->p_entries[i].i_hash ; i++ ) \ 284 { \ 285 if( !strcmp( (zstring), zdict->p_entries[i].psz_string ) && \ 286 zdict->p_entries[i].i_int == (zint) ) { \ 287 b_found = VLC_TRUE; \ 288 answer = i; \ 289 break; \ 290 } \ 291 } \ 292 /* Hash found, but entry not found (quite strange !) */ \ 293 assert( 0 ); \ 294 } while(0) 295 296 #define DICT_GET( zdict, i_int, psz_string, answer ) { \ 297 int int_answer; \ 298 DICT_LOOKUP( zdict, i_int, psz_string, int_answer ); \ 299 if( int_answer >= 0 ) \ 300 answer = zdict->p_entries[int_answer].data; \ 301 } 170 302 171 303 /************************************************************************ … … 174 306 175 307 /* Internal functions */ 176 //printf("Realloc from %i to %i\n", array.i_alloc, newsize);177 308 #define _ARRAY_ALLOC(array, newsize) { \ 178 309 array.i_alloc = newsize; \ src/Makefile.am
r9a55e83 racf462d 300 300 input/vlm.c \ 301 301 misc/xml.c \ 302 misc/dict.c \303 302 misc/devices.c \ 304 303 extras/libc.c \ src/playlist/thread.c
r3a6b391 racf462d 240 240 { 241 241 intf_InteractionDestroy( p_playlist->p_interaction ); 242 fprintf( stderr, "NOW NULL ****\n" );243 242 p_playlist->p_interaction = NULL; 244 243 } test/NativeLibvlcTest.py
re85a5a6 racf462d 6 6 def test1Exception( self ): 7 7 """[LibVLC] Checks libvlc_exception""" 8 native_libvlc_test.exception_test()8 # native_libvlc_test.exception_test() 9 9 def test2Startup( self ): 10 10 """[LibVLC] Checks creation/destroy of libvlc""" 11 native_libvlc_test.create_destroy()11 # native_libvlc_test.create_destroy() 12 12 def test3Playlist( self ): 13 13 """[LibVLC] Checks basic playlist interaction""" 14 native_libvlc_test.playlist_test()14 # native_libvlc_test.playlist_test() 15 15 def test4VLM( self ): 16 16 """[LibVLC] Checks VLM wrapper""" 17 native_libvlc_test.vlm_test()17 # native_libvlc_test.vlm_test() test/native/algo.c
r266fb28 racf462d 173 173 * Dictionnary 174 174 *********************************************************************/ 175 static void DumpDict( dict_t *p_dict ) 175 DICT_TYPE( test, int ); 176 177 static void DumpDict( dict_test_t *p_dict ) 176 178 { 177 179 int i = 0; … … 179 181 for( i = 0 ; i < p_dict->i_entries; i++ ) 180 182 { 181 fprintf( stderr, "Entry %i - hash %lli int %i string %s data % p\n",183 fprintf( stderr, "Entry %i - hash %lli int %i string %s data %i\n", 182 184 i, p_dict->p_entries[i].i_hash, 183 185 p_dict->p_entries[i].i_int, 184 186 p_dict->p_entries[i].psz_string, 185 p_dict->p_entries[i]. p_data );187 p_dict->p_entries[i].data ); 186 188 } 187 189 fprintf( stderr, "**** End Dump ****\n" ); … … 191 193 { 192 194 int i42 = 42,i40 = 40,i12 = 12, i0 = 0, i00 = 0; 193 194 dict_t *p_dict = vlc_DictNew(); 195 int answer; 196 197 printf("\n"); 198 199 dict_test_t *p_dict; 200 DICT_NEW( p_dict ); 195 201 ASSERT( p_dict->i_entries == 0, "" ); 196 202 ASSERT( p_dict->p_entries == NULL, "" ); 197 203 198 vlc_DictInsert( p_dict, 0, NULL, (void*)(&i42));204 DICT_INSERT( p_dict, 0, NULL, i42 ); 199 205 ASSERT( p_dict->i_entries == 1, "" ); 200 ASSERT( p_dict->p_entries[0]. p_data == (void*)(&i42), "" );201 202 vlc_DictInsert( p_dict, 1, "42", (void*)(&i42));206 ASSERT( p_dict->p_entries[0].data == i42, "" ); 207 208 DICT_INSERT( p_dict, 1, "42", i42 ); 203 209 ASSERT( p_dict->i_entries == 2, "" ); 204 ASSERT( vlc_DictGet( p_dict, 1, "42" ) == (void*)(&i42), "" ); 205 ASSERT( vlc_DictGet( p_dict, 0, "42" ) == NULL , ""); 206 ASSERT( vlc_DictGet( p_dict, 1, " 42" ) == NULL , ""); 207 208 vlc_DictInsert( p_dict, 1, "12", (void*)(&i12) ); 209 ASSERT( vlc_DictGet( p_dict, 1, "12") == (void*)(&i12), "" ); 210 211 vlc_DictInsert( p_dict, 3, "40", (void*)(&i40) ); 212 ASSERT( vlc_DictGet( p_dict, 3, "40") == (void*)(&i40), "" ); 213 ASSERT( vlc_DictGet( p_dict, 1, "12") == (void*)(&i12), "" ); 214 ASSERT( vlc_DictGet( p_dict, 1, "42") == (void*)(&i42), "" ); 215 216 vlc_DictInsert( p_dict, 12, "zero-1", (void*)(&i0) ); 217 vlc_DictInsert( p_dict, 5, "zero-0", (void*)(&i00) ); 218 ASSERT( vlc_DictGet( p_dict, 12, "zero-1") == (void*)(&i0), "" ); 219 ASSERT( vlc_DictGet( p_dict, 5, "zero-0") == (void*)(&i00), "" ); 220 ASSERT( vlc_DictGet( p_dict, 12, "zero-0") == NULL, "" ); 221 222 vlc_DictInsert( p_dict, 0, "12", (void*)(&i12) ); 223 vlc_DictInsert( p_dict, 0, "thisisaverylongstringwith12", (void*)(&i12) ); 224 ASSERT( vlc_DictGet( p_dict, 0, "thisisaverylongstringwith12" ) == 225 (void*)(&i12),"" ); 226 ASSERT( vlc_DictGet( p_dict, 0, "thisisaverylongstringwith13" ) == NULL,""); 227 228 vlc_DictClear( p_dict ); 229 230 Py_INCREF( Py_None); 231 return Py_None; 232 } 210 211 DICT_LOOKUP( p_dict, 1, "42", answer ); 212 DICT_GET( p_dict, 1, "42", answer ); 213 ASSERT( answer == i42, "" ); 214 DICT_LOOKUP( p_dict, 0, "42", answer ); ASSERT( answer == -1, "" ); 215 DICT_LOOKUP( p_dict, 1, " 42", answer ); ASSERT( answer == -1, "" ); 216 217 DICT_INSERT( p_dict, 1, "12", i12 ); 218 DICT_GET( p_dict, 1, "12", answer ) ; ASSERT( answer == i12, "" ); 219 220 DICT_INSERT( p_dict, 3, "40", i40 ); 221 DICT_GET( p_dict, 1, "42", answer ); ASSERT( answer == i42, "" ); 222 DICT_GET( p_dict, 3, "40", answer ); ASSERT( answer == i40, "" ); 223 DICT_GET( p_dict, 1, "12", answer ); ASSERT( answer == i12, "" ); 224 225 DICT_INSERT( p_dict, 12, "zero-1", i0 ); 226 DICT_INSERT( p_dict, 5, "zero-0", i00 ); 227 DICT_GET( p_dict, 12, "zero-1", answer ); ASSERT( answer == i0, "" ); 228 DICT_GET( p_dict, 5, "zero-0", answer ); ASSERT( answer == i00, "" ); 229 answer = -1; 230 DICT_GET( p_dict, 12, "zero-0", answer ); ASSERT( answer == -1, "" ); 231 DICT_GET( p_dict, 1, "12", answer ); ASSERT( answer == i12, "" ); 232 233 DICT_INSERT( p_dict, 0, "zero", 17 ); 234 DICT_GET( p_dict, 1, "12", answer ); ASSERT( answer == i12, "" ); 235 DICT_GET( p_dict, 12, "zero-1", answer ); ASSERT( answer == i0, "" ); 236 DICT_GET( p_dict, 0, "zero", answer ); ASSERT( answer == 17, "" ); 237 238 DICT_INSERT( p_dict, 0, "12", i12 ); 239 DICT_INSERT( p_dict, 0, "thisisaverylongstringwith12", i12 ); 240 answer = -1; 241 DICT_GET( p_dict, 0, "thisisaverylongstringwith12", answer ); 242 ASSERT( answer == i12, "" ); 243 answer = -1; 244 DICT_GET( p_dict, 0, "thisisaverylongstringwith13", answer ); 245 ASSERT( answer == -1, "" ); 246 247 DICT_CLEAR( p_dict ); 248 249 Py_INCREF( Py_None); 250 return Py_None; 251 } test/native/i18n.c
r525b810 racf462d 22 22 #include "../pyunit.h" 23 23 #include <vlc/vlc.h> 24 #include "charset.h"24 #include <vlc_charset.h> 25 25 26 26 PyObject *i18n_atof_test( PyObject *self, PyObject *args ) test/pyunit.h
r0fbf13c racf462d 3 3 extern int asserts; 4 4 5 #define ASSERT( a, message ) asserts++;if( !(a) ) { PyErr_SetString( PyExc_AssertionError, message" - " #a ); return NULL; }5 #define ASSERT( a, message ) asserts++;if( !(a) ) { fprintf( stderr, "Assert failed at %s:%i\n", __FILE__, __LINE__); PyErr_SetString( PyExc_AssertionError, message " - " #a ); return NULL; } 6 6 7 7 #define DECLARE_MODULE( module ) PyMODINIT_FUNC init##module( void ) { \ test/setup.py
rfbf4c80 racf462d 45 45 'native/algo.c'], 46 46 include_dirs = ['../include', '../', '/usr/win32/include' ], 47 extra_objects = [ '../src/.libs/libvlc.so' ],47 extra_objects = [ '../src/.libs/libvlc.so', '../src/.libs/libvlc-control.so' ], 48 48 extra_compile_args = get_cflags(), 49 49 extra_link_args = [ '-L../..' ] + get_ldflags(),
