aboutsummaryrefslogtreecommitdiff
path: root/src/stable/myriad.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/stable/myriad.cpp66
1 files changed, 45 insertions, 21 deletions
diff --git a/src/stable/myriad.cpp b/src/stable/myriad.cpp
index eba1ebf..85daa0d 100644
--- a/src/stable/myriad.cpp
+++ b/src/stable/myriad.cpp
@@ -252,6 +252,41 @@ int32_t Bu::Myriad::getTotalUnusedBytes(int32_t iAssumeBlockSize ) const
252 return iTotal; 252 return iTotal;
253} 253}
254 254
255Bu::BitString Bu::Myriad::buildBlockUseMap() const
256{
257 Bu::MutexLocker l( mAccess );
258 Bu::BitString bsMap( iBlockCount );
259 bsMap.fill();
260 for( IndexList::const_iterator i = lFreeBlocks.begin(); i; i++ )
261 {
262 bsMap.setBit( *i, false );
263 }
264 return bsMap;
265}
266
267Bu::Array<int32_t> Bu::Myriad::buildBlockMap() const
268{
269 Bu::MutexLocker l( mAccess );
270 Bu::Array<int32_t> bm( iBlockCount );
271 for( int j = 0; j < iBlockCount; j++ )
272 {
273 bm.append( -1 );
274 }
275 Bu::MutexLocker l2( mhStream );
276 for( StreamHash::const_iterator iStream = hStream.begin();
277 iStream; iStream++ )
278 {
279 int32_t iId = iStream.getKey();
280 Stream *pStream = iStream.getValue();
281 for( Bu::Array<int32_t>::const_iterator iBlock =
282 pStream->aBlocks.begin(); iBlock; iBlock++ )
283 {
284 bm[*iBlock] = iId;
285 }
286 }
287 return bm;
288}
289
255void Bu::Myriad::sync() 290void Bu::Myriad::sync()
256{ 291{
257 writeHeader(); 292 writeHeader();
@@ -259,7 +294,7 @@ void Bu::Myriad::sync()
259 294
260bool Bu::Myriad::loadMyriad() 295bool Bu::Myriad::loadMyriad()
261{ 296{
262 Bu::println("Load myriad!"); 297 //Bu::println("Load myriad!");
263 char sMagicCode[4]; 298 char sMagicCode[4];
264 rBacking.setPos( 0 ); 299 rBacking.setPos( 0 );
265 MyriadRead( sMagicCode, 4 ); 300 MyriadRead( sMagicCode, 4 );
@@ -362,7 +397,7 @@ bool Bu::Myriad::loadMyriad()
362 } 397 }
363 398
364 lFreeBlocks = hUnusedBlocks.getKeys(); 399 lFreeBlocks = hUnusedBlocks.getKeys();
365 Bu::println("Free blocks: %1").arg( lFreeBlocks.getSize() ); 400 //Bu::println("Free blocks: %1").arg( lFreeBlocks.getSize() );
366 401
367 return true; 402 return true;
368} 403}
@@ -389,22 +424,14 @@ void Bu::Myriad::createMyriad( int32_t iBlockSize, int32_t iPreallocateBlocks )
389 // plus one block index. 424 // plus one block index.
390 int iHeaderStreamBlocks = blkDiv(iHeaderStreamBytes+4, iBlockSize ); 425 int iHeaderStreamBlocks = blkDiv(iHeaderStreamBytes+4, iBlockSize );
391 426
392 Bu::println("Initial estimate: %1 bytes / %2 cur blocks, %3 computed blocks (%4 target bytes).") 427 //Bu::println("Initial estimate: %1 bytes / %2 cur blocks, %3 computed blocks (%4 target bytes).").arg( iHeaderStreamBytes+(iHeaderStreamBlocks*4) ).arg( iHeaderStreamBlocks ).arg( blkDiv((iHeaderStreamBytes+(iHeaderStreamBlocks*4)), iBlockSize) ).arg( iHeaderStreamBlocks*iBlockSize );
393 .arg( iHeaderStreamBytes+(iHeaderStreamBlocks*4) )
394 .arg( iHeaderStreamBlocks )
395 .arg( blkDiv((iHeaderStreamBytes+(iHeaderStreamBlocks*4)), iBlockSize) )
396 .arg( iHeaderStreamBlocks*iBlockSize );
397 while( iHeaderStreamBytes+(iHeaderStreamBlocks*4) 428 while( iHeaderStreamBytes+(iHeaderStreamBlocks*4)
398 > iHeaderStreamBlocks*iBlockSize ) 429 > iHeaderStreamBlocks*iBlockSize )
399 { 430 {
400 iHeaderStreamBlocks = blkDiv((iHeaderStreamBytes+((iHeaderStreamBlocks+1)*4)), iBlockSize); 431 iHeaderStreamBlocks = blkDiv((iHeaderStreamBytes+((iHeaderStreamBlocks+1)*4)), iBlockSize);
401 if( iHeaderStreamBlocks > 100 ) 432 if( iHeaderStreamBlocks > 100 )
402 break; 433 break;
403 Bu::println(" Adjustment: %1 bytes / %2 cur blocks, %3 computed blocks (%4 target bytes).") 434 //Bu::println(" Adjustment: %1 bytes / %2 cur blocks, %3 computed blocks (%4 target bytes).").arg( iHeaderStreamBytes+(iHeaderStreamBlocks*4) ).arg( iHeaderStreamBlocks ).arg( blkDiv((iHeaderStreamBytes+(iHeaderStreamBlocks*4)), iBlockSize) ).arg( iHeaderStreamBlocks*iBlockSize );
404 .arg( iHeaderStreamBytes+(iHeaderStreamBlocks*4) )
405 .arg( iHeaderStreamBlocks )
406 .arg( blkDiv((iHeaderStreamBytes+(iHeaderStreamBlocks*4)), iBlockSize) )
407 .arg( iHeaderStreamBlocks*iBlockSize );
408 } 435 }
409 436
410 if( iPreallocateBlocks > iHeaderStreamBlocks ) 437 if( iPreallocateBlocks > iHeaderStreamBlocks )
@@ -459,7 +486,7 @@ void Bu::Myriad::writeHeader()
459 Bu::MutexLocker l( mAccess ); 486 Bu::MutexLocker l( mAccess );
460 if( !rBacking.isWritable() ) 487 if( !rBacking.isWritable() )
461 return; 488 return;
462 Bu::println("Writing stream breakdown:"); 489 //Bu::println("Writing stream breakdown:");
463 Bu::MemBuf mbHeader; 490 Bu::MemBuf mbHeader;
464 { 491 {
465 Bu::MutexLocker l2( mhStream ); 492 Bu::MutexLocker l2( mhStream );
@@ -488,7 +515,7 @@ void Bu::Myriad::writeHeader()
488 psHeader->iSize = iHdrStreamSize; 515 psHeader->iSize = iHdrStreamSize;
489 } 516 }
490 517
491 Bu::println("Computed header size: %1 bytes. Ver=%2, Bpi=%3, BlockSize=%4").arg( iHdrStreamSize ).arg( 1 ).arg( 32 ).arg( iBlockSize ); 518 //Bu::println("Computed header size: %1 bytes. Ver=%2, Bpi=%3, BlockSize=%4").arg( iHdrStreamSize ).arg( 1 ).arg( 32 ).arg( iBlockSize );
492 519
493 uint8_t uVer = 1; 520 uint8_t uVer = 1;
494 uint8_t uBpi = 32; 521 uint8_t uBpi = 32;
@@ -515,10 +542,7 @@ void Bu::Myriad::writeHeader()
515 mbHeader.write( &uStreamSize, 4 ); 542 mbHeader.write( &uStreamSize, 4 );
516 Bu::Array<int32_t> aBlocks = pStream->getBlockList(); 543 Bu::Array<int32_t> aBlocks = pStream->getBlockList();
517 544
518 Bu::println(" Stream %1 is %2 bytes %3 blocks (%4 blocks computed)") 545 //Bu::println(" Stream %1 is %2 bytes %3 blocks (%4 blocks computed)").arg( *i ).arg( uStreamSize ).arg( aBlocks.getSize() ).arg( Bu::blkDiv( (int)uStreamSize, (int)iBlockSize ) );
519 .arg( *i ).arg( uStreamSize )
520 .arg( aBlocks.getSize() )
521 .arg( Bu::blkDiv( (int)uStreamSize, (int)iBlockSize ) );
522 546
523 for( Bu::Array<int32_t>::iterator i = aBlocks.begin(); i; i++ ) 547 for( Bu::Array<int32_t>::iterator i = aBlocks.begin(); i; i++ )
524 { 548 {
@@ -556,15 +580,15 @@ int32_t Bu::Myriad::__calcHeaderSize()
556 } 580 }
557 } 581 }
558 582
559 Bu::println("HeaderCalc:"); 583 //Bu::println("HeaderCalc:");
560 Bu::println(" Base (no header stream): %1").arg( iHdrSize ); 584 //Bu::println(" Base (no header stream): %1").arg( iHdrSize );
561 int32_t iNewSize = iHdrSize; 585 int32_t iNewSize = iHdrSize;
562 int32_t iOldSize; 586 int32_t iOldSize;
563 587
564 do { 588 do {
565 iOldSize = iNewSize; 589 iOldSize = iNewSize;
566 iNewSize = iHdrSize + Bu::blkDiv(iNewSize, iBlockSize)*4; 590 iNewSize = iHdrSize + Bu::blkDiv(iNewSize, iBlockSize)*4;
567 Bu::println(" Recomp: %1").arg( iNewSize ); 591 //Bu::println(" Recomp: %1").arg( iNewSize );
568 } while( iOldSize != iNewSize ); 592 } while( iOldSize != iNewSize );
569 593
570 return iNewSize; 594 return iNewSize;