Changeset View
Changeset View
Standalone View
Standalone View
src/engine/mtimedb.cpp
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | 126 | { | |||
---|---|---|---|---|---|
136 | if (rc != 0 && rc != MDB_NOTFOUND) { | 136 | if (rc != 0 && rc != MDB_NOTFOUND) { | ||
137 | qCWarning(ENGINE) << "MTimeDB::del" << mtime << docId << mdb_strerror(rc); | 137 | qCWarning(ENGINE) << "MTimeDB::del" << mtime << docId << mdb_strerror(rc); | ||
138 | } | 138 | } | ||
139 | } | 139 | } | ||
140 | 140 | | |||
141 | // | 141 | // | ||
142 | // Posting Iterator | 142 | // Posting Iterator | ||
143 | // | 143 | // | ||
144 | | ||||
145 | PostingIterator* MTimeDB::iter(quint32 mtime, MTimeDB::Comparator com) | | |||
146 | { | | |||
147 | if (com == Equal) { | | |||
148 | return new VectorPostingIterator(get(mtime)); | | |||
149 | } | | |||
150 | | ||||
151 | MDB_val key; | | |||
152 | key.mv_size = sizeof(quint32); | | |||
153 | key.mv_data = &mtime; | | |||
154 | | ||||
155 | MDB_cursor* cursor; | | |||
156 | mdb_cursor_open(m_txn, m_dbi, &cursor); | | |||
157 | | ||||
158 | MDB_val val{0, nullptr}; | | |||
159 | // Set cursor at first element greater or equal key | | |||
160 | int rc = mdb_cursor_get(cursor, &key, &val, MDB_SET_RANGE); | | |||
161 | if (com == LessEqual && rc == MDB_NOTFOUND) { | | |||
162 | rc = mdb_cursor_get(cursor, &key, &val, MDB_LAST); | | |||
163 | } | | |||
164 | if (rc) { | | |||
165 | if (rc != MDB_NOTFOUND) { | | |||
166 | qCWarning(ENGINE) << "MTimeDB::iter" << mtime << mdb_strerror(rc); | | |||
167 | } | | |||
168 | mdb_cursor_close(cursor); | | |||
169 | return nullptr; | | |||
170 | } | | |||
171 | | ||||
172 | QVector<quint64> results; | | |||
173 | | ||||
174 | if (com == GreaterEqual) { | | |||
175 | results << *static_cast<quint64*>(val.mv_data); | | |||
176 | while (1) { | | |||
177 | rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT); | | |||
178 | if (rc) { | | |||
179 | if (rc != MDB_NOTFOUND) { | | |||
180 | qCWarning(ENGINE) << "MTimeDB::iter GreaterEqual (loop)" << mtime << mdb_strerror(rc); | | |||
181 | } | | |||
182 | break; | | |||
183 | } | | |||
184 | | ||||
185 | results << *static_cast<quint64*>(val.mv_data); | | |||
186 | } | | |||
187 | } else { | | |||
188 | quint32 time = *static_cast<quint32*>(key.mv_data); | | |||
189 | if (time <= mtime) { | | |||
190 | // set cursor to last element equal key | | |||
191 | rc = mdb_cursor_get(cursor, &key, &val, MDB_LAST_DUP); | | |||
192 | } else { | | |||
193 | // set cursor to element less than key | | |||
194 | rc = mdb_cursor_get(cursor, &key, &val, MDB_PREV); | | |||
195 | } | | |||
196 | if (rc) { | | |||
197 | if (rc != MDB_NOTFOUND) { | | |||
198 | qCWarning(ENGINE) << "MTimeDB::iter LessEqual" << mtime << mdb_strerror(rc); | | |||
199 | } else { | | |||
200 | return nullptr; | | |||
201 | } | | |||
202 | } | | |||
203 | results << *static_cast<quint64*>(val.mv_data); | | |||
204 | while (1) { | | |||
205 | rc = mdb_cursor_get(cursor, &key, &val, MDB_PREV); | | |||
206 | if (rc) { | | |||
207 | if (rc != MDB_NOTFOUND) { | | |||
208 | qCWarning(ENGINE) << "MTimeDB::iter LessEqual (loop)" << mtime << mdb_strerror(rc); | | |||
209 | } | | |||
210 | break; | | |||
211 | } | | |||
212 | | ||||
213 | quint64 id = *static_cast<quint64*>(val.mv_data); | | |||
214 | results.push_front(id); | | |||
215 | } | | |||
216 | } | | |||
217 | | ||||
218 | mdb_cursor_close(cursor); | | |||
219 | std::sort(results.begin(), results.end()); | | |||
220 | results.erase(std::unique(results.begin(), results.end()), results.end()); | | |||
221 | return new VectorPostingIterator(results); | | |||
222 | } | | |||
223 | | ||||
224 | PostingIterator* MTimeDB::iterRange(quint32 beginTime, quint32 endTime) | 144 | PostingIterator* MTimeDB::iterRange(quint32 beginTime, quint32 endTime) | ||
225 | { | 145 | { | ||
226 | if (endTime < beginTime) { | 146 | if (endTime < beginTime) { | ||
227 | return nullptr; | 147 | return nullptr; | ||
228 | } | 148 | } | ||
229 | 149 | | |||
230 | MDB_val key; | 150 | MDB_val key; | ||
231 | key.mv_size = sizeof(quint32); | 151 | key.mv_size = sizeof(quint32); | ||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |