@nxtedition/rocksdb 10.0.10 → 10.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.cc +30 -23
- package/package.json +1 -1
package/binding.cc
CHANGED
|
@@ -323,30 +323,14 @@ struct BaseIterator : public Closable {
|
|
|
323
323
|
|
|
324
324
|
virtual ~BaseIterator() { assert(!iterator_); }
|
|
325
325
|
|
|
326
|
-
bool DidSeek() const { return iterator_ != nullptr
|
|
326
|
+
bool DidSeek() const { return iterator_ != nullptr; }
|
|
327
327
|
|
|
328
328
|
void SeekToRange() {
|
|
329
329
|
if (!iterator_) {
|
|
330
330
|
Init();
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (target) {
|
|
336
|
-
if ((upper_bound_ && target->compare(*upper_bound_) >= 0) ||
|
|
337
|
-
(lower_bound_ && target->compare(*lower_bound_) < 0)) {
|
|
338
|
-
// TODO (fix): Why is this required? Seek should handle it?
|
|
339
|
-
// https://github.com/facebook/rocksdb/issues/9904
|
|
340
|
-
iterator_->SeekToLast();
|
|
341
|
-
if (iterator_->Valid()) {
|
|
342
|
-
iterator_->Next();
|
|
343
|
-
}
|
|
344
|
-
} else if (reverse_) {
|
|
345
|
-
iterator_->SeekForPrev(*target);
|
|
346
|
-
} else {
|
|
347
|
-
iterator_->Seek(*target);
|
|
348
|
-
}
|
|
349
|
-
} else if (reverse_) {
|
|
333
|
+
if (reverse_) {
|
|
350
334
|
iterator_->SeekToLast();
|
|
351
335
|
} else {
|
|
352
336
|
iterator_->SeekToFirst();
|
|
@@ -354,8 +338,22 @@ struct BaseIterator : public Closable {
|
|
|
354
338
|
}
|
|
355
339
|
|
|
356
340
|
void Seek(const rocksdb::Slice& target) {
|
|
357
|
-
|
|
358
|
-
|
|
341
|
+
if (!iterator_) {
|
|
342
|
+
Init();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if ((upper_bound_ && target.compare(*upper_bound_) >= 0) || (lower_bound_ && target.compare(*lower_bound_) < 0)) {
|
|
346
|
+
// TODO (fix): Why is this required? Seek should handle it?
|
|
347
|
+
// https://github.com/facebook/rocksdb/issues/9904
|
|
348
|
+
iterator_->SeekToLast();
|
|
349
|
+
if (iterator_->Valid()) {
|
|
350
|
+
iterator_->Next();
|
|
351
|
+
}
|
|
352
|
+
} else if (reverse_) {
|
|
353
|
+
iterator_->SeekForPrev(target);
|
|
354
|
+
} else {
|
|
355
|
+
iterator_->Seek(target);
|
|
356
|
+
}
|
|
359
357
|
}
|
|
360
358
|
|
|
361
359
|
rocksdb::Status Close() override {
|
|
@@ -423,7 +421,6 @@ struct BaseIterator : public Closable {
|
|
|
423
421
|
int count_ = 0;
|
|
424
422
|
std::optional<rocksdb::PinnableSlice> lower_bound_;
|
|
425
423
|
std::optional<rocksdb::PinnableSlice> upper_bound_;
|
|
426
|
-
std::optional<rocksdb::PinnableSlice> target_;
|
|
427
424
|
std::unique_ptr<rocksdb::Iterator> iterator_;
|
|
428
425
|
const bool reverse_;
|
|
429
426
|
const int limit_;
|
|
@@ -1277,8 +1274,18 @@ NAPI_METHOD(iterator_seek) {
|
|
|
1277
1274
|
NapiSlice target;
|
|
1278
1275
|
NAPI_STATUS_THROWS(GetValue(env, argv[1], target));
|
|
1279
1276
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1277
|
+
struct State {};
|
|
1278
|
+
|
|
1279
|
+
runAsync<State>(
|
|
1280
|
+
std::string("leveldown.iterator.seek"), env, callback,
|
|
1281
|
+
[=](auto& state) {
|
|
1282
|
+
iterator->first_ = true;
|
|
1283
|
+
iterator->Seek(target);
|
|
1284
|
+
return iterator->Status();
|
|
1285
|
+
},
|
|
1286
|
+
[=](auto& state, auto env, auto& argv) {
|
|
1287
|
+
return napi_ok;
|
|
1288
|
+
});
|
|
1282
1289
|
|
|
1283
1290
|
return 0;
|
|
1284
1291
|
}
|