Ejemplo n.º 1
0
void TestRTree::testRemoveRows()
{
    RTree<QString> tree;
    tree.insert(QRect(1, 1, 1, 2), QString("1"));
    tree.insert(QRect(2, 1, 1, 3), QString("2"));
    tree.insert(QRect(3, 2, 1, 4), QString("3"));
    tree.insert(QRect(4, 2, 1, 5), QString("4"));
    tree.insert(QRect(5, 3, 1, 3), QString("5"));
    tree.insert(QRect(6, 3, 1, 4), QString("6"));
    tree.insert(QRect(7, 4, 1, 2), QString("7"));
    tree.insert(QRect(8, 4, 1, 3), QString("8"));
    tree.insert(QRect(9, 6, 1, 3), QString("9"));
    QList< QPair<QRectF, QString> > undo = tree.removeRows(3, 3);
    QList< QPair<QRectF, QString> > pairs = tree.intersectingPairs(QRect(1, 1, 10, 10)).values();
    QCOMPARE(pairs.count(), 7);
    QCOMPARE(pairs[0].first, QRectF(1, 1, 1, 2));
    QCOMPARE(pairs[0].second, QString("1"));
    QCOMPARE(pairs[1].first, QRectF(2, 1, 1, 2));
    QCOMPARE(pairs[1].second, QString("2"));
    QCOMPARE(pairs[2].first, QRectF(3, 2, 1, 1));
    QCOMPARE(pairs[2].second, QString("3"));
    QCOMPARE(pairs[3].first, QRectF(4, 2, 1, 2));
    QCOMPARE(pairs[3].second, QString("4"));
    QCOMPARE(pairs[4].first, QRectF(6, 3, 1, 1));
    QCOMPARE(pairs[4].second, QString("6"));
    QCOMPARE(pairs[5].first, QRectF(8, 3, 1, 1));
    QCOMPARE(pairs[5].second, QString("8"));
    QCOMPARE(pairs[6].first, QRectF(9, 3, 1, 3));
    QCOMPARE(pairs[6].second, QString("9"));
    QCOMPARE(undo.count(), 2);
    QCOMPARE(undo[0].first.toRect(), QRect(5, 3, 1, 3));
    QCOMPARE(undo[0].second, QString("5"));
    QCOMPARE(undo[1].first.toRect(), QRect(7, 4, 1, 2));
    QCOMPARE(undo[1].second, QString("7"));
}
int main() {
	tree.insert(generateBound(1, 2), 1);
	tree.insert(generateBound(1, 2), 2);
	tree.insert(generateBound(1, 2), 3);
	tree.insert(generateBound(1, 2), 4);
	tree.insert(generateBound(1, 2), 5);
	tree.insert(generateBound(1, 2), 6);
	tree.insert(generateBound(1, 2), 7);
	tree.insert(generateBound(1, 2), 8);
	tree.remove(generateBound(1, 2)); tree.travel();
	tree.remove(generateBound(1, 2)); tree.travel();
	tree.remove(generateBound(1, 2)); tree.travel();
	tree.remove(generateBound(1, 2)); tree.travel();
	tree.remove(generateBound(1, 2)); tree.travel();
	tree.remove(generateBound(1, 2)); tree.travel();
	tree.remove(generateBound(1, 2)); tree.travel();
	tree.remove(generateBound(1, 2)); tree.travel();
	tree.insert(generateBound(1, 2), 1);
	tree.insert(generateBound(1, 2), 2);
	tree.insert(generateBound(1, 2), 3);
	tree.insert(generateBound(1, 2), 4);
	tree.insert(generateBound(1, 2), 5);
	tree.insert(generateBound(1, 2), 6);
	tree.insert(generateBound(1, 2), 7);
	tree.insert(generateBound(1, 2), 8);
	auto ret = tree.getPointSet(generateBound(1, 2));
	printf("%d\n", (int)ret.size());
	std::sort(ret.begin(), ret.end());
	for (auto element : ret) {
		printf("%d\n", element);
	}
	return 0;
}
Ejemplo n.º 3
0
void TestRTree::testInsertColumns()
{
    // RTree::InsertMode = RTree::CopyPrevious
    RTree<QString> tree;
    tree.insert(QRect(1, 1, 2, 1), QString("1"));
    tree.insert(QRect(1, 2, 3, 1), QString("2"));
    tree.insert(QRect(2, 3, 4, 1), QString("3"));
    tree.insert(QRect(2, 4, 5, 1), QString("4"));
    tree.insert(QRect(3, 5, 3, 1), QString("5"));
    tree.insert(QRect(3, 6, 4, 1), QString("6"));
    tree.insert(QRect(4, 7, 2, 1), QString("7"));
    tree.insert(QRect(4, 8, 3, 1), QString("8"));
    tree.insert(QRect(6, 9, 3, 1), QString("9"));
    QList< QPair<QRectF, QString> > undo = tree.insertColumns(3, 3);
    QList< QPair<QRectF, QString> > pairs = tree.intersectingPairs(QRect(1, 1, 10, 10)).values();
    QCOMPARE(pairs.count(), 9);
    QCOMPARE(pairs[0].first, QRectF(1, 1, 5, 1));
    QCOMPARE(pairs[0].second, QString("1"));
    QCOMPARE(pairs[1].first, QRectF(1, 2, 6, 1));
    QCOMPARE(pairs[1].second, QString("2"));
    QCOMPARE(pairs[2].first, QRectF(2, 3, 7, 1));
    QCOMPARE(pairs[2].second, QString("3"));
    QCOMPARE(pairs[3].first, QRectF(2, 4, 8, 1));
    QCOMPARE(pairs[3].second, QString("4"));
    QCOMPARE(pairs[4].first, QRectF(6, 5, 3, 1));
    QCOMPARE(pairs[4].second, QString("5"));
    QCOMPARE(pairs[5].first, QRectF(6, 6, 4, 1));
    QCOMPARE(pairs[5].second, QString("6"));
    QCOMPARE(pairs[6].first, QRectF(7, 7, 2, 1));
    QCOMPARE(pairs[6].second, QString("7"));
    QCOMPARE(pairs[7].first, QRectF(7, 8, 3, 1));
    QCOMPARE(pairs[7].second, QString("8"));
    QCOMPARE(pairs[8].first, QRectF(9, 9, 3, 1));
    QCOMPARE(pairs[8].second, QString("9"));
    QCOMPARE(undo.count(), 0);
#if 0
    // RTree::InsertMode = RTree::CopyCurrent
    tree.clear();
    tree.insert(QRect(1, 1, 2, 1), QString("1"));
    tree.insert(QRect(1, 2, 3, 1), QString("2"));
    undo = tree.insertColumns(3, 3, RTree<QString>::CopyCurrent);
    pairs = tree.intersectingPairs(QRect(1, 1, 10, 10));
    QCOMPARE(pairs.count(), 2);
    QCOMPARE(pairs[0].first, QRectF(1, 1, 2, 1));
    QCOMPARE(pairs[1].first, QRectF(1, 2, 6, 1));
    QCOMPARE(undo.count(), 0);

    // RTree::InsertMode = RTree::CopyNone
    tree.clear();
    tree.insert(QRect(1, 1, 2, 1), QString("1"));
    tree.insert(QRect(1, 2, 3, 1), QString("2"));
    undo = tree.insertColumns(3, 3, RTree<QString>::CopyNone);
    pairs = tree.intersectingPairs(QRect(1, 1, 10, 10));
    QCOMPARE(pairs.count(), 3);
    QCOMPARE(pairs[0].first, QRectF(1, 1, 2, 1));
    QCOMPARE(pairs[1].first, QRectF(1, 2, 2, 1));
    QCOMPARE(pairs[2].first, QRectF(6, 2, 1, 1));
    QCOMPARE(undo.count(), 0);
#endif
}
Ejemplo n.º 4
0
void TestRTree::testIntersectingPairs()
{
    RTree<SharedTestClass> tree;
    tree.insert(QRect(1, 1, 1, 1), new DerivedClass(QString("foo")));
    QList< QPair<QRectF, SharedTestClass> > pairs = tree.intersectingPairs(QRect(1, 1, 10, 10)).values();
    QVERIFY(pairs.count() == 1);
    QCOMPARE(pairs[0].first, QRectF(1, 1, 1, 1));
    QCOMPARE(pairs[0].second->member, QString("foo"));
    QCOMPARE(pairs[0].second->type(), 1);
}
Ejemplo n.º 5
0
void TestRTree::testPrimitive()
{
    RTree<bool> tree;
    tree.insert(QRect(2, 5, 1, 2), true);
    QCOMPARE(tree.contains(QPoint(2, 2)).isEmpty(), true);
    QCOMPARE(tree.contains(QPoint(2, 5)).first(), true);
    QCOMPARE(tree.contains(QPoint(3, 5)).isEmpty(), true);
    QCOMPARE(tree.contains(QPoint(2, 6)).first(), true);
    const QList< QPair<QRectF, bool> > pairs = tree.intersectingPairs(QRect(2, 5, 1, 2)).values();
    QCOMPARE(pairs.count(), 1);
    QCOMPARE(pairs.first().first.toRect(), QRect(2, 5, 1, 2));
    QCOMPARE(pairs.first().second, true);
}
Ejemplo n.º 6
0
void TestRTree::testRemoveShiftLeft()
{
    RTree<SharedTestClass> tree;
    tree.insert(QRect(5, 2, 2, 1), new DerivedClass(QString("foo")));
    tree.removeShiftLeft(QRect(2, 1, 3, 4));
    QList< QPair<QRectF, SharedTestClass> > pairs = tree.intersectingPairs(QRect(1, 1, 10, 10)).values();
    QCOMPARE(pairs.count(), 3);
    QCOMPARE(pairs[0].first, QRectF(5, 2, 2, 1));
    QCOMPARE(pairs[0].second->member, QString("foo"));
    QCOMPARE(pairs[1].first, QRectF(2, 1, KS_colMax - 1, 4));
    QCOMPARE(pairs[1].second->member, QString(""));
    QCOMPARE(pairs[2].first, QRectF(2, 2, 2, 1));
    QCOMPARE(pairs[2].second->member, QString("foo"));
}
Ejemplo n.º 7
0
void TestRTree::testInsertShiftDown()
{
    RTree<SharedTestClass> tree;
    tree.insert(QRect(2, 2, 1, 2), new DerivedClass(QString("foo")));
    tree.insertShiftDown(QRect(2, 1, 4, 3));
    QList< QPair<QRectF, SharedTestClass> > pairs = tree.intersectingPairs(QRect(1, 1, 10, 10)).values();
    QCOMPARE(pairs.count(), 3);
    QCOMPARE(pairs[0].first, QRectF(2, 2, 1, 2));
    QCOMPARE(pairs[0].second->member, QString("foo"));
    QCOMPARE(pairs[1].first, QRectF(2, 1, 4, KS_rowMax));
    QCOMPARE(pairs[1].second->member, QString(""));
    QCOMPARE(pairs[2].first, QRectF(2, 5, 1, 2));
    QCOMPARE(pairs[2].second->member, QString("foo"));
}
Ejemplo n.º 8
0
void TestRTree::testInsertRows()
{
    // RTree::InsertMode = RTree::CopyPrevious
    RTree<QString> tree;
    tree.insert(QRect(1, 1, 1, 2), QString("1"));
    tree.insert(QRect(2, 1, 1, 3), QString("2"));
    tree.insert(QRect(3, 2, 1, 4), QString("3"));
    tree.insert(QRect(4, 2, 1, 5), QString("4"));
    tree.insert(QRect(5, 3, 1, 3), QString("5"));
    tree.insert(QRect(6, 3, 1, 4), QString("6"));
    tree.insert(QRect(7, 4, 1, 2), QString("7"));
    tree.insert(QRect(8, 4, 1, 3), QString("8"));
    tree.insert(QRect(9, 6, 1, 3), QString("9"));
    QList< QPair<QRectF, QString> > undo = tree.insertRows(3, 3);
    QList< QPair<QRectF, QString> > pairs = tree.intersectingPairs(QRect(1, 1, 10, 10)).values();
    QCOMPARE(pairs.count(), 9);
    QCOMPARE(pairs[0].first, QRectF(1, 1, 1, 2));
    QCOMPARE(pairs[0].second, QString("1"));
    QCOMPARE(pairs[1].first, QRectF(2, 1, 1, 6));
    QCOMPARE(pairs[1].second, QString("2"));
    QCOMPARE(pairs[2].first, QRectF(3, 2, 1, 7));
    QCOMPARE(pairs[2].second, QString("3"));
    QCOMPARE(pairs[3].first, QRectF(4, 2, 1, 8));
    QCOMPARE(pairs[3].second, QString("4"));
    QCOMPARE(pairs[4].first, QRectF(5, 6, 1, 3));
    QCOMPARE(pairs[4].second, QString("5"));
    QCOMPARE(pairs[5].first, QRectF(6, 6, 1, 4));
    QCOMPARE(pairs[5].second, QString("6"));
    QCOMPARE(pairs[6].first, QRectF(7, 7, 1, 2));
    QCOMPARE(pairs[6].second, QString("7"));
    QCOMPARE(pairs[7].first, QRectF(8, 7, 1, 3));
    QCOMPARE(pairs[7].second, QString("8"));
    QCOMPARE(pairs[8].first, QRectF(9, 9, 1, 3));
    QCOMPARE(pairs[8].second, QString("9"));
    QCOMPARE(undo.count(), 0);
#if 0
    // RTree::InsertMode = RTree::CopyCurrent
    tree.clear();
    tree.insert(QRect(1, 1, 1, 2), QString("1"));
    tree.insert(QRect(2, 1, 1, 3), QString("2"));
    undo = tree.insertColumns(3, 3, RTree<QString>::CopyCurrent);
    pairs = tree.intersectingPairs(QRect(1, 1, 10, 10));
    QCOMPARE(pairs.count(), 2);
    QCOMPARE(pairs[0].first, QRectF(1, 1, 1, 2));
    QCOMPARE(pairs[1].first, QRectF(2, 1, 1, 6));
    QCOMPARE(undo.count(), 0);
#endif

    RTree<bool> boolTree;
    boolTree.insert(QRect(1, 2, 2, 1), true);
    boolTree.insert(QRect(1, 3, 1, 2), true);
    boolTree.insertRows(6, 1);
    QList< QPair<QRectF, bool> > boolPairs = boolTree.intersectingPairs(QRect(1, 2, 1, 1)).values();
    QCOMPARE(boolPairs.count(), 1);
    QCOMPARE(boolPairs[0].first, QRectF(1, 2, 2, 1));
    QCOMPARE(boolPairs[0].second, true);
    boolPairs = boolTree.intersectingPairs(QRect(1, 3, 1, 1)).values();
    QCOMPARE(boolPairs.count(), 1);
    QCOMPARE(boolPairs[0].first, QRectF(1, 3, 1, 2));
    QCOMPARE(boolPairs[0].second, true);
}
Ejemplo n.º 9
0
    Status MultiIndexBlock::init(const std::vector<BSONObj>& indexSpecs) {
        WriteUnitOfWork wunit(_txn);

        invariant(_indexes.empty());
        _txn->recoveryUnit()->registerChange(new CleanupIndexesVectorOnRollback(this));

        const string& ns = _collection->ns().ns();

        Status status = _collection->getIndexCatalog()->checkUnfinished();
        if ( !status.isOK() )
            return status;

        for ( size_t i = 0; i < indexSpecs.size(); i++ ) {
            BSONObj info = indexSpecs[i];

            string pluginName = IndexNames::findPluginName( info["key"].Obj() );
			//log() << "PLUGIN IS " << pluginName;
			
			// CUSTOM
			if (pluginName == "test") {
				// YOU SHOULD BE ABLE TO MAKE TE INDEX HERE
				//log() << "INX_CREATE NUM REC:" << _collection->numRecords(_txn);
				RecordIterator* ri = _collection->getIterator(_txn);

				std::vector<Entry*> initialEntries;

				while (!ri->isEOF()) {
					//log() << "SEE ITEM";
					RecordData recordData = ri->dataFor(ri->curr());
					//log() << "VALU IS " << recordData.toBson();

					std::vector<double> lower; std::vector<double> upper;
					bool foundOK = false;

					if (recordData.toBson().getFieldDotted("loc")["lng"].ok()) {
						// A POINT
						log() << "ELE IS A POINT: " << recordData.toBson().getFieldDotted("loc")["lng"].Double() << " AND " << recordData.toBson().getFieldDotted("loc")["lat"].Double();

						lower.push_back(recordData.toBson().getFieldDotted("loc")["lng"].Double()); lower.push_back(recordData.toBson().getFieldDotted("loc")["lat"].Double());
						upper.push_back(recordData.toBson().getFieldDotted("loc")["lng"].Double()); upper.push_back(recordData.toBson().getFieldDotted("loc")["lat"].Double());
						foundOK = true;
					}
					else { 
						//log() << "NOT OK LINE!"; 
					}
					if (recordData.toBson().getFieldDotted("loc")["type"].ok()) {
						if (recordData.toBson().getFieldDotted("loc")["type"].String() == "Polygon") {
							//log() << "ITS A POLY"; // << recordData.toBson().getFieldDotted("loc")["rew"].Double();

							lower.push_back(recordData.toBson().getFieldDotted("loc")["coordinates"].Array().at(0).Array().at(0).Array().at(0).Double());
							lower.push_back(recordData.toBson().getFieldDotted("loc")["coordinates"].Array().at(0).Array().at(0).Array().at(1).Double());
							upper.push_back(recordData.toBson().getFieldDotted("loc")["coordinates"].Array().at(0).Array().at(2).Array().at(0).Double());
							upper.push_back(recordData.toBson().getFieldDotted("loc")["coordinates"].Array().at(0).Array().at(2).Array().at(1).Double());

							foundOK = true;
						}
					}
					else { 
						//log() << "NOT OK POLY!"; 
					}

					if (foundOK) {
						std::unordered_map<int, std::string> newDoc;
						BoundingBox I = BoundingBox(lower, upper);
						Entry* myEnt = new Entry(I, newDoc);
						initialEntries.push_back(myEnt);
					}

					ri->getNext();
				}

				int dimensions = 2;
				int max = 6;
				int min = 3;

				log() << "RTRee creation has begun!";
				//create a new Node, this will be the root node
				std::vector<Entry*> newV;
				Node* R = new Node(dimensions, newV, max, min, true);
				//create a new RTree
				RTree myIndex = RTree(dimensions, R, max, min);
				//insert the entries we created into myIndex RTree
				for (int i = 0; i<initialEntries.size(); i++){
					//log() << "started inserting entry " << i << " which has lat ";
					Entry* current = initialEntries.at(i);
					//log() << "started inserting entry " << i << " which has lat " << current->getI().get_ithLower(0) << "," << current->getI().get_ithLower(1);
					//log() << "started inserting entry " << i << " which has lat " << current->getI().get_ithUpper(0) << "," << current->getI().get_ithUpper(1);
					myIndex.insert(current);
					//log() << "finished inserting entry " << i;
				}
				log() << "inserted all initial entries!";
				
				myIndex.theTree = &myIndex;
				
				
				
				double rand1 = -100;//0;//-2.0;// 2.0;//
				double rand2 = -100;//0;//-3.0;// 1.0;//
				double rand3 = 100;//50;//2.0;// 4.0;//
				double rand4 = 100;//50;//3.0;// 4.0;//
				std::vector<double> lowerBB;
				lowerBB.push_back(rand1);
				lowerBB.push_back(rand2);
				std::vector<double> upperBB;
				upperBB.push_back(rand3);
				upperBB.push_back(rand4);
				BoundingBox* IBB = new BoundingBox(lowerBB, upperBB);//this is the bounding box we will be searching for

				std::vector<Entry*> overlapping = myIndex.search(IBB); // just leave this for now
				//cout << "found: " << overlapping.size() << " search results when searching for I = ";
				//cout << "lower bounds: " << I.getLower() << endl;
				//cout << "upper bounds: " << I.getUpper() << endl;
				/*log() << "SEARCH FOUND " << overlapping.size() << " RESULTS" << endl;
				for(int i=0; i<overlapping.size();i++){
					log() << "Entry " << i << endl;
					//TODO print Entry
					log() << overlapping.at(i)->getI().get_ithLower(0)<< " "<< overlapping.at(i)->getI().get_ithLower(1) << endl;
					
					log() << overlapping.at(i)->getI().get_ithUpper(0)<< " " << overlapping.at(i)->getI().get_ithUpper(1) << endl;
					
				}*/
				
				
				

				return Status::OK();
			}
			// CUSTOM
			
            if ( pluginName.size() ) {
                Status s =
                    _collection->getIndexCatalog()->_upgradeDatabaseMinorVersionIfNeeded(_txn, pluginName);
                if ( !s.isOK() )
                    return s;
            }

            // Any foreground indexes make all indexes be built in the foreground.
            _buildInBackground = (_buildInBackground && info["background"].trueValue());
        }

        for ( size_t i = 0; i < indexSpecs.size(); i++ ) {
            BSONObj info = indexSpecs[i];
            StatusWith<BSONObj> statusWithInfo =
                _collection->getIndexCatalog()->prepareSpecForCreate( _txn, info );
            Status status = statusWithInfo.getStatus();
            if ( !status.isOK() )
                return status;
            info = statusWithInfo.getValue();

            IndexToBuild index;
            index.block = boost::make_shared<IndexCatalog::IndexBuildBlock>(_txn,
                                                                            _collection,
                                                                            info);
            status = index.block->init();
            if ( !status.isOK() )
                return status;

            index.real = index.block->getEntry()->accessMethod();
            status = index.real->initializeAsEmpty(_txn);
            if ( !status.isOK() )
                return status;

            if (!_buildInBackground) {
                // Bulk build process requires foreground building as it assumes nothing is changing
                // under it.
                index.bulk.reset(index.real->initiateBulk(_txn));
            }

            const IndexDescriptor* descriptor = index.block->getEntry()->descriptor();

            index.options.logIfError = false; // logging happens elsewhere if needed.
            index.options.dupsAllowed = !descriptor->unique()
                                     || _ignoreUnique
                                     || repl::getGlobalReplicationCoordinator()
                                                    ->shouldIgnoreUniqueIndex(descriptor);

            log() << "build index on: " << ns << " properties: " << descriptor->toString();
            if (index.bulk)
                log() << "\t building index using bulk method";

            // TODO SERVER-14888 Suppress this in cases we don't want to audit.
            audit::logCreateIndex(_txn->getClient(), &info, descriptor->indexName(), ns);

            _indexes.push_back( index );
        }

        // this is so that operations examining the list of indexes know there are more keys to look
        // at when doing things like in place updates, etc...
        _collection->infoCache()->addedIndex(_txn);

        if (_buildInBackground)
            _backgroundOperation.reset(new BackgroundOperation(ns));

        wunit.commit();
        return Status::OK();
    }