MCPcopy Create free account
hub / github.com/chen3feng/toft / SeekKey

Method SeekKey

storage/sstable/reader/in_memory_sstable_reader.cpp:87–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87void InMemoryIterator::SeekKey(const std::string &key) {
88 bool found = false;
89 std::map<std::string, DataVector::iterator>::iterator it = sstable_->index_.find(key);
90 if (it != sstable_->index_.end()) {
91 cur_it_ = it->second;
92 found = true;
93 }
94 // FIXME(yesp) : is it right?
95 if (!found && (key < sstable_->data_.begin()->first)) {
96 cur_it_ = sstable_->data_.begin();
97 found = true;
98 }
99 if (!found && (key > sstable_->data_.back().first)) {
100 valid_ = false;
101 return;
102 }
103 if (!found) {
104 DataVector::size_type n = sstable_->data_.size();
105 unsigned int begin = 0;
106 unsigned int end = n - 1;
107 unsigned int mid = 0;
108 while (begin <= end) {
109 mid = (begin + end) / 2;
110 LOG(INFO)<< "begin:" << begin << ";mid:" << mid << ";end:" << end;
111 const std::pair<std::string, std::vector<std::string> >& midPair = sstable_->data_[mid];
112 if (midPair.first == key) {
113 break;
114 } else if (midPair.first < key) {
115 begin = mid + 1;
116 } else if (midPair.first > key) {
117 end = mid - 1;
118 }
119 }
120 cur_it_ = sstable_->data_.begin() + mid;
121 }
122 pos_ = 0;
123 size_ = cur_it_->second.size();
124 valid_ = true;
125 return;
126}
127
128} // namespace toft

Callers

nothing calls this directly

Calls 4

findMethod · 0.80
endMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected