leveldb
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
leveldb::anonymous_namespace{merger.cc}::MergingIterator Class Reference
Inheritance diagram for leveldb::anonymous_namespace{merger.cc}::MergingIterator:
Inheritance graph
[legend]
Collaboration diagram for leveldb::anonymous_namespace{merger.cc}::MergingIterator:
Collaboration graph
[legend]

Public Member Functions

 MergingIterator (const Comparator *comparator, Iterator **children, int n)
 
virtual ~MergingIterator ()
 
virtual bool Valid () const
 
virtual void SeekToFirst ()
 
virtual void SeekToLast ()
 
virtual void Seek (const Slice &target)
 
virtual void Next ()
 
virtual void Prev ()
 
virtual Slice key () const
 
virtual Slice value () const
 
virtual Status status () const
 
- Public Member Functions inherited from leveldb::Iterator
 Iterator ()
 
virtual ~Iterator ()
 
void RegisterCleanup (CleanupFunction function, void *arg1, void *arg2)
 

Private Types

enum  Direction { kForward, kReverse }
 

Private Member Functions

void FindSmallest ()
 
void FindLargest ()
 

Private Attributes

const Comparatorcomparator_
 
IteratorWrapperchildren_
 
int n_
 
IteratorWrappercurrent_
 
Direction direction_
 

Additional Inherited Members

- Public Types inherited from leveldb::Iterator
typedef void(* CleanupFunction) (void *arg1, void *arg2)
 

Detailed Description

Definition at line 14 of file merger.cc.

Member Enumeration Documentation

§ Direction

enum leveldb::anonymous_namespace{merger.cc}::MergingIterator::Direction
private

Constructor & Destructor Documentation

§ MergingIterator()

leveldb::anonymous_namespace{merger.cc}::MergingIterator::MergingIterator ( const Comparator comparator,
Iterator **  children,
int  n 
)
inline

Definition at line 16 of file merger.cc.

§ ~MergingIterator()

virtual leveldb::anonymous_namespace{merger.cc}::MergingIterator::~MergingIterator ( )
inlinevirtual

Definition at line 27 of file merger.cc.

27  {
28  delete[] children_;
29  }

Member Function Documentation

§ FindLargest()

void leveldb::anonymous_namespace{merger.cc}::MergingIterator::FindLargest ( )
private

Definition at line 170 of file merger.cc.

170  {
171  IteratorWrapper* largest = NULL;
172  for (int i = n_-1; i >= 0; i--) {
173  IteratorWrapper* child = &children_[i];
174  if (child->Valid()) {
175  if (largest == NULL) {
176  largest = child;
177  } else if (comparator_->Compare(child->key(), largest->key()) > 0) {
178  largest = child;
179  }
180  }
181  }
182  current_ = largest;
183 }
virtual int Compare(const Slice &a, const Slice &b) const =0
Here is the call graph for this function:

§ FindSmallest()

void leveldb::anonymous_namespace{merger.cc}::MergingIterator::FindSmallest ( )
private

Definition at line 155 of file merger.cc.

155  {
156  IteratorWrapper* smallest = NULL;
157  for (int i = 0; i < n_; i++) {
158  IteratorWrapper* child = &children_[i];
159  if (child->Valid()) {
160  if (smallest == NULL) {
161  smallest = child;
162  } else if (comparator_->Compare(child->key(), smallest->key()) < 0) {
163  smallest = child;
164  }
165  }
166  }
167  current_ = smallest;
168 }
virtual int Compare(const Slice &a, const Slice &b) const =0
Here is the call graph for this function:

§ key()

virtual Slice leveldb::anonymous_namespace{merger.cc}::MergingIterator::key ( ) const
inlinevirtual

Implements leveldb::Iterator.

Definition at line 114 of file merger.cc.

114  {
115  assert(Valid());
116  return current_->key();
117  }

§ Next()

virtual void leveldb::anonymous_namespace{merger.cc}::MergingIterator::Next ( )
inlinevirtual

Implements leveldb::Iterator.

Definition at line 59 of file merger.cc.

59  {
60  assert(Valid());
61 
62  // Ensure that all children are positioned after key().
63  // If we are moving in the forward direction, it is already
64  // true for all of the non-current_ children since current_ is
65  // the smallest child and key() == current_->key(). Otherwise,
66  // we explicitly position the non-current_ children.
67  if (direction_ != kForward) {
68  for (int i = 0; i < n_; i++) {
69  IteratorWrapper* child = &children_[i];
70  if (child != current_) {
71  child->Seek(key());
72  if (child->Valid() &&
73  comparator_->Compare(key(), child->key()) == 0) {
74  child->Next();
75  }
76  }
77  }
79  }
80 
81  current_->Next();
82  FindSmallest();
83  }
void Seek(const Slice &k)
virtual int Compare(const Slice &a, const Slice &b) const =0
Here is the call graph for this function:

§ Prev()

virtual void leveldb::anonymous_namespace{merger.cc}::MergingIterator::Prev ( )
inlinevirtual

Implements leveldb::Iterator.

Definition at line 85 of file merger.cc.

85  {
86  assert(Valid());
87 
88  // Ensure that all children are positioned before key().
89  // If we are moving in the reverse direction, it is already
90  // true for all of the non-current_ children since current_ is
91  // the largest child and key() == current_->key(). Otherwise,
92  // we explicitly position the non-current_ children.
93  if (direction_ != kReverse) {
94  for (int i = 0; i < n_; i++) {
95  IteratorWrapper* child = &children_[i];
96  if (child != current_) {
97  child->Seek(key());
98  if (child->Valid()) {
99  // Child is at first entry >= key(). Step back one to be < key()
100  child->Prev();
101  } else {
102  // Child has no entries >= key(). Position at last entry.
103  child->SeekToLast();
104  }
105  }
106  }
108  }
109 
110  current_->Prev();
111  FindLargest();
112  }
void Seek(const Slice &k)
Here is the call graph for this function:

§ Seek()

virtual void leveldb::anonymous_namespace{merger.cc}::MergingIterator::Seek ( const Slice target)
inlinevirtual

§ SeekToFirst()

virtual void leveldb::anonymous_namespace{merger.cc}::MergingIterator::SeekToFirst ( )
inlinevirtual

§ SeekToLast()

virtual void leveldb::anonymous_namespace{merger.cc}::MergingIterator::SeekToLast ( )
inlinevirtual

§ status()

virtual Status leveldb::anonymous_namespace{merger.cc}::MergingIterator::status ( ) const
inlinevirtual

Implements leveldb::Iterator.

Definition at line 124 of file merger.cc.

124  {
125  Status status;
126  for (int i = 0; i < n_; i++) {
127  status = children_[i].status();
128  if (!status.ok()) {
129  break;
130  }
131  }
132  return status;
133  }
Here is the call graph for this function:

§ Valid()

virtual bool leveldb::anonymous_namespace{merger.cc}::MergingIterator::Valid ( ) const
inlinevirtual

Implements leveldb::Iterator.

Definition at line 31 of file merger.cc.

31  {
32  return (current_ != NULL);
33  }

§ value()

virtual Slice leveldb::anonymous_namespace{merger.cc}::MergingIterator::value ( ) const
inlinevirtual

Implements leveldb::Iterator.

Definition at line 119 of file merger.cc.

119  {
120  assert(Valid());
121  return current_->value();
122  }

Member Data Documentation

§ children_

IteratorWrapper* leveldb::anonymous_namespace{merger.cc}::MergingIterator::children_
private

Definition at line 143 of file merger.cc.

§ comparator_

const Comparator* leveldb::anonymous_namespace{merger.cc}::MergingIterator::comparator_
private

Definition at line 142 of file merger.cc.

§ current_

IteratorWrapper* leveldb::anonymous_namespace{merger.cc}::MergingIterator::current_
private

Definition at line 145 of file merger.cc.

§ direction_

Direction leveldb::anonymous_namespace{merger.cc}::MergingIterator::direction_
private

Definition at line 152 of file merger.cc.

§ n_

int leveldb::anonymous_namespace{merger.cc}::MergingIterator::n_
private

Definition at line 144 of file merger.cc.


The documentation for this class was generated from the following file: