@@ -140,21 +140,24 @@ class CDBIterator
140140
141141 void SeekToFirst ();
142142
143- template <typename K> void Seek (const K& key) {
143+ template <typename K> void Seek (const K& key)
144+ {
144145 CDataStream ssKey (SER_DISK, CLIENT_VERSION);
145146 ssKey.reserve (DBWRAPPER_PREALLOC_KEY_SIZE);
146147 ssKey << key;
147148 Seek (ssKey);
148149 }
149150
150- void Seek (const CDataStream& ssKey) {
151+ void Seek (const CDataStream& ssKey)
152+ {
151153 leveldb::Slice slKey (ssKey.data (), ssKey.size ());
152154 piter->Seek (slKey);
153155 }
154156
155157 void Next ();
156158
157- template <typename K> bool GetKey (K& key) {
159+ template <typename K> bool GetKey (K& key)
160+ {
158161 try {
159162 CDataStream ssKey = GetKey ();
160163 ssKey >> key;
@@ -164,16 +167,19 @@ class CDBIterator
164167 return true ;
165168 }
166169
167- CDataStream GetKey () {
170+ CDataStream GetKey ()
171+ {
168172 leveldb::Slice slKey = piter->key ();
169173 return CDataStream (slKey.data (), slKey.data () + slKey.size (), SER_DISK, CLIENT_VERSION);
170174 }
171175
172- unsigned int GetKeySize () {
176+ unsigned int GetKeySize ()
177+ {
173178 return piter->key ().size ();
174179 }
175180
176- template <typename V> bool GetValue (V& value) {
181+ template <typename V> bool GetValue (V& value)
182+ {
177183 leveldb::Slice slValue = piter->value ();
178184 try {
179185 CDataStream ssValue (slValue.data (), slValue.data () + slValue.size (), SER_DISK, CLIENT_VERSION);
@@ -184,7 +190,8 @@ class CDBIterator
184190 return true ;
185191 }
186192
187- unsigned int GetValueSize () {
193+ unsigned int GetValueSize ()
194+ {
188195 return piter->value ().size ();
189196 }
190197
@@ -404,30 +411,35 @@ class CDBTransactionIterator
404411 parentIt = std::unique_ptr<ParentIterator>(transaction.parent .NewIterator ());
405412 }
406413
407- void SeekToFirst () {
414+ void SeekToFirst ()
415+ {
408416 transactionIt = transaction.writes .begin ();
409417 parentIt->SeekToFirst ();
410418 SkipDeletedAndOverwritten ();
411419 DecideCur ();
412420 }
413421
414422 template <typename K>
415- void Seek (const K& key) {
423+ void Seek (const K& key)
424+ {
416425 Seek (CDBTransaction::KeyToDataStream (key));
417426 }
418427
419- void Seek (const CDataStream& ssKey) {
428+ void Seek (const CDataStream& ssKey)
429+ {
420430 transactionIt = transaction.writes .lower_bound (ssKey);
421431 parentIt->Seek (ssKey);
422432 SkipDeletedAndOverwritten ();
423433 DecideCur ();
424434 }
425435
426- bool Valid () {
436+ bool Valid ()
437+ {
427438 return transactionIt != transaction.writes .end () || parentIt->Valid ();
428439 }
429440
430- void Next () {
441+ void Next ()
442+ {
431443 if (transactionIt == transaction.writes .end () && !parentIt->Valid ()) {
432444 return ;
433445 }
@@ -443,7 +455,8 @@ class CDBTransactionIterator
443455 }
444456
445457 template <typename K>
446- bool GetKey (K& key) {
458+ bool GetKey (K& key)
459+ {
447460 if (!Valid ()) {
448461 return false ;
449462 }
@@ -462,7 +475,8 @@ class CDBTransactionIterator
462475 }
463476 }
464477
465- CDataStream GetKey () {
478+ CDataStream GetKey ()
479+ {
466480 if (!Valid ()) {
467481 return CDataStream (SER_DISK, CLIENT_VERSION);
468482 }
@@ -473,7 +487,8 @@ class CDBTransactionIterator
473487 }
474488 }
475489
476- unsigned int GetKeySize () {
490+ unsigned int GetKeySize ()
491+ {
477492 if (!Valid ()) {
478493 return 0 ;
479494 }
@@ -485,7 +500,8 @@ class CDBTransactionIterator
485500 }
486501
487502 template <typename V>
488- bool GetValue (V& value) {
503+ bool GetValue (V& value)
504+ {
489505 if (!Valid ()) {
490506 return false ;
491507 }
@@ -497,7 +513,8 @@ class CDBTransactionIterator
497513 };
498514
499515private:
500- void SkipDeletedAndOverwritten () {
516+ void SkipDeletedAndOverwritten ()
517+ {
501518 while (parentIt->Valid ()) {
502519 parentKey = parentIt->GetKey ();
503520 if (!transaction.deletes .count (parentKey) && !transaction.writes .count (parentKey)) {
@@ -507,7 +524,8 @@ class CDBTransactionIterator
507524 }
508525 }
509526
510- void DecideCur () {
527+ void DecideCur ()
528+ {
511529 if (transactionIt != transaction.writes .end () && !parentIt->Valid ()) {
512530 curIsParent = false ;
513531 } else if (transactionIt == transaction.writes .end () && parentIt->Valid ()) {
@@ -532,14 +550,13 @@ class CDBTransaction {
532550 ssize_t memoryUsage{0 }; // signed, just in case we made an error in the calculations so that we don't get an overflow
533551
534552 struct DataStreamCmp {
535- static bool less (const CDataStream& a, const CDataStream& b) {
553+ static bool less (const CDataStream& a, const CDataStream& b)
554+ {
536555 return std::lexicographical_compare (
537556 (const uint8_t *)a.data (), (const uint8_t *)a.data () + a.size (),
538557 (const uint8_t *)b.data (), (const uint8_t *)b.data () + b.size ());
539558 }
540- bool operator ()(const CDataStream& a, const CDataStream& b) const {
541- return less (a, b);
542- }
559+ bool operator ()(const CDataStream& a, const CDataStream& b) const { return less (a, b); }
543560 };
544561
545562 struct ValueHolder {
@@ -554,7 +571,8 @@ class CDBTransaction {
554571 struct ValueHolderImpl : ValueHolder {
555572 ValueHolderImpl (const V &_value, size_t _memoryUsage) : ValueHolder(_memoryUsage), value(_value) {}
556573
557- virtual void Write (const CDataStream& ssKey, CommitTarget &commitTarget) {
574+ virtual void Write (const CDataStream& ssKey, CommitTarget &commitTarget)
575+ {
558576 // we're moving the value instead of copying it. This means that Write() can only be called once per
559577 // ValueHolderImpl instance. Commit() clears the write maps, so this ok.
560578 commitTarget.Write (ssKey, std::move (value));
@@ -563,7 +581,8 @@ class CDBTransaction {
563581 };
564582
565583 template <typename K>
566- static CDataStream KeyToDataStream (const K& key) {
584+ static CDataStream KeyToDataStream (const K& key)
585+ {
567586 CDataStream ssKey (SER_DISK, CLIENT_VERSION);
568587 ssKey.reserve (DBWRAPPER_PREALLOC_KEY_SIZE);
569588 ssKey << key;
@@ -580,12 +599,14 @@ class CDBTransaction {
580599 CDBTransaction (Parent &_parent, CommitTarget &_commitTarget) : parent(_parent), commitTarget(_commitTarget) {}
581600
582601 template <typename K, typename V>
583- void Write (const K& key, const V& v) {
602+ void Write (const K& key, const V& v)
603+ {
584604 Write (KeyToDataStream (key), v);
585605 }
586606
587607 template <typename V>
588- void Write (const CDataStream& ssKey, const V& v) {
608+ void Write (const CDataStream& ssKey, const V& v)
609+ {
589610 auto valueMemoryUsage = ::GetSerializeSize (v, SER_DISK, CLIENT_VERSION);
590611 if (deletes.erase (ssKey)) {
591612 memoryUsage -= ssKey.size ();
@@ -600,12 +621,14 @@ class CDBTransaction {
600621 }
601622
602623 template <typename K, typename V>
603- bool Read (const K& key, V& value) {
624+ bool Read (const K& key, V& value)
625+ {
604626 return Read (KeyToDataStream (key), value);
605627 }
606628
607629 template <typename V>
608- bool Read (const CDataStream& ssKey, V& value) {
630+ bool Read (const CDataStream& ssKey, V& value)
631+ {
609632 if (deletes.count (ssKey)) {
610633 return false ;
611634 }
@@ -624,11 +647,13 @@ class CDBTransaction {
624647 }
625648
626649 template <typename K>
627- bool Exists (const K& key) {
650+ bool Exists (const K& key)
651+ {
628652 return Exists (KeyToDataStream (key));
629653 }
630654
631- bool Exists (const CDataStream& ssKey) {
655+ bool Exists (const CDataStream& ssKey)
656+ {
632657 if (deletes.count (ssKey)) {
633658 return false ;
634659 }
@@ -641,11 +666,13 @@ class CDBTransaction {
641666 }
642667
643668 template <typename K>
644- void Erase (const K& key) {
669+ void Erase (const K& key)
670+ {
645671 return Erase (KeyToDataStream (key));
646672 }
647673
648- void Erase (const CDataStream& ssKey) {
674+ void Erase (const CDataStream& ssKey)
675+ {
649676 auto it = writes.find (ssKey);
650677 if (it != writes.end ()) {
651678 memoryUsage -= ssKey.size () + it->second ->memoryUsage ;
@@ -656,13 +683,15 @@ class CDBTransaction {
656683 }
657684 }
658685
659- void Clear () {
686+ void Clear ()
687+ {
660688 writes.clear ();
661689 deletes.clear ();
662690 memoryUsage = 0 ;
663691 }
664692
665- void Commit () {
693+ void Commit ()
694+ {
666695 for (const auto &k : deletes) {
667696 commitTarget.Erase (k);
668697 }
@@ -672,11 +701,13 @@ class CDBTransaction {
672701 Clear ();
673702 }
674703
675- bool IsClean () {
704+ bool IsClean ()
705+ {
676706 return writes.empty () && deletes.empty ();
677707 }
678708
679- size_t GetMemoryUsage () const {
709+ size_t GetMemoryUsage () const
710+ {
680711 if (memoryUsage < 0 ) {
681712 // something went wrong when we accounted/calculated used memory...
682713 static volatile bool didPrint = false ;
@@ -689,10 +720,12 @@ class CDBTransaction {
689720 return (size_t )memoryUsage;
690721 }
691722
692- CDBTransactionIterator<CDBTransaction>* NewIterator () {
723+ CDBTransactionIterator<CDBTransaction>* NewIterator ()
724+ {
693725 return new CDBTransactionIterator<CDBTransaction>(*this );
694726 }
695- std::unique_ptr<CDBTransactionIterator<CDBTransaction>> NewIteratorUniquePtr () {
727+ std::unique_ptr<CDBTransactionIterator<CDBTransaction>> NewIteratorUniquePtr ()
728+ {
696729 return std::make_unique<CDBTransactionIterator<CDBTransaction>>(*this );
697730 }
698731};
0 commit comments