Mercurial > hg > audiodb
comparison lshlib.cpp @ 344:223a5994a962
unionized punning of the sbucket.snext field into {subucket* ptr, unsigned numBuckets}snext; so that list-head code is 64-bit friendly.
author | mas01mc |
---|---|
date | Tue, 07 Oct 2008 21:03:26 +0000 |
parents | fdeb8db97678 |
children | 6564be3109c5 |
comparison
equal
deleted
inserted
replaced
343:fdeb8db97678 | 344:223a5994a962 |
---|---|
238 #ifdef LSH_CORE_ARRAY | 238 #ifdef LSH_CORE_ARRAY |
239 if(H::h[ j ][ i ]) | 239 if(H::h[ j ][ i ]) |
240 if(H::h[ j ][ i ]->t2 & LSH_CORE_ARRAY_BIT){ | 240 if(H::h[ j ][ i ]->t2 & LSH_CORE_ARRAY_BIT){ |
241 pp = get_pointer_to_bucket_linked_list(H::h[ j ][ i ]); | 241 pp = get_pointer_to_bucket_linked_list(H::h[ j ][ i ]); |
242 if(*pp){ | 242 if(*pp){ |
243 (*pp)->snext=0; // Head of list uses snext as a non-pointer value | 243 (*pp)->snext.ptr=0; // Head of list uses snext as a non-pointer value |
244 delete *pp; // Now the destructor can do its work properly | 244 delete *pp; // Now the destructor can do its work properly |
245 } | 245 } |
246 free(H::h[ j ][ i ]->next); | 246 free(H::h[ j ][ i ]->next); |
247 H::h[ j ][ i ]->next = 0; // Zero next pointer | 247 H::h[ j ][ i ]->next = 0; // Zero next pointer |
248 H::h[ j ][ i ]->snext = 0; // Zero head-of-list pointer as above | 248 H::h[ j ][ i ]->snext.ptr = 0; // Zero head-of-list pointer as above |
249 } | 249 } |
250 #endif | 250 #endif |
251 delete H::h[ j ][ i ]; | 251 delete H::h[ j ][ i ]; |
252 } | 252 } |
253 delete[] H::h[ j ]; | 253 delete[] H::h[ j ]; |
391 // insert points into hashtable row collision chain | 391 // insert points into hashtable row collision chain |
392 void H::__bucket_insert_point(bucket* p){ | 392 void H::__bucket_insert_point(bucket* p){ |
393 if(p->t2 == IFLAG){ // initialization flag, is it in the domain of t2? | 393 if(p->t2 == IFLAG){ // initialization flag, is it in the domain of t2? |
394 p->t2 = H::t2; | 394 p->t2 = H::t2; |
395 bucketCount++; // Record start of new point-locale collision chain | 395 bucketCount++; // Record start of new point-locale collision chain |
396 p->snext = new sbucket(); | 396 p->snext.ptr = new sbucket(); |
397 __sbucket_insert_point(p->snext); | 397 __sbucket_insert_point(p->snext.ptr); |
398 return; | 398 return; |
399 } | 399 } |
400 | 400 |
401 if(p->t2 == H::t2){ | 401 if(p->t2 == H::t2){ |
402 __sbucket_insert_point(p->snext); | 402 __sbucket_insert_point(p->snext.ptr); |
403 return; | 403 return; |
404 } | 404 } |
405 | 405 |
406 if(p->next){ | 406 if(p->next){ |
407 // Construct list in t2 order | 407 // Construct list in t2 order |
442 return *(h+j); | 442 return *(h+j); |
443 } | 443 } |
444 | 444 |
445 // Find the linked-list pointer at the end of the CORE_ARRAY | 445 // Find the linked-list pointer at the end of the CORE_ARRAY |
446 bucket** H::get_pointer_to_bucket_linked_list(bucket* rowPtr){ | 446 bucket** H::get_pointer_to_bucket_linked_list(bucket* rowPtr){ |
447 Uns32T numBuckets = reinterpret_cast<Uns32T> (rowPtr->snext); // Cast pointer to unsigned int | 447 Uns32T numBuckets = rowPtr->snext.numBuckets; // Cast pointer to unsigned int |
448 Uns32T numPoints = rowPtr->t2 & 0x7FFFFFFF; // Value is stored in low 31 bits of t2 field | 448 Uns32T numPoints = rowPtr->t2 & 0x7FFFFFFF; // Value is stored in low 31 bits of t2 field |
449 bucket** listPtr = reinterpret_cast<bucket**> (reinterpret_cast<unsigned int*>(rowPtr->next)+numPoints+numBuckets+1); | 449 bucket** listPtr = reinterpret_cast<bucket**> (reinterpret_cast<unsigned int*>(rowPtr->next)+numPoints+numBuckets+1); |
450 return listPtr; | 450 return listPtr; |
451 } | 451 } |
452 | 452 |
878 } | 878 } |
879 | 879 |
880 void G::serial_merge_hashtable_row_format1(SerialElementT* pr, bucket* b, Uns32T& colCount){ | 880 void G::serial_merge_hashtable_row_format1(SerialElementT* pr, bucket* b, Uns32T& colCount){ |
881 while(b && b->t2!=IFLAG){ | 881 while(b && b->t2!=IFLAG){ |
882 SerialElementT*pe=pr; // reset disk pointer to beginning of row | 882 SerialElementT*pe=pr; // reset disk pointer to beginning of row |
883 serial_merge_element_format1(pe, b->snext, b->t2, colCount); | 883 serial_merge_element_format1(pe, b->snext.ptr, b->t2, colCount); |
884 b=b->next; | 884 b=b->next; |
885 } | 885 } |
886 } | 886 } |
887 | 887 |
888 void G::serial_merge_element_format1(SerialElementT* pe, sbucket* sb, Uns32T t2, Uns32T& colCount){ | 888 void G::serial_merge_element_format1(SerialElementT* pe, sbucket* sb, Uns32T t2, Uns32T& colCount){ |
910 } | 910 } |
911 | 911 |
912 void G::serial_write_hashtable_row_format1(SerialElementT*& pe, bucket* b, Uns32T& colCount){ | 912 void G::serial_write_hashtable_row_format1(SerialElementT*& pe, bucket* b, Uns32T& colCount){ |
913 pe->hashValue=IFLAG; | 913 pe->hashValue=IFLAG; |
914 while(b && b->t2!=IFLAG){ | 914 while(b && b->t2!=IFLAG){ |
915 serial_write_element_format1(pe, b->snext, b->t2, colCount); | 915 serial_write_element_format1(pe, b->snext.ptr, b->t2, colCount); |
916 b=b->next; | 916 b=b->next; |
917 } | 917 } |
918 } | 918 } |
919 | 919 |
920 void G::serial_write_element_format1(SerialElementT*& pe, sbucket* sb, Uns32T t2, Uns32T& colCount){ | 920 void G::serial_write_element_format1(SerialElementT*& pe, sbucket* sb, Uns32T t2, Uns32T& colCount){ |
1031 Uns32T G::count_points_hashtable_row(bucket* bPtr){ | 1031 Uns32T G::count_points_hashtable_row(bucket* bPtr){ |
1032 Uns32T point_count = 0; | 1032 Uns32T point_count = 0; |
1033 bucket* p = bPtr; | 1033 bucket* p = bPtr; |
1034 sbucket* s = 0; | 1034 sbucket* s = 0; |
1035 while(p){ | 1035 while(p){ |
1036 s = p->snext; | 1036 s = p->snext.ptr; |
1037 while(s){ | 1037 while(s){ |
1038 point_count++; | 1038 point_count++; |
1039 s=s->snext; | 1039 s=s->snext; |
1040 } | 1040 } |
1041 p=p->next; | 1041 p=p->next; |
1043 return point_count; | 1043 return point_count; |
1044 } | 1044 } |
1045 | 1045 |
1046 void G::serial_write_hashtable_row_format2(FILE* dbFile, bucket* b, Uns32T& colCount){ | 1046 void G::serial_write_hashtable_row_format2(FILE* dbFile, bucket* b, Uns32T& colCount){ |
1047 while(b && b->t2!=IFLAG){ | 1047 while(b && b->t2!=IFLAG){ |
1048 if(!b->snext){ | 1048 if(!b->snext.ptr){ |
1049 fclose(dbFile); | 1049 fclose(dbFile); |
1050 error("Empty collision chain in serial_write_hashtable_row_format2()"); | 1050 error("Empty collision chain in serial_write_hashtable_row_format2()"); |
1051 } | 1051 } |
1052 t2 = O2_SERIAL_TOKEN_T2; | 1052 t2 = O2_SERIAL_TOKEN_T2; |
1053 if( fwrite(&t2, sizeof(Uns32T), 1, dbFile) != 1 ){ | 1053 if( fwrite(&t2, sizeof(Uns32T), 1, dbFile) != 1 ){ |
1057 t2 = b->t2; | 1057 t2 = b->t2; |
1058 if( fwrite(&t2, sizeof(Uns32T), 1, dbFile) != 1 ){ | 1058 if( fwrite(&t2, sizeof(Uns32T), 1, dbFile) != 1 ){ |
1059 fclose(dbFile); | 1059 fclose(dbFile); |
1060 error("write error in serial_write_hashtable_row_format2()"); | 1060 error("write error in serial_write_hashtable_row_format2()"); |
1061 } | 1061 } |
1062 serial_write_element_format2(dbFile, b->snext, colCount); | 1062 serial_write_element_format2(dbFile, b->snext.ptr, colCount); |
1063 b=b->next; | 1063 b=b->next; |
1064 } | 1064 } |
1065 } | 1065 } |
1066 | 1066 |
1067 void G::serial_write_element_format2(FILE* dbFile, sbucket* sb, Uns32T& colCount){ | 1067 void G::serial_write_element_format2(FILE* dbFile, sbucket* sb, Uns32T& colCount){ |
1508 H::t2 = H::p; // Copy last found token to t2 | 1508 H::t2 = H::p; // Copy last found token to t2 |
1509 } | 1509 } |
1510 // Reallocate the row to its actual size | 1510 // Reallocate the row to its actual size |
1511 CR_ASSERT(rowPtr->next = (bucket*) realloc(rowPtr->next, (numBuckets+numPoints+1)*sizeof(Uns32T)+sizeof(bucket**))); | 1511 CR_ASSERT(rowPtr->next = (bucket*) realloc(rowPtr->next, (numBuckets+numPoints+1)*sizeof(Uns32T)+sizeof(bucket**))); |
1512 // Record the sizes at the head of the row | 1512 // Record the sizes at the head of the row |
1513 rowPtr->snext = (sbucket*) numBuckets; | 1513 rowPtr->snext.numBuckets = numBuckets; |
1514 rowPtr->t2 = numPoints; | 1514 rowPtr->t2 = numPoints; |
1515 // Place end of row marker | 1515 // Place end of row marker |
1516 *ap++ = LSH_CORE_ARRAY_END_ROW_TOKEN; | 1516 *ap++ = LSH_CORE_ARRAY_END_ROW_TOKEN; |
1517 // Set the LSH_CORE_ARRAY_BIT to identify data structure for insertion and retrieval | 1517 // Set the LSH_CORE_ARRAY_BIT to identify data structure for insertion and retrieval |
1518 rowPtr->t2 |= LSH_CORE_ARRAY_BIT; | 1518 rowPtr->t2 |= LSH_CORE_ARRAY_BIT; |
1560 }while( *p != LSH_CORE_ARRAY_END_ROW_TOKEN ); | 1560 }while( *p != LSH_CORE_ARRAY_END_ROW_TOKEN ); |
1561 } | 1561 } |
1562 | 1562 |
1563 void G::dump_hashtable_row(bucket* p){ | 1563 void G::dump_hashtable_row(bucket* p){ |
1564 while(p && p->t2!=IFLAG){ | 1564 while(p && p->t2!=IFLAG){ |
1565 sbucket* sbp = p->snext; | 1565 sbucket* sbp = p->snext.ptr; |
1566 while(sbp){ | 1566 while(sbp){ |
1567 printf("(%0X,%u)", p->t2, sbp->pointID); | 1567 printf("(%0X,%u)", p->t2, sbp->pointID); |
1568 fflush(stdout); | 1568 fflush(stdout); |
1569 sbp=sbp->snext; | 1569 sbp=sbp->snext; |
1570 } | 1570 } |
1707 | 1707 |
1708 void G::bucket_chain_point(bucket* p, Uns32T qpos){ | 1708 void G::bucket_chain_point(bucket* p, Uns32T qpos){ |
1709 if(!p || p->t2==IFLAG) | 1709 if(!p || p->t2==IFLAG) |
1710 return; | 1710 return; |
1711 if(p->t2==t2){ // match | 1711 if(p->t2==t2){ // match |
1712 sbucket_chain_point(p->snext, qpos); // add to reporter | 1712 sbucket_chain_point(p->snext.ptr, qpos); // add to reporter |
1713 } | 1713 } |
1714 if(p->next){ | 1714 if(p->next){ |
1715 bucket_chain_point(p->next, qpos); // recurse | 1715 bucket_chain_point(p->next, qpos); // recurse |
1716 } | 1716 } |
1717 } | 1717 } |