18
18
#include " IndexSink.h"
19
19
#include " Log.h"
20
20
#include " StringView.h"
21
+ #include " PrettyBytes.h"
21
22
#include < sys/types.h>
22
23
#include < sys/stat.h>
23
24
#include < unistd.h>
@@ -59,7 +60,7 @@ size_t makeWindow(uint8_t *out, size_t outSize, const uint8_t *in,
59
60
return destLen;
60
61
}
61
62
62
- void uncompress (const std::vector <uint8_t > &compressed, uint8_t *to,
63
+ void uncompress (const std::vector<uint8_t > &compressed, uint8_t *to,
63
64
size_t len) {
64
65
uLongf destLen = len;
65
66
R (::uncompress (to, &len, &compressed[0 ], compressed.size ()));
@@ -325,7 +326,7 @@ Index::Index() { }
325
326
326
327
Index::~Index () { }
327
328
328
- Index::Index (std::unique_ptr < Impl > && imp) : impl_(std::move(imp)) { }
329
+ Index::Index (std::unique_ptr< Impl> &&imp) : impl_(std::move(imp)) { }
329
330
330
331
struct Index ::Builder::Impl : LineSink {
331
332
Log &log;
@@ -336,7 +337,7 @@ struct Index::Builder::Impl : LineSink {
336
337
Sqlite::Statement addIndexSql;
337
338
Sqlite::Statement addMetaSql;
338
339
uint64_t indexEvery = DefaultIndexEvery;
339
- std::unordered_map <std::string, std::unique_ptr<IndexHandler>> indexers;
340
+ std::unordered_map<std::string, std::unique_ptr<IndexHandler>> indexers;
340
341
341
342
Impl (Log &log, File &&from, const std::string &fromPath,
342
343
const std::string &indexFilename)
@@ -397,8 +398,8 @@ INSERT INTO Indexes VALUES(:name, :creationString, :isNumeric)
397
398
}
398
399
399
400
void build () {
400
- log .info (" Building index, generating a checkpoint every " , indexEvery,
401
- " bytes " );
401
+ log .info (" Building index, generating a checkpoint every " ,
402
+ PrettyBytes (indexEvery) );
402
403
struct stat compressedStat;
403
404
if (fstat (fileno (from.get ()), &compressedStat) != 0 )
404
405
throw ZlibError (Z_DATA_ERROR);
@@ -457,8 +458,9 @@ INSERT INTO LineOffsets VALUES(:line, :offset, :length))");
457
458
bool endOfBlock = zs.stream .data_type & 0x80 ;
458
459
bool lastBlockInStream = zs.stream .data_type & 0x40 ;
459
460
if (endOfBlock && !lastBlockInStream && needsIndex) {
460
- log .debug (" Creating checkpoint at " , totalOut,
461
- " (compressed offset " , totalIn, " )" );
461
+ log .debug (" Creating checkpoint at " , PrettyBytes (totalOut),
462
+ " (compressed offset " , PrettyBytes (totalIn),
463
+ " )" );
462
464
if (totalOut != 0 ) {
463
465
// Flush previous information.
464
466
addIndex
@@ -482,8 +484,8 @@ INSERT INTO LineOffsets VALUES(:line, :offset, :length))");
482
484
char pc[16 ];
483
485
snprintf (pc, sizeof (pc) - 1 , " %.2f" ,
484
486
(totalIn * 100.0 ) / compressedStat.st_size );
485
- log .info (" Progress: " , totalIn, " of " ,
486
- compressedStat.st_size ,
487
+ log .info (" Progress: " , PrettyBytes ( totalIn) , " of " ,
488
+ PrettyBytes ( compressedStat.st_size ) ,
487
489
" (" , pc, " %)" );
488
490
nextProgress = now + LogProgressEverySecs;
489
491
}
@@ -597,9 +599,9 @@ Index Index::load(Log &log, File &&fromCompressed,
597
599
Sqlite db (log );
598
600
db.open (indexFilename.c_str (), true );
599
601
600
- std::unique_ptr <Impl> impl (new Impl (log ,
601
- std::move (fromCompressed),
602
- std::move (db)));
602
+ std::unique_ptr<Impl> impl (new Impl (log ,
603
+ std::move (fromCompressed),
604
+ std::move (db)));
603
605
impl->init (forceLoad);
604
606
return Index (std::move (impl));
605
607
}
@@ -608,7 +610,7 @@ void Index::getLine(uint64_t line, LineSink &sink) {
608
610
impl_->getLine (line, sink);
609
611
}
610
612
611
- void Index::getLines (const std::vector <uint64_t > &lines, LineSink &sink) {
613
+ void Index::getLines (const std::vector<uint64_t > &lines, LineSink &sink) {
612
614
for (auto line : lines) impl_->getLine (line, sink);
613
615
}
614
616
@@ -618,7 +620,7 @@ void Index::queryIndex(const std::string &index, const std::string &query,
618
620
}
619
621
620
622
void Index::queryIndexMulti (const std::string &index,
621
- const std::vector <std::string> &queries,
623
+ const std::vector<std::string> &queries,
622
624
LineSink &sink) {
623
625
// TODO be a little smarter about this.
624
626
for (auto query : queries) impl_->queryIndex (index , query, sink);
0 commit comments