Mercurial > hg > audiodb
comparison lshlib.cpp @ 512:6439cfba2524 memory-leaks
Implemented correct LSH table via compile-time switch -DLSH_DUMP_CORE_TABLES. Dumps on LSH load.
author | mas01mc |
---|---|
date | Fri, 23 Jan 2009 18:45:44 +0000 |
parents | bf54b8fa7d89 |
children |
comparison
equal
deleted
inserted
replaced
502:eb9a7ef110c1 | 512:6439cfba2524 |
---|---|
1356 else | 1356 else |
1357 // Use ARRAY CORE format with numElements counter | 1357 // Use ARRAY CORE format with numElements counter |
1358 token = unserialize_hashtable_row_to_array(dbFile, h[x]+y, numElements); | 1358 token = unserialize_hashtable_row_to_array(dbFile, h[x]+y, numElements); |
1359 #else | 1359 #else |
1360 token = unserialize_hashtable_row_format2(dbFile, h[x]+y); | 1360 token = unserialize_hashtable_row_format2(dbFile, h[x]+y); |
1361 #endif | 1361 #endif |
1362 | |
1363 #ifdef LSH_DUMP_CORE_TABLES | |
1364 printf("C[%d,%d]", x, y); | |
1365 dump_hashtable_row(h[x][y]); | |
1366 #endif | |
1367 // Check that token is valid | 1362 // Check that token is valid |
1368 if( !(token==O2_SERIAL_TOKEN_T1 || token==O2_SERIAL_TOKEN_ENDTABLE) ){ | 1363 if( !(token==O2_SERIAL_TOKEN_T1 || token==O2_SERIAL_TOKEN_ENDTABLE) ){ |
1369 fclose(dbFile); | 1364 fclose(dbFile); |
1370 error("State machine error end of row/table", "unserialize_lsh_hashtables_format2()"); | 1365 error("State machine error end of row/table", "unserialize_lsh_hashtables_format2()"); |
1371 } | 1366 } |
1377 // Check for new row flag | 1372 // Check for new row flag |
1378 if(token==O2_SERIAL_TOKEN_T1) | 1373 if(token==O2_SERIAL_TOKEN_T1) |
1379 H::t1 = token; | 1374 H::t1 = token; |
1380 } | 1375 } |
1381 } | 1376 } |
1377 #ifdef LSH_DUMP_CORE_TABLES | |
1378 dump_hashtables(); | |
1379 #endif | |
1382 } | 1380 } |
1383 | 1381 |
1384 Uns32T G::unserialize_hashtable_row_format2(FILE* dbFile, bucket** b, Uns32T token){ | 1382 Uns32T G::unserialize_hashtable_row_format2(FILE* dbFile, bucket** b, Uns32T token){ |
1385 bool pointFound = false; | 1383 bool pointFound = false; |
1386 | 1384 |
1572 else | 1570 else |
1573 if(*p != LSH_CORE_ARRAY_END_ROW_TOKEN) | 1571 if(*p != LSH_CORE_ARRAY_END_ROW_TOKEN) |
1574 p = p + skip; | 1572 p = p + skip; |
1575 }while( *p != LSH_CORE_ARRAY_END_ROW_TOKEN ); | 1573 }while( *p != LSH_CORE_ARRAY_END_ROW_TOKEN ); |
1576 } | 1574 } |
1575 | |
1576 void G::dump_hashtables(){ | |
1577 for(Uns32T x = 0; x < H::L ; x++) | |
1578 for(Uns32T y = 0; y < H::N ; y++){ | |
1579 bucket* bPtr = h[x][y]; | |
1580 if(bPtr){ | |
1581 printf("C[%d,%d]", x, y); | |
1582 #ifdef LSH_LIST_HEAD_COUNTERS | |
1583 printf("[numBuckets=%d]",bPtr->snext.numBuckets); | |
1584 if(bPtr->t2&LSH_CORE_ARRAY_BIT) { | |
1585 dump_core_hashtable_array((Uns32T*)(bPtr->next)); | |
1586 } | |
1587 else { | |
1588 dump_hashtable_row(bPtr->next); | |
1589 } | |
1590 #else | |
1591 dump_hashtable_row(bPtr); | |
1592 #endif | |
1593 printf("\n"); | |
1594 fflush(stdout); | |
1595 } | |
1596 } | |
1597 } | |
1598 | |
1599 void G::dump_core_hashtable_array(Uns32T* p){ | |
1600 Uns32T skip; | |
1601 Uns32T t2; | |
1602 Uns32T p1; | |
1603 Uns32T p2; | |
1604 CR_ASSERT(p); | |
1605 do{ | |
1606 t2 = *p++; | |
1607 p1 = *p++; | |
1608 p2 = *p++; | |
1609 skip = (( p1 & SKIP_BITS ) >> SKIP_BITS_RIGHT_SHIFT_LSB) + (( p2 & SKIP_BITS ) >> SKIP_BITS_RIGHT_SHIFT_MSB); | |
1610 printf("(%0x, %0x)", t2, p1 ^ (p1 & SKIP_BITS)); | |
1611 if(skip--){ | |
1612 printf("(%0x, %0x)", t2, p2 ^ (p2 & SKIP_BITS)); | |
1613 while(skip-- ) | |
1614 printf("(%0x, %0x)", t2, *p++); | |
1615 } | |
1616 }while( *p != LSH_CORE_ARRAY_END_ROW_TOKEN ); | |
1617 } | |
1577 | 1618 |
1578 void G::dump_hashtable_row(bucket* p){ | 1619 void G::dump_hashtable_row(bucket* p){ |
1579 while(p && p->t2!=IFLAG){ | 1620 while(p && p->t2!=IFLAG){ |
1580 sbucket* sbp = p->snext.ptr; | 1621 sbucket* sbp = p->snext.ptr; |
1581 while(sbp){ | 1622 while(sbp){ |