void testSetEndPosition_Restore_Reverse(bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( unique, { {key1, loc1}, {key2, loc1}, {key3, loc1}, {key4, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key2, false); // Should never see key1 or key2. ASSERT_EQ(cursor->seek(key4, true), IndexKeyEntry(key4, loc1)); cursor->save(); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc1)); cursor->save(); removeFromIndex(opCtx, sorted, { {key2, loc1}, {key3, loc1}, }); cursor->restore(); ASSERT_EQ(cursor->next(), boost::none); }
bool RSpatialIndexNavel::removeFromIndex(int id, const QList<RBox>& bb) { //bool ok = true; // QList<int> sids = idToSid.value(id); // qDebug() << "bb.size(): " << bb.size(); // qDebug() << "sids.size(): " << sids.size(); // if (bb.size()!=sids.size()) { // qWarning() << "RSpatialIndexNavel::removeFromIndex: no remove..."; // return; // } //Q_ASSERT(bb.size()==sids.size()); bool ok = true; for (int pos = 0; pos < bb.size(); ++pos) { ok = removeFromIndex(id, pos, bb[pos]) && ok; } //idToSid.remove(id); //if (!ok) { // TODO: //removeFromIndex(id); //} return ok; }
bool RSpatialIndex::removeFromIndex(int id, int pos, const RBox& bb) { return removeFromIndex( id, pos, bb.c1.x, bb.c1.y, bb.c1.z, bb.c2.x, bb.c2.y, bb.c2.z ); }
void testSetEndPosition_Seek_Reverse(bool unique, bool inclusive) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key1, loc1}, {key2, loc1}, // No key3 {key4, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key2, inclusive); // Directly seeking past end is considered out of range. ASSERT_EQ(cursor->seek(key1, true), boost::none); ASSERT_EQ(cursor->seekExact(key1), boost::none); // Seeking to key2 directly or indirectly is only returned if endPosition is inclusive. auto maybeKey2 = inclusive ? boost::make_optional(IndexKeyEntry(key2, loc1)) : boost::none; // direct ASSERT_EQ(cursor->seek(key2, true), maybeKey2); ASSERT_EQ(cursor->seekExact(key2), maybeKey2); // indirect ASSERT_EQ(cursor->seek(key3, true), maybeKey2); cursor->saveUnpositioned(); removeFromIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(); ASSERT_EQ(cursor->seek(key3, true), boost::none); ASSERT_EQ(cursor->seek(key2, true), boost::none); }
// Make sure we restore to a RecordId at or ahead of save point if same key on reverse cursor. void testSaveAndRestorePositionConsidersRecordId_Reverse(bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key0, loc1}, {key1, loc1}, {key2, loc2}, }); auto cursor = sorted->newCursor(opCtx.get(), false); ASSERT_EQ(cursor->seek(key2, true), IndexKeyEntry(key2, loc2)); cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key2, loc2}}); insertToIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key2, loc1}}); insertToIndex(opCtx, sorted, {{key2, loc2}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->next(), IndexKeyEntry(key1, loc1)); cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key1, loc1}}); cursor->restore(opCtx.get()); cursor->savePositioned(); insertToIndex(opCtx, sorted, {{key1, loc1}}); cursor->restore(opCtx.get()); // Lands at same point as initial save. // Advances from restore point since restore didn't move position. ASSERT_EQ(cursor->next(), IndexKeyEntry(key0, loc1)); }
bool RSpatialIndex::removeFromIndex(int id, const QList<RBox>& bb) { bool ok = true; for (int pos = 0; pos < bb.size(); ++pos) { ok = removeFromIndex(id, pos, bb.at(pos)) && ok; } return ok; //if (!ok) { // TODO: //removeFromIndex(id); //} }
// Ensure that SaveUnpositioned allows later use of the cursor. TEST(SortedDataInterface, SaveUnpositionedAndRestore) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(false, { {key1, loc1}, {key2, loc1}, {key3, loc1}, }); auto cursor = sorted->newCursor(opCtx.get()); ASSERT_EQ(cursor->seek(key2, true), IndexKeyEntry(key2, loc1)); cursor->saveUnpositioned(); removeFromIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->seek(key1, true), IndexKeyEntry(key1, loc1)); cursor->saveUnpositioned(); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->seek(key3, true), IndexKeyEntry(key3, loc1)); }
// Ensure that repeated restores lands as close as possible to original position, even if data // inserted while saved and the current position removed in a way that temporarily makes the // cursor EOF. void testSaveAndRestorePositionSeesNewInsertsAfterEOF(bool forward, bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(false, { {key1, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), forward); ASSERT_EQ(cursor->seek(key1, true), IndexKeyEntry(key1, loc1)); // next() would return EOF now. cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key1, loc1}}); cursor->restore(opCtx.get()); // The restore may have seeked to EOF. auto insertPoint = forward ? key2 : key0; cursor->savePositioned(); // Should still save key1 as "current position". insertToIndex(opCtx, sorted, {{insertPoint, loc1}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->next(), IndexKeyEntry(insertPoint, loc1)); }
// Ensure that repeated restores lands as close as possible to original position, even if data // inserted while saved and the current position removed. void testSaveAndRestorePositionSeesNewInsertsAfterRemove(bool forward, bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key1, loc1}, {key3, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), forward); const auto seekPoint = forward ? key1 : key3; ASSERT_EQ(cursor->seek(seekPoint, true), IndexKeyEntry(seekPoint, loc1)); cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key1, loc1}}); cursor->restore(opCtx.get()); // The restore may have seeked since it can't return to the saved position. cursor->savePositioned(); // Should still save originally saved key as "current position". insertToIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); }
void DhQGraphicsItemGroup::DvhremoveFromIndex() { return removeFromIndex(); }
void DhQGraphicsEllipseItem::DvhremoveFromIndex() { return removeFromIndex(); }