コード例 #1
0
ファイル: translator.cpp プロジェクト: kileven/qt5
void Translator::insert(int idx, const TranslatorMessage &msg)
{
    addIndex(idx, msg);
    m_messages.insert(idx, msg);
}
コード例 #2
0
ファイル: query_stage_and.cpp プロジェクト: Cassie90/mongo
        void run() {
            Client::WriteContext ctx(ns());

            for (int i = 0; i < 50; ++i) {
                insert(BSON("foo" << i << "bar" << i));
            }

            addIndex(BSON("foo" << 1));
            addIndex(BSON("bar" << 1));

            WorkingSet ws;
            scoped_ptr<AndHashStage> ah(new AndHashStage(&ws, NULL));

            // Foo <= 20
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1));
            params.bounds.isSimpleRange = true;
            params.bounds.startKey = BSON("" << 20);
            params.bounds.endKey = BSONObj();
            params.bounds.endKeyInclusive = true;
            params.direction = -1;
            ah->addChild(new IndexScan(params, &ws, NULL));

            // Bar >= 10
            params.descriptor = getIndex(BSON("bar" << 1));
            params.bounds.startKey = BSON("" << 10);
            params.bounds.endKey = BSONObj();
            params.bounds.endKeyInclusive = true;
            params.direction = 1;
            ah->addChild(new IndexScan(params, &ws, NULL));

            // ah reads the first child into its hash table.
            // ah should read foo=20, foo=19, ..., foo=0 in that order.
            // Read half of them...
            for (int i = 0; i < 10; ++i) {
                WorkingSetID out;
                PlanStage::StageState status = ah->work(&out);
                ASSERT_EQUALS(PlanStage::NEED_TIME, status);
            }

            // ...yield
            ah->prepareToYield();
            // ...invalidate one of the read objects
            set<DiskLoc> data;
            getLocs(&data);
            for (set<DiskLoc>::const_iterator it = data.begin(); it != data.end(); ++it) {
                if (it->obj()["foo"].numberInt() == 15) {
                    ah->invalidate(*it);
                    remove(it->obj());
                    break;
                }
            }
            ah->recoverFromYield();

            // And expect to find foo==15 it flagged for review.
            const vector<WorkingSetID>& flagged = ws.getFlagged();
            ASSERT_EQUALS(size_t(1), flagged.size());

            // Expect to find the right value of foo in the flagged item.
            WorkingSetMember* member = ws.get(flagged[0]);
            ASSERT_TRUE(NULL != member);
            ASSERT_EQUALS(WorkingSetMember::OWNED_OBJ, member->state);
            BSONElement elt;
            ASSERT_TRUE(member->getFieldDotted("foo", &elt));
            ASSERT_EQUALS(15, elt.numberInt());

            // Now, finish up the AND.  Since foo == bar, we would have 11 results, but we subtract
            // one because of a mid-plan invalidation, so 10.
            int count = 0;
            while (!ah->isEOF()) {
                WorkingSetID id;
                PlanStage::StageState status = ah->work(&id);
                if (PlanStage::ADVANCED != status) { continue; }

                ++count;
                member = ws.get(id);

                ASSERT_TRUE(member->getFieldDotted("foo", &elt));
                ASSERT_LESS_THAN_OR_EQUALS(elt.numberInt(), 20);
                ASSERT_NOT_EQUALS(15, elt.numberInt());
                ASSERT_TRUE(member->getFieldDotted("bar", &elt));
                ASSERT_GREATER_THAN_OR_EQUALS(elt.numberInt(), 10);
            }

            ASSERT_EQUALS(10, count);
        }
コード例 #3
0
ファイル: ofMesh.cpp プロジェクト: alesaccoia/xtrees
//--------------------------------------------------------------
void ofMesh::addTriangle(ofIndexType index1, ofIndexType index2, ofIndexType index3) {
    addIndex(index1);
    addIndex(index2);
    addIndex(index3);
}
コード例 #4
0
ファイル: ofMesh.cpp プロジェクト: apexcode/openFrameworks
//--------------------------------------------------------------
void ofMesh::addIndices(const ofIndexType* inds, int amt){
	for (int i = 0; i < amt;i++){
		addIndex(inds[i]);
	}
	bIndicesChanged = true;
}
コード例 #5
0
ファイル: query_stage_and.cpp プロジェクト: Cassie90/mongo
        void run() {
            Client::WriteContext ctx(ns());

            // Insert a bunch of data
            for (int i = 0; i < 50; ++i) {
                insert(BSON("foo" << 1 << "bar" << 1));
            }
            addIndex(BSON("foo" << 1));
            addIndex(BSON("bar" << 1));

            WorkingSet ws;
            scoped_ptr<AndSortedStage> ah(new AndSortedStage(&ws, NULL));

            // Scan over foo == 1
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1));
            params.bounds.isSimpleRange = true;
            params.bounds.startKey = BSON("" << 1);
            params.bounds.endKey = BSON("" << 1);
            params.bounds.endKeyInclusive = true;
            params.direction = 1;
            ah->addChild(new IndexScan(params, &ws, NULL));

            // Scan over bar == 1
            params.descriptor = getIndex(BSON("bar" << 1));
            ah->addChild(new IndexScan(params, &ws, NULL));

            // Get the set of disklocs in our collection to use later.
            set<DiskLoc> data;
            getLocs(&data);

            // We're making an assumption here that happens to be true because we clear out the
            // collection before running this: increasing inserts have increasing DiskLocs.
            // This isn't true in general if the collection is not dropped beforehand.
            WorkingSetID id;

            // Sorted AND looks at the first child, which is an index scan over foo==1.
            ah->work(&id);

            // The first thing that the index scan returns (due to increasing DiskLoc trick) is the
            // very first insert, which should be the very first thing in data.  Let's invalidate it
            // and make sure it shows up in the flagged results.
            ah->prepareToYield();
            ah->invalidate(*data.begin());
            remove(data.begin()->obj());
            ah->recoverFromYield();

            // Make sure the nuked obj is actually in the flagged data.
            ASSERT_EQUALS(ws.getFlagged().size(), size_t(1));
            WorkingSetMember* member = ws.get(ws.getFlagged()[0]);
            ASSERT_EQUALS(WorkingSetMember::OWNED_OBJ, member->state);
            BSONElement elt;
            ASSERT_TRUE(member->getFieldDotted("foo", &elt));
            ASSERT_EQUALS(1, elt.numberInt());
            ASSERT_TRUE(member->getFieldDotted("bar", &elt));
            ASSERT_EQUALS(1, elt.numberInt());

            set<DiskLoc>::iterator it = data.begin();

            // Proceed along, AND-ing results.
            int count = 0;
            while (!ah->isEOF() && count < 10) {
                WorkingSetID id;
                PlanStage::StageState status = ah->work(&id);
                if (PlanStage::ADVANCED != status) { continue; }

                ++count;
                ++it;
                member = ws.get(id);

                ASSERT_TRUE(member->getFieldDotted("foo", &elt));
                ASSERT_EQUALS(1, elt.numberInt());
                ASSERT_TRUE(member->getFieldDotted("bar", &elt));
                ASSERT_EQUALS(1, elt.numberInt());
                ASSERT_EQUALS(member->loc, *it);
            }

            // Move 'it' to a result that's yet to show up.
            for (int i = 0; i < count + 10; ++i) { ++it; }
            // Remove a result that's coming up.  It's not the 'target' result of the AND so it's
            // not flagged.
            ah->prepareToYield();
            ah->invalidate(*it);
            remove(it->obj());
            ah->recoverFromYield();

            // Get all results aside from the two we killed.
            while (!ah->isEOF()) {
                WorkingSetID id;
                PlanStage::StageState status = ah->work(&id);
                if (PlanStage::ADVANCED != status) { continue; }

                ++count;
                member = ws.get(id);

                ASSERT_TRUE(member->getFieldDotted("foo", &elt));
                ASSERT_EQUALS(1, elt.numberInt());
                ASSERT_TRUE(member->getFieldDotted("bar", &elt));
                ASSERT_EQUALS(1, elt.numberInt());
            }

            ASSERT_EQUALS(count, 48);

            ASSERT_EQUALS(size_t(1), ws.getFlagged().size());
        }
コード例 #6
0
 Base() : lk(ns()), _context( ns() ) {
     addIndex( fromjson( "{\"a\":1}" ) );
 }
コード例 #7
0
void MainWindow::showContextMenu( const QPoint & )
{
	QModelIndexList selectedRows = mUI.mTreeView->selectedRows();
	printf( "%i rows selected\n", selectedRows.size() );
	if( selectedRows.size() > 1 ) return;

	QModelIndex idx;
	if( selectedRows.size() == 1 ) idx = selectedRows[0];

	QMenu * m = new QMenu( this );
	QAction * newTable = 0, * newTableInherit = 0, * newField = 0, * newIndex = 0, * modifyTable = 0, * removeTable = 0, * createVerifyTable = 0;
	QAction * modifyField = 0, * removeField = 0, * modifyIndex = 0, * removeIndex = 0;
	TableSchema * table = 0;
	if( !idx.isValid() || TableTranslator::isType(idx) ) {
		newTable = m->addAction( "Create Table" );
		if( TableTranslator::isType(idx) ) {
			newTableInherit = m->addAction( "Create Inherited Table" );
			table = TableTranslator::data(idx).mTable;
		}
	}

	if( StandardTranslator::isType(idx) ) {
		QString name = idx.data(Qt::DisplayRole).toString();
		table = TableTranslator::data(idx.parent()).mTable;
		if( name == "Fields" )
			newField = m->addAction( "Create Field/Variable" );
		if( name == "Indexes" )
			newIndex = m->addAction( "Create Index" );
	}

	if( TableTranslator::isType(idx) ) {
		m->addSeparator();
		modifyTable = m->addAction( "Modify Table" );
		removeTable = m->addAction( "Remove Table" );
		m->addSeparator();
		createVerifyTable = m->addAction( "Create or Verify Table in Database..." );
	}

	if( FieldTranslator::isType(idx) ) {
		modifyField = m->addAction( "Modify Field" );
		removeField = m->addAction( "Remove Field" );
	} else if ( IndexTranslator::isType(idx) ) {
		modifyIndex = m->addAction( "Modify Index" );
		removeIndex = m->addAction( "Remove Index" );
	}
	
	QAction * res = m->exec( QCursor::pos() );
	if( !res ) {
		delete m;
		return;
	}

	if( res == newTable ) {
		addTable( TableDialog::createTable( this, mSchema,  0 ) );
	} else if( res == newTableInherit ) {
		addTable( TableDialog::createTable( this, mSchema, table ) );
	} else if( res == modifyTable ) {
		if( TableDialog::modifyTable( this, table ) ) {
			mModel->dataChange(idx);
			mChanges = true;
		}
	} else if( res == removeTable ) {
		mModel->remove(idx);
		delete table;
		mChanges = true;
	} else if( res == createVerifyTable ) {
		slotCreateDatabase( table );
	} else if( res == newField ) {
		addField( FieldDialog::createField( this, table ) );
	} else if( res == modifyField ) {
		if( FieldDialog::modifyField( this, FieldTranslator::data(idx).mField ) ) {
			mModel->dataChange(idx);
			mChanges = true;
		}
	} else if( res == removeField ) {
		Field * f = FieldTranslator::data(idx).mField;
		mModel->remove(idx);
		delete f;
		mChanges = true;
	} else if( res == newIndex ) {
		addIndex( IndexDialog::createIndex( this, table ) );
	} else if( res == modifyIndex ) {
		if( IndexDialog::modifyIndex( this, IndexTranslator::data(idx).mIndex ) ) {
			mModel->dataChange(idx);
			mChanges = true;
		}
	} else if( res == removeIndex ) {
		IndexSchema * i = IndexTranslator::data(idx).mIndex;
		mModel->remove(idx);
		delete i;
		mChanges = true;
	}
	delete m;
}
コード例 #8
0
ファイル: model.cpp プロジェクト: criptych/minengine
void Model::addTriangle(uint16_t a, uint16_t b, uint16_t c) {
    addIndex(a);
    addIndex(b);
    addIndex(c);
}
コード例 #9
0
ファイル: boundingbox.cpp プロジェクト: hsimpson/qparticles
void BoundingBox::createGeometry()
{
  // create the vertices
  float halfx = _dimensions.x()/2;
  float halfy = _dimensions.y()/2;
  float halfz = _dimensions.z()/2;
  
  //unsigned int col = 0x55555555; // pure white and opaque
  /* the cube:
    

       v5-----------v6
      / |          / |
     /  |         /  |
    v2----------v1   |
    |   |        |   |
    |   |        |   |
    |  v4--------|--v7 
    | /          |  /
    |/           | /
    v3-----------v0


  */
  // front vertices:
  
  addVertex(Vertex( halfx, -halfy,  -halfz,  1.0f, 1.0f, 1.0f));
  addVertex(Vertex( halfx,  halfy,  -halfz,  1.0f, 1.0f, 1.0f));
  addVertex(Vertex(-halfx,  halfy,  -halfz,  1.0f, 1.0f, 1.0f));
  addVertex(Vertex(-halfx, -halfy,  -halfz,  1.0f, 1.0f, 1.0f));
                                                    
  // back vertices:                                               
  addVertex(Vertex(-halfx, -halfy, halfz,  1.0f, 1.0f, 1.0f));
  addVertex(Vertex(-halfx,  halfy, halfz,  1.0f, 1.0f, 1.0f));
  addVertex(Vertex( halfx,  halfy, halfz,  1.0f, 1.0f, 1.0f));
  addVertex(Vertex( halfx, -halfy, halfz,  1.0f, 1.0f, 1.0f));

  
  // create the indices for the lines
  // front
  addIndex(0);  addIndex(1);
  addIndex(1);  addIndex(2);
  addIndex(2);  addIndex(3);
  addIndex(3);  addIndex(0);

  // left
  addIndex(3);  addIndex(2);
  addIndex(2);  addIndex(5);
  addIndex(5);  addIndex(4);
  addIndex(4);  addIndex(3);

  // right
  addIndex(7);  addIndex(6);
  addIndex(6);  addIndex(1);
  addIndex(1);  addIndex(0);
  addIndex(0);  addIndex(7);

  // back
  addIndex(4);  addIndex(5);
  addIndex(5);  addIndex(6);
  addIndex(6);  addIndex(7);
  addIndex(7);  addIndex(4);
}
コード例 #10
0
        void run() {
            Client::WriteContext ctx(ns());

            const int N = 5000;
            for (int i = 0; i < N; ++i) {
                insert(BSON("foo" << (i % 10)));
            }

            addIndex(BSON("foo" << 1));

            // Plan 0: IXScan over foo == 7
            // Every call to work() returns something so this should clearly win (by current scoring
            // at least).
            IndexScanParams ixparams;
            ixparams.descriptor = getIndex(BSON("foo" << 1));
            ixparams.bounds.isSimpleRange = true;
            ixparams.bounds.startKey = BSON("" << 7);
            ixparams.bounds.endKey = BSON("" << 7);
            ixparams.bounds.endKeyInclusive = true;
            ixparams.direction = 1;
            auto_ptr<WorkingSet> firstWs(new WorkingSet());
            IndexScan* ix = new IndexScan(ixparams, firstWs.get(), NULL);
            auto_ptr<PlanStage> firstRoot(new FetchStage(firstWs.get(), ix, NULL));

            // Plan 1: CollScan with matcher.
            CollectionScanParams csparams;
            csparams.ns = ns();
            csparams.direction = CollectionScanParams::FORWARD;
            auto_ptr<WorkingSet> secondWs(new WorkingSet());
            // Make the filter.
            BSONObj filterObj = BSON("foo" << 7);
            StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj);
            verify(swme.isOK());
            auto_ptr<MatchExpression> filter(swme.getValue());
            // Make the stage.
            auto_ptr<PlanStage> secondRoot(new CollectionScan(csparams, secondWs.get(),
                                                              filter.get()));

            // Hand the plans off to the runner.
            CanonicalQuery* cq = NULL;
            verify(CanonicalQuery::canonicalize(ns(), BSON("foo" << 7), &cq).isOK());
            verify(NULL != cq);
            MultiPlanRunner mpr(ctx.ctx().db()->getCollection(ns()),cq);
            mpr.addPlan(createQuerySolution(), firstRoot.release(), firstWs.release());
            mpr.addPlan(createQuerySolution(), secondRoot.release(), secondWs.release());

            // Plan 0 aka the first plan aka the index scan should be the best.
            size_t best;
            ASSERT(mpr.pickBestPlan(&best));
            ASSERT_EQUALS(size_t(0), best);

            // Get all our results out.
            int results = 0;
            BSONObj obj;
            while (Runner::RUNNER_ADVANCED == mpr.getNext(&obj, NULL)) {
                ASSERT_EQUALS(obj["foo"].numberInt(), 7);
                ++results;
            }

            ASSERT_EQUALS(results, N / 10);
        }
コード例 #11
0
    void run() {
        // insert documents with a: 1 and b: 1
        for (size_t i = 0; i < 1000; ++i) {
            insert(BSON("a" << 1 << "b" << 1));
        }
        // insert documents with a: 1 and b: 2
        for (size_t i = 0; i < 1000; ++i) {
            insert(BSON("a" << 1 << "b" << 2));
        }
        // insert documents with a: 2 and b: 1
        for (size_t i = 0; i < 1000; ++i) {
            insert(BSON("a" << 2 << "b" << 1));
        }
        // insert documents with a: 2 and b: 3
        for (size_t i = 0; i < 1000; ++i) {
            insert(BSON("a" << 2 << "b" << 3));
        }

        addIndex(BSON("a" << 1 << "b" << 1));

        AutoGetCollectionForReadCommand ctx(&_opCtx, nss);
        Collection* coll = ctx.getCollection();

        std::vector<const IndexDescriptor*> indices;
        coll->getIndexCatalog()->findIndexesByKeyPattern(
            &_opCtx, BSON("a" << 1 << "b" << 1), false, &indices);
        ASSERT_EQ(1U, indices.size());

        DistinctParams params{&_opCtx, indices[0]};

        params.scanDirection = 1;
        params.fieldNo = 1;
        params.bounds.isSimpleRange = false;

        OrderedIntervalList aOil{"a"};
        aOil.intervals.push_back(IndexBoundsBuilder::allValues());
        params.bounds.fields.push_back(aOil);

        OrderedIntervalList bOil{"b"};
        bOil.intervals.push_back(IndexBoundsBuilder::allValues());
        params.bounds.fields.push_back(bOil);

        WorkingSet ws;
        DistinctScan distinct(&_opCtx, std::move(params), &ws);

        WorkingSetID wsid;
        PlanStage::StageState state;

        std::vector<int> seen;

        while (PlanStage::IS_EOF != (state = distinct.work(&wsid))) {
            ASSERT_NE(PlanStage::FAILURE, state);
            if (PlanStage::ADVANCED == state) {
                seen.push_back(getIntFieldDotted(ws, wsid, "b"));
            }
        }

        ASSERT_EQUALS(4U, seen.size());
        ASSERT_EQUALS(1, seen[0]);
        ASSERT_EQUALS(2, seen[1]);
        ASSERT_EQUALS(1, seen[2]);
        ASSERT_EQUALS(3, seen[3]);
    }
コード例 #12
0
ファイル: ustslave.c プロジェクト: Audioniek/Fortis-4G
int loadElf(int cpuf, int fd, unsigned int *entry_p, unsigned int *stack_p, int verbose)
{
   unsigned char buf[BUF_SIZE];
   int ReadBytes = 0, err = 0;

   //EntryPoint
   err = lseek(fd, 0x18, SEEK_SET);
   if(err < 0)
   {
      printf("error lseek(0x18) loadElf\n");
      return 1;
   }

   err = read(fd, &buf, 4);
   if(err != 4)
   {
      printf("error read(4) loadElf\n");
      return 1;
   }

   *entry_p = buf[0]|buf[1]<<8|buf[2]<<16|buf[3]<<24;
   //printf("EntryPoint is 0x%08X\n", *entry_p);

   //seek to the table address field
   err = lseek(fd, 0x20, SEEK_SET);
   if(err < 0)
   {
      printf("error lseek(0x18) loadElf\n");
      return 1;
   }

   err = read(fd, &buf, 4);
   if(err != 4)
   {
      printf("error read(4) loadElf\n");
      return 1;
   }

   unsigned int TableAddress = buf[0]|buf[1]<<8|buf[2]<<16|buf[3]<<24;
   //printf("TableAddress is 0x%08X\n", TableAddress);

   err = lseek(fd, TableAddress, SEEK_SET);
   if(err < 0)
   {
      printf("error lseek(TableAdress) loadElf\n");
      return 1;
   }

   while( (ReadBytes = read(fd, &buf, 10 * sizeof(int))) == (10 * sizeof(int)) ) {

      unsigned int IncreasingNumber   = buf[0]  | buf[1]<<8  | buf[2]<<16  | buf[3]<<24;
      unsigned int Flags              = buf[4]  | buf[5]<<8  | buf[6]<<16  | buf[7]<<24;
      unsigned int DontKnow2          = buf[8]  | buf[9]<<8  | buf[10]<<16 | buf[11]<<24;

      unsigned int DestinationAddress = buf[12] | buf[13]<<8 | buf[14]<<16 | buf[15]<<24;
      unsigned int SourceAddress      = buf[16] | buf[17]<<8 | buf[18]<<16 | buf[19]<<24;
      unsigned int Size               = buf[20] | buf[21]<<8 | buf[22]<<16 | buf[23]<<24;

      unsigned int DontKnow3          = buf[24] | buf[25]<<8 | buf[26]<<16 | buf[27]<<24;
      unsigned int DontKnow4          = buf[28] | buf[29]<<8 | buf[30]<<16 | buf[31]<<24;

      unsigned int Alignment          = buf[32] | buf[33]<<8 | buf[34]<<16 | buf[35]<<24;

      unsigned int DontKnow5          = buf[36] | buf[37]<<8 | buf[38]<<16 | buf[39]<<24;

      if(DestinationAddress == 0x00 && SourceAddress != 0x00) {
         //Source Address is address of description
         err = readDescription(fd, SourceAddress, Size);
         if(err != 0) return 1;
         break; //Exit While
      } else {
         //Add Index to Table
         addIndex(DestinationAddress, SourceAddress, Size, Alignment,
                  Flags, DontKnow2);
      }

   }
   if(ReadBytes != 10 * sizeof(int))
   {
      printf("error ReadBytes\n");
      return 1;
   }
	
   //printTable();

   err = sectionToSlave(cpuf, fd, entry_p);
   if(err != 0) return 1;

   //printf("start address = 0x%08X\n", *entry_p);

   return 0;
}
コード例 #13
0
        void run() {
            Client::WriteContext ctx(ns());
            OperationContextImpl txn;
            Database* db = ctx.ctx().db();
            Collection* coll = db->getCollection(ns());
            if (!coll) {
                coll = db->createCollection(&txn, ns());
            }

            WorkingSet ws;
            // Sort by foo:1
            MergeSortStageParams msparams;
            msparams.pattern = BSON("foo" << 1);
            auto_ptr<MergeSortStage> ms(new MergeSortStage(msparams, &ws, coll));

            IndexScanParams params;
            params.bounds.isSimpleRange = true;
            params.bounds.startKey = objWithMinKey(1);
            params.bounds.endKey = objWithMaxKey(1);
            params.bounds.endKeyInclusive = true;
            params.direction = 1;

            // Index 'a'+i has foo equal to 'i'.

            int numIndices = 20;
            for (int i = 0; i < numIndices; ++i) {
                // 'a', 'b', ...
                string index(1, 'a' + i);
                insert(BSON(index << 1 << "foo" << i));

                BSONObj indexSpec = BSON(index << 1 << "foo" << 1);
                addIndex(indexSpec);
                params.descriptor = getIndex(indexSpec, coll);
                ms->addChild(new IndexScan(params, &ws, NULL));
            }

            set<DiskLoc> locs;
            getLocs(&locs, coll);

            set<DiskLoc>::iterator it = locs.begin();

            // Get 10 results.  Should be getting results in order of 'locs'.
            int count = 0;
            while (!ms->isEOF() && count < 10) {
                WorkingSetID id = WorkingSet::INVALID_ID;
                PlanStage::StageState status = ms->work(&id);
                if (PlanStage::ADVANCED != status) { continue; }

                WorkingSetMember* member = ws.get(id);
                ASSERT_EQUALS(member->loc, *it);
                BSONElement elt;
                string index(1, 'a' + count);
                ASSERT(member->getFieldDotted(index, &elt));
                ASSERT_EQUALS(1, elt.numberInt());
                ASSERT(member->getFieldDotted("foo", &elt));
                ASSERT_EQUALS(count, elt.numberInt());
                ++count;
                ++it;
            }

            // Invalidate locs[11].  Should force a fetch.  We don't get it back.
            ms->prepareToYield();
            ms->invalidate(*it, INVALIDATION_DELETION);
            ms->recoverFromYield();

            // Make sure locs[11] was fetched for us.
            {
            // TODO: If we have "return upon invalidation" ever triggerable, do the following test.
            /*
                WorkingSetID id = WorkingSet::INVALID_ID;
                PlanStage::StageState status;
                do {
                    status = ms->work(&id);
                } while (PlanStage::ADVANCED != status);

                WorkingSetMember* member = ws.get(id);
                ASSERT(!member->hasLoc());
                ASSERT(member->hasObj());
                string index(1, 'a' + count);
                BSONElement elt;
                ASSERT_TRUE(member->getFieldDotted(index, &elt));
                ASSERT_EQUALS(1, elt.numberInt());
                ASSERT(member->getFieldDotted("foo", &elt));
                ASSERT_EQUALS(count, elt.numberInt());
            */

                ++it;
                ++count;
            }

            // And get the rest.
            while (!ms->isEOF()) {
                WorkingSetID id = WorkingSet::INVALID_ID;
                PlanStage::StageState status = ms->work(&id);
                if (PlanStage::ADVANCED != status) { continue; }

                WorkingSetMember* member = ws.get(id);
                ASSERT_EQUALS(member->loc, *it);
                BSONElement elt;
                string index(1, 'a' + count);
                ASSERT_TRUE(member->getFieldDotted(index, &elt));
                ASSERT_EQUALS(1, elt.numberInt());
                ASSERT(member->getFieldDotted("foo", &elt));
                ASSERT_EQUALS(count, elt.numberInt());
                ++count;
                ++it;
            }
        }
コード例 #14
0
        void run() {
            Client::WriteContext ctx(ns());
            Database* db = ctx.ctx().db();
            Collection* coll = db->getCollection(ns());
            if (!coll) {
                coll = db->createCollection(ns());
            }

            for (int i = 0; i < 50; ++i) {
                insert(BSON("_id" << i << "foo" << i << "bar" << i << "baz" << i));
            }

            addIndex(BSON("foo" << 1));
            addIndex(BSON("bar" << 1));
            addIndex(BSON("baz" << 1));

            WorkingSet ws;
            scoped_ptr<AndHashStage> ah(new AndHashStage(&ws, NULL));

            // Foo <= 20 (descending)
            IndexScanParams params;
            params.descriptor = getIndex(BSON("foo" << 1), coll);
            params.bounds.isSimpleRange = true;
            params.bounds.startKey = BSON("" << 20);
            params.bounds.endKey = BSONObj();
            params.bounds.endKeyInclusive = true;
            params.direction = -1;
            ah->addChild(new IndexScan(params, &ws, NULL));

            // Bar <= 19 (descending)
            params.descriptor = getIndex(BSON("bar" << 1), coll);
            params.bounds.startKey = BSON("" << 19);
            ah->addChild(new IndexScan(params, &ws, NULL));

            // First call to work reads the first result from the children.
            // The first result is for the first scan over foo is {foo: 20, bar: 20, baz: 20}.
            // The first result is for the second scan over bar is {foo: 19, bar: 19, baz: 19}.
            WorkingSetID id;
            PlanStage::StageState status = ah->work(&id);
            ASSERT_EQUALS(PlanStage::NEED_TIME, status);

            const unordered_set<WorkingSetID>& flagged = ws.getFlagged();
            ASSERT_EQUALS(size_t(0), flagged.size());

            // "delete" deletedObj (by invalidating the DiskLoc of the obj that matches it).
            BSONObj deletedObj = BSON("_id" << 20 << "foo" << 20 << "bar" << 20 << "baz" << 20);
            ah->prepareToYield();
            set<DiskLoc> data;
            getLocs(&data, coll);
            for (set<DiskLoc>::const_iterator it = data.begin(); it != data.end(); ++it) {
                if (0 == deletedObj.woCompare(it->obj())) {
                    ah->invalidate(*it, INVALIDATION_DELETION);
                    break;
                }
            }
            ah->recoverFromYield();

            // The deleted obj should show up in flagged.
            ASSERT_EQUALS(size_t(1), flagged.size());

            // And not in our results.
            int count = 0;
            while (!ah->isEOF()) {
                WorkingSetID id;
                PlanStage::StageState status = ah->work(&id);
                if (PlanStage::ADVANCED != status) { continue; }
                WorkingSetMember* wsm = ws.get(id);
                ASSERT_NOT_EQUALS(0, deletedObj.woCompare(wsm->loc.obj()));
                ++count;
            }

            ASSERT_EQUALS(count, 20);
        }
コード例 #15
0
void GeometryBuffer::addIndex(uint16 index)
{
	return addIndex((uint8*) &index, sizeof(uint16));
}
コード例 #16
0
void GeometryBuffer::setIndex(uint8* buf, uint32 size)
{
	indexData.clear();
	addIndex(buf, size);
	forceRebuild();
}