@ -89,7 +89,7 @@ struct STLLessThan {
class StringSink : public WritableFile {
class StringSink : public WritableFile {
public :
public :
~ StringSink ( ) { }
~ StringSink ( ) = default ;
const std : : string & contents ( ) const { return contents_ ; }
const std : : string & contents ( ) const { return contents_ ; }
@ -111,7 +111,7 @@ class StringSource : public RandomAccessFile {
StringSource ( const Slice & contents )
StringSource ( const Slice & contents )
: contents_ ( contents . data ( ) , contents . size ( ) ) { }
: contents_ ( contents . data ( ) , contents . size ( ) ) { }
virtual ~ StringSource ( ) { }
virtual ~ StringSource ( ) = default ;
uint64_t Size ( ) const { return contents_ . size ( ) ; }
uint64_t Size ( ) const { return contents_ . size ( ) ; }
@ -139,7 +139,7 @@ typedef std::map KVMap;
class Constructor {
class Constructor {
public :
public :
explicit Constructor ( const Comparator * cmp ) : data_ ( STLLessThan ( cmp ) ) { }
explicit Constructor ( const Comparator * cmp ) : data_ ( STLLessThan ( cmp ) ) { }
virtual ~ Constructor ( ) { }
virtual ~ Constructor ( ) = default ;
void Add ( const std : : string & key , const Slice & value ) {
void Add ( const std : : string & key , const Slice & value ) {
data_ [ key ] = value . ToString ( ) ;
data_ [ key ] = value . ToString ( ) ;
@ -152,8 +152,8 @@ class Constructor {
KVMap * kvmap ) {
KVMap * kvmap ) {
* kvmap = data_ ;
* kvmap = data_ ;
keys - > clear ( ) ;
keys - > clear ( ) ;
for ( KVMap : : const_iterator it = data_ . begin ( ) ; it ! = data_ . end ( ) ; + + it ) {
keys - > push_back ( it - > first ) ;
for ( const auto & kvp : data_ ) {
keys - > push_back ( kvp . first ) ;
}
}
data_ . clear ( ) ;
data_ . clear ( ) ;
Status s = FinishImpl ( options , * kvmap ) ;
Status s = FinishImpl ( options , * kvmap ) ;
@ -165,7 +165,7 @@ class Constructor {
virtual Iterator * NewIterator ( ) const = 0 ;
virtual Iterator * NewIterator ( ) const = 0 ;
virtual const KVMap & data ( ) { return data_ ; }
const KVMap & data ( ) const { return data_ ; }
virtual DB * db ( ) const { return nullptr ; } // Overridden in DBConstructor
virtual DB * db ( ) const { return nullptr ; } // Overridden in DBConstructor
@ -177,14 +177,14 @@ class BlockConstructor : public Constructor {
public :
public :
explicit BlockConstructor ( const Comparator * cmp )
explicit BlockConstructor ( const Comparator * cmp )
: Constructor ( cmp ) , comparator_ ( cmp ) , block_ ( nullptr ) { }
: Constructor ( cmp ) , comparator_ ( cmp ) , block_ ( nullptr ) { }
~ BlockConstructor ( ) { delete block_ ; }
virtual Status FinishImpl ( const Options & options , const KVMap & data ) {
~ BlockConstructor ( ) override { delete block_ ; }
Status FinishImpl ( const Options & options , const KVMap & data ) override {
delete block_ ;
delete block_ ;
block_ = nullptr ;
block_ = nullptr ;
BlockBuilder builder ( & options ) ;
BlockBuilder builder ( & options ) ;
for ( KVMap : : const_iterator it = data . begin ( ) ; it ! = data . end ( ) ; + + it ) {
builder . Add ( it - > first , it - > second ) ;
for ( const auto & kvp : data ) {
builder . Add ( kvp . first , kvp . second ) ;
}
}
// Open the block
// Open the block
data_ = builder . Finish ( ) . ToString ( ) ;
data_ = builder . Finish ( ) . ToString ( ) ;
@ -195,12 +195,12 @@ class BlockConstructor : public Constructor {
block_ = new Block ( contents ) ;
block_ = new Block ( contents ) ;
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
virtual Iterator * NewIterator ( ) const {
Iterator * NewIterator ( ) const override {
return block_ - > NewIterator ( comparator_ ) ;
return block_ - > NewIterator ( comparator_ ) ;
}
}
private :
private :
const Comparator * comparator_ ;
const Comparator * const comparator_ ;
std : : string data_ ;
std : : string data_ ;
Block * block_ ;
Block * block_ ;
@ -211,14 +211,14 @@ class TableConstructor : public Constructor {
public :
public :
TableConstructor ( const Comparator * cmp )
TableConstructor ( const Comparator * cmp )
: Constructor ( cmp ) , source_ ( nullptr ) , table_ ( nullptr ) { }
: Constructor ( cmp ) , source_ ( nullptr ) , table_ ( nullptr ) { }
~ TableConstructor ( ) { Reset ( ) ; }
virtual Status FinishImpl ( const Options & options , const KVMap & data ) {
~ TableConstructor ( ) override { Reset ( ) ; }
Status FinishImpl ( const Options & options , const KVMap & data ) override {
Reset ( ) ;
Reset ( ) ;
StringSink sink ;
StringSink sink ;
TableBuilder builder ( options , & sink ) ;
TableBuilder builder ( options , & sink ) ;
for ( KVMap : : const_iterator it = data . begin ( ) ; it ! = data . end ( ) ; + + it ) {
builder . Add ( it - > first , it - > second ) ;
for ( const auto & kvp : data ) {
builder . Add ( kvp . first , kvp . second ) ;
ASSERT_TRUE ( builder . status ( ) . ok ( ) ) ;
ASSERT_TRUE ( builder . status ( ) . ok ( ) ) ;
}
}
Status s = builder . Finish ( ) ;
Status s = builder . Finish ( ) ;
@ -233,7 +233,7 @@ class TableConstructor : public Constructor {
return Table : : Open ( table_options , source_ , sink . contents ( ) . size ( ) , & table_ ) ;
return Table : : Open ( table_options , source_ , sink . contents ( ) . size ( ) , & table_ ) ;
}
}
virtual Iterator * NewIterator ( ) const {
Iterator * NewIterator ( ) const override {
return table_ - > NewIterator ( ReadOptions ( ) ) ;
return table_ - > NewIterator ( ReadOptions ( ) ) ;
}
}
@ -259,20 +259,25 @@ class TableConstructor : public Constructor {
class KeyConvertingIterator : public Iterator {
class KeyConvertingIterator : public Iterator {
public :
public :
explicit KeyConvertingIterator ( Iterator * iter ) : iter_ ( iter ) { }
explicit KeyConvertingIterator ( Iterator * iter ) : iter_ ( iter ) { }
virtual ~ KeyConvertingIterator ( ) { delete iter_ ; }
virtual bool Valid ( ) const { return iter_ - > Valid ( ) ; }
virtual void Seek ( const Slice & target ) {
KeyConvertingIterator ( const KeyConvertingIterator & ) = delete ;
KeyConvertingIterator & operator = ( const KeyConvertingIterator & ) = delete ;
~ KeyConvertingIterator ( ) override { delete iter_ ; }
bool Valid ( ) const override { return iter_ - > Valid ( ) ; }
void Seek ( const Slice & target ) override {
ParsedInternalKey ikey ( target , kMaxSequenceNumber , kTypeValue ) ;
ParsedInternalKey ikey ( target , kMaxSequenceNumber , kTypeValue ) ;
std : : string encoded ;
std : : string encoded ;
AppendInternalKey ( & encoded , ikey ) ;
AppendInternalKey ( & encoded , ikey ) ;
iter_ - > Seek ( encoded ) ;
iter_ - > Seek ( encoded ) ;
}
}
virtual void SeekToFirst ( ) { iter_ - > SeekToFirst ( ) ; }
virtual void SeekToLast ( ) { iter_ - > SeekToLast ( ) ; }
virtual void Next ( ) { iter_ - > Next ( ) ; }
virtual void Prev ( ) { iter_ - > Prev ( ) ; }
void SeekToFirst ( ) override { iter_ - > SeekToFirst ( ) ; }
void SeekToLast ( ) override { iter_ - > SeekToLast ( ) ; }
void Next ( ) override { iter_ - > Next ( ) ; }
void Prev ( ) override { iter_ - > Prev ( ) ; }
virtual Slice key ( ) const {
Slice key ( ) const override {
assert ( Valid ( ) ) ;
assert ( Valid ( ) ) ;
ParsedInternalKey key ;
ParsedInternalKey key ;
if ( ! ParseInternalKey ( iter_ - > key ( ) , & key ) ) {
if ( ! ParseInternalKey ( iter_ - > key ( ) , & key ) ) {
@ -282,18 +287,14 @@ class KeyConvertingIterator : public Iterator {
return key . user_key ;
return key . user_key ;
}
}
virtual Slice value ( ) const { return iter_ - > value ( ) ; }
virtual Status status ( ) const {
Slice value ( ) const override { return iter_ - > value ( ) ; }
Status status ( ) const override {
return status_ . ok ( ) ? iter_ - > status ( ) : status_ ;
return status_ . ok ( ) ? iter_ - > status ( ) : status_ ;
}
}
private :
private :
mutable Status status_ ;
mutable Status status_ ;
Iterator * iter_ ;
Iterator * iter_ ;
// No copying allowed
KeyConvertingIterator ( const KeyConvertingIterator & ) ;
void operator = ( const KeyConvertingIterator & ) ;
} ;
} ;
class MemTableConstructor : public Constructor {
class MemTableConstructor : public Constructor {
@ -303,24 +304,24 @@ class MemTableConstructor : public Constructor {
memtable_ = new MemTable ( internal_comparator_ ) ;
memtable_ = new MemTable ( internal_comparator_ ) ;
memtable_ - > Ref ( ) ;
memtable_ - > Ref ( ) ;
}
}
~ MemTableConstructor ( ) { memtable_ - > Unref ( ) ; }
virtual Status FinishImpl ( const Options & options , const KVMap & data ) {
~ MemTableConstructor ( ) override { memtable_ - > Unref ( ) ; }
Status FinishImpl ( const Options & options , const KVMap & data ) override {
memtable_ - > Unref ( ) ;
memtable_ - > Unref ( ) ;
memtable_ = new MemTable ( internal_comparator_ ) ;
memtable_ = new MemTable ( internal_comparator_ ) ;
memtable_ - > Ref ( ) ;
memtable_ - > Ref ( ) ;
int seq = 1 ;
int seq = 1 ;
for ( KVMap : : const_iterator it = data . begin ( ) ; it ! = data . end ( ) ; + + it ) {
memtable_ - > Add ( seq , kTypeValue , it - > first , it - > second ) ;
for ( const auto & kvp : data ) {
memtable_ - > Add ( seq , kTypeValue , kvp . first , kvp . second ) ;
seq + + ;
seq + + ;
}
}
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
virtual Iterator * NewIterator ( ) const {
Iterator * NewIterator ( ) const override {
return new KeyConvertingIterator ( memtable_ - > NewIterator ( ) ) ;
return new KeyConvertingIterator ( memtable_ - > NewIterator ( ) ) ;
}
}
private :
private :
InternalKeyComparator internal_comparator_ ;
const InternalKeyComparator internal_comparator_ ;
MemTable * memtable_ ;
MemTable * memtable_ ;
} ;
} ;
@ -331,23 +332,23 @@ class DBConstructor : public Constructor {
db_ = nullptr ;
db_ = nullptr ;
NewDB ( ) ;
NewDB ( ) ;
}
}
~ DBConstructor ( ) { delete db_ ; }
virtual Status FinishImpl ( const Options & options , const KVMap & data ) {
~ DBConstructor ( ) override { delete db_ ; }
Status FinishImpl ( const Options & options , const KVMap & data ) override {
delete db_ ;
delete db_ ;
db_ = nullptr ;
db_ = nullptr ;
NewDB ( ) ;
NewDB ( ) ;
for ( KVMap : : const_iterator it = data . begin ( ) ; it ! = data . end ( ) ; + + it ) {
for ( const auto & kvp : data ) {
WriteBatch batch ;
WriteBatch batch ;
batch . Put ( it - > first , it - > second ) ;
batch . Put ( kvp . first , kvp . second ) ;
ASSERT_TRUE ( db_ - > Write ( WriteOptions ( ) , & batch ) . ok ( ) ) ;
ASSERT_TRUE ( db_ - > Write ( WriteOptions ( ) , & batch ) . ok ( ) ) ;
}
}
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
virtual Iterator * NewIterator ( ) const {
Iterator * NewIterator ( ) const override {
return db_ - > NewIterator ( ReadOptions ( ) ) ;
return db_ - > NewIterator ( ReadOptions ( ) ) ;
}
}
virtual DB * db ( ) const { return db_ ; }
DB * db ( ) const override { return db_ ; }
private :
private :
void NewDB ( ) {
void NewDB ( ) {
@ -365,7 +366,7 @@ class DBConstructor : public Constructor {
ASSERT_TRUE ( status . ok ( ) ) < < status . ToString ( ) ;
ASSERT_TRUE ( status . ok ( ) ) < < status . ToString ( ) ;
}
}
const Comparator * comparator_ ;
const Comparator * const comparator_ ;
DB * db_ ;
DB * db_ ;
} ;
} ;