Exemple #1
0
void MainWindow::on_input_sct()
{
    const bool needDeg = ui->pushButton_13->isChecked();
    const bool needArc = ui->pushButton_14->isChecked();

    if (ui->pushButton_12->isChecked())
    {
        // Insert "deg()" for arc func
        if (needDeg && needArc)
        {
            doInsert("deg()", -1);
        }

        // Insert the string from the button's text and "arc" button
        doInsert(
              (needArc ? "a" : "")
            + ((QPushButton *) sender())->text()
            + "()"
        , -1);

        // Insert "rad()" for non-arc func
        if (needDeg && !needArc)
        {
            doInsert("rad()", -1);
        }
    }
    else
    {
        // Apply "rad()" for non-arc func
        if (needDeg && !needArc)
        {
            doApply("rad(", ")");
        }

        // Apply the string from the button's text and "arc" button
        doApply(
              (needArc ? "a" : "")
            + ((QPushButton *) sender())->text()
            + "("
        , ")");

        // Apply "deg()" for arc func
        if (needDeg && needArc)
        {
            doApply("deg(", ")");
        }
    }

}
Node* BSTree::doInsert(Node** pNode, const int data)
{
	if (nullptr == *pNode)
	{
		*pNode = new Node(data);
		return *pNode;
	}
	else
	{
		if (data < (*pNode)->data)
			doInsert(&((*pNode)->pLeft), data);
		else
			doInsert(&((*pNode)->pRight), data);
	}
}
Exemple #3
0
/* the test: insert some data, update it and finally delete it */
static sword doWork(char op, char *arg, OCISvcCtx *svcCtx, OCIStmt *stmthp, OCIError *errhp, test_req_t *resp) {
	sword status = OCI_SUCCESS;
	int empno;

	btlogger_debug( "TxLog doWork op=%c arg=%s", op, arg);
	empno = (*arg ? atoi(arg) : 8000);
	(resp->data)[0] = 0;

	if (op == '0') {
		status = doInsert(svcCtx, stmthp, errhp, empno);
	} else if (op == '1') {
		int rcnt = 0;	// no of matching records
		status = doSelect(svcCtx, stmthp, errhp, empno, &rcnt);
	   	btlogger_snprintf(resp->data, sizeof (resp->data), "%d", rcnt);
	} else if (op == '2') {
		status = doUpdate(svcCtx, stmthp, errhp, empno);
	} else if (op == '3') {
		status = doDelete(svcCtx, stmthp, errhp, empno);
	}

	if (status != OCI_SUCCESS)
		get_error(resp, errhp, status);

	return status;
}
void showMenu(){

   printf("     ___   ___      _____ ___ ___ ___       \n");
   printf("     /_\\ \\ / / |    |_   _| _ \\ __| __|  \n");
   printf("    / _ \\ - /| |__    | | |   / _|| _|     \n");
   printf("   /_/ \\_\\_/ |____|   |_| |_|_\\___|___|  \n");
   printf("                     By: Raven G. Duran     \n");
    printf("\n\n");
    printf("(1) Insert a Node\n");
    printf("(2) Delete a Node\n");
    printf("(3) Search a Node\n");
    printf("(4) Print In Order\n");
    printf("(5) Exit\n");

    int choice;
    printf("\n\nChoice: ");
    scanf("%d",&choice);

    switch(choice){
       case 1 : doInsert();   break;
       case 2 : doDelete();   break;
       case 3 : doSearch();   break;
       case 4 : doInOrder();   break;
       default  : exit(0);
    }
}
KviSharedFile * KviSharedFilesManager::addSharedFile(const QString & szName, const QString & szAbsPath, const QString & szMask, int timeoutInSecs)
{
	QFileInfo inf(szAbsPath);
	if(inf.exists() && inf.isFile() && inf.isReadable() && (inf.size() > 0))
	{
		// First find the list
		KviSharedFileList * l = m_pSharedListDict->find(szName);
		if(!l)
		{
			l = new KviSharedFileList;
			l->setAutoDelete(true);
			m_pSharedListDict->replace(szName, l);
		}

		// Now insert
		KviSharedFile * o = new KviSharedFile(szName, szAbsPath, szMask, timeoutInSecs > 0 ? (((int)(time(nullptr))) + timeoutInSecs) : 0, inf.size());

		doInsert(l, o);

		if(((int)o->expireTime()) > 0)
		{
			if(!m_pCleanupTimer->isActive())
				m_pCleanupTimer->start(60000);
		}

		emit sharedFileAdded(o);

		return o;
	}
	else
	{
		qDebug("File %s unreadable: can't add offer", szAbsPath.toUtf8().data());
		return nullptr;
	}
}
Exemple #6
0
void MainWindow::on_input()
{
    // Insert the string from the button's tool tip
    doInsert(
        ((QPushButton *) sender())->toolTip()
    );
}
Exemple #7
0
int database::dbPrivate::baseRecord::doSave()
{
    int err=saveAllRelated();
    if(err!=Basic::OK)
    {
        setError("some related enties couldn't save its value");
        return err;
    }

    if(_hasChanged )
    {
        if(_id.isNull() || _needNewId )
        {
            int err=selectFromUnique();
            if(err==Basic::NOTINDB)
            {
                err=doInsert();
                return err;
            }
        }
        else
        {
            return doUpdate();
        }
    }
    
    return Basic::OK;
}
Exemple #8
0
int database::dbPrivate::baseRecord::insert()
{
    saveAllRelated();
    int ret=doInsert();
    saveValue();
    return ret;
}
void rice::p2p::past::gc::GCPastImpl::insert(::rice::p2p::past::PastContent* obj, int64_t expiration, ::rice::Continuation* command)
{
    if(npc(logger)->level <= ::rice::environment::logging::Logger::FINE)
        npc(logger)->log(::java::lang::StringBuilder().append(u"Inserting data of class "_j)->append(npc(npc(obj)->getClass())->getName())
            ->append(u" under "_j)
            ->append(npc(npc(obj)->getId())->toStringFull())->toString());

    doInsert(npc(obj)->getId(), new GCPastImpl_insert_1(this, obj, expiration), command, npc(socketStrategy)->sendAlongSocket(::rice::p2p::past::rawserialization::SocketStrategy::TYPE_INSERT, obj));
}
Exemple #10
0
void MainWindow::on_input_o()
{
    if (ui->pushButton_12->isChecked())
    {
        // Insert the string from the button's tool tip
        doInsert(
            ((QPushButton *) sender())->toolTip()
        );
    }
    else
    {
        // Apply the string from the button's tool tip
        doApply("(", ")" + ((QPushButton *) sender())->toolTip());
    }
}
Exemple #11
0
void MainWindow::on_input_f()
{
    if (ui->pushButton_12->isChecked())
    {
        // Insert the string from the button's text
        doInsert(
              ((QPushButton *) sender())->text()
            + "()"
        , -1);
    }
    else
    {
        // Apply the string from the button's text
        doApply(((QPushButton *) sender())->text() + "(", ")");
    }
}
void KviSharedFilesManager::addSharedFile(KviSharedFile * f)
{
	// First find the list
	KviSharedFileList * l = m_pSharedListDict->find(f->name());
	if(!l)
	{
		l = new KviSharedFileList;
		l->setAutoDelete(true);
		m_pSharedListDict->replace(f->name(),l);
	}

	doInsert(l,f);

	if(((int)f->expireTime()) > 0)
	{
		if(!m_pCleanupTimer->isActive())m_pCleanupTimer->start(60000);
	}

	emit sharedFileAdded(f);
}
Exemple #13
0
void MainWindow::on_input_scth()
{
    const bool needArc = ui->pushButton_14->isChecked();

    if (ui->pushButton_12->isChecked())
    {
        // Insert the string from the button's text and "arc" button
        doInsert(
              (needArc ? "a" : "")
            + ((QPushButton *) sender())->text()
            + "()"
        , -1);
    }
    else
    {
        // Apply the string from the button's text and "arc" button
        doApply(
              (needArc ? "a" : "")
            + ((QPushButton *) sender())->text()
            + "("
        , ")");
    }
}
void testRandom(size_t numSteps = 10000) {
  describePlatform();

  auto target = folly::make_unique<T>();
  std::vector<bool> valid;

  for (size_t step = 0; step < numSteps; ++step) {
    auto pct = folly::Random::rand32(100);
    auto v = folly::Random::rand32(uint32_t{3} << folly::Random::rand32(14));

    if (pct < 5) {
      doClear(*target, valid);
    } else if (pct < 30) {
      T copy;
      folly::resizeWithoutInitialization(copy, target->size());
      for (size_t i = 0; i < copy.size(); ++i) {
        if (valid[i]) {
          copy[i] = target->at(i);
        }
      }
      if (pct < 10) {
        std::swap(copy, *target);
      } else if (pct < 15) {
        *target = std::move(copy);
      } else if (pct < 20) {
        *target = copy;
      } else if (pct < 25) {
        target = folly::make_unique<T>(std::move(copy));
      } else {
        target = folly::make_unique<T>(copy);
      }
    } else if (pct < 35) {
      target->reserve(v);
    } else if (pct < 40) {
      target->shrink_to_fit();
    } else if (pct < 45) {
      doResize(*target, valid, v);
    } else if (pct < 50) {
      doInsert(*target, valid, v % (target->size() + 1));
    } else if (pct < 55) {
      if (!target->empty()) {
        doErase(*target, valid, v % target->size());
      }
    } else if (pct < 60) {
      doPushBack(*target, valid);
    } else if (pct < 65) {
      target = folly::make_unique<T>();
      valid.clear();
    } else if (pct < 80) {
      auto v2 = folly::Random::rand32(uint32_t{3} << folly::Random::rand32(14));
      doOverwrite(*target, valid, std::min(v, v2), std::max(v, v2));
    } else {
      doResizeWithoutInit(*target, valid, v);
    }

    // don't check every time in implementation does lazy work
    if (folly::Random::rand32(100) < 50) {
      check(*target);
    }
  }
}
Node* BSTree::Insert(const int data)
{
	return doInsert(&pRoot, data);
}
Exemple #16
0
    PlanStage::StageState UpdateStage::work(WorkingSetID* out) {
        ++_commonStats.works;

        // Adds the amount of time taken by work() to executionTimeMillis.
        ScopedTimer timer(&_commonStats.executionTimeMillis);

        if (isEOF()) { return PlanStage::IS_EOF; }

        if (doneUpdating()) {
            // Even if we're done updating, we may have some inserting left to do.
            if (needInsert()) {
                doInsert();
            }

            // At this point either we're done updating and there was no insert to do,
            // or we're done updating and we're done inserting. Either way, we're EOF.
            invariant(isEOF());
            return PlanStage::IS_EOF;
        }

        // If we're here, then we still have to ask for results from the child and apply
        // updates to them. We should only get here if the collection exists.
        invariant(_collection);

        WorkingSetID id = WorkingSet::INVALID_ID;
        StageState status = _child->work(&id);

        if (PlanStage::ADVANCED == status) {
            // Need to get these things from the result returned by the child.
            DiskLoc loc;
            BSONObj oldObj;

            WorkingSetMember* member = _ws->get(id);

            if (!member->hasLoc()) {
                _ws->free(id);
                const std::string errmsg = "update stage failed to read member w/ loc from child";
                *out = WorkingSetCommon::allocateStatusMember(_ws, Status(ErrorCodes::InternalError,
                                                                          errmsg));
                return PlanStage::FAILURE;
            }
            loc = member->loc;

            // Updates can't have projections. This means that covering analysis will always add
            // a fetch. We should always get fetched data, and never just key data.
            invariant(member->hasObj());
            oldObj = member->obj;

            // If we're here, then we have retrieved both a DiskLoc and the corresponding
            // unowned object from the child stage. Since we have the object and the diskloc,
            // we can free the WSM.
            _ws->free(id);

            // We fill this with the new locs of moved doc so we don't double-update.
            if (_updatedLocs && _updatedLocs->count(loc) > 0) {
                // Found a loc that we already updated.
                ++_commonStats.needTime;
                return PlanStage::NEED_TIME;
            }

            ++_specificStats.nMatched;

            // Do the update and return.
            transformAndUpdate(oldObj, loc);
            ++_commonStats.needTime;
            return PlanStage::NEED_TIME;
        }
        else if (PlanStage::IS_EOF == status) {
            // The child is out of results, but we might not be done yet because we still might
            // have to do an insert.
            ++_commonStats.needTime;
            return PlanStage::NEED_TIME;
        }
        else if (PlanStage::FAILURE == status) {
            *out = id;
            // If a stage fails, it may create a status WSM to indicate why it failed, in which case
            // 'id' is valid.  If ID is invalid, we create our own error message.
            if (WorkingSet::INVALID_ID == id) {
                const std::string errmsg = "delete stage failed to read in results from child";
                *out = WorkingSetCommon::allocateStatusMember(_ws, Status(ErrorCodes::InternalError,
                                                                          errmsg));
                return PlanStage::FAILURE;
            }
            return status;
        }
        else {
            if (PlanStage::NEED_TIME == status) {
                ++_commonStats.needTime;
            }
            return status;
        }
    }
Exemple #17
0
    bool WriteBatchExecutor::doWrite( const string& ns,
                                      const BatchItemRef& itemRef,
                                      CurOp* currentOp,
                                      WriteStats* stats,
                                      BSONObj* upsertedID,
                                      BatchedErrorDetail* error ) {

        const BatchedCommandRequest& request = *itemRef.getRequest();
        int index = itemRef.getItemIndex();

        //
        // Check our shard version if we need to (must be in the write lock)
        //

        if ( shardingState.enabled() && request.isShardVersionSet()
             && !ChunkVersion::isIgnoredVersion( request.getShardVersion() ) ) {

            Lock::assertWriteLocked( ns );
            CollectionMetadataPtr metadata = shardingState.getCollectionMetadata( ns );
            ChunkVersion shardVersion =
                metadata ? metadata->getShardVersion() : ChunkVersion::UNSHARDED();

            if ( !request.getShardVersion() //
                .isWriteCompatibleWith( shardVersion ) ) {

                // Write stale error to results
                error->setErrCode( ErrorCodes::StaleShardVersion );

                BSONObjBuilder infoB;
                shardVersion.addToBSON( infoB, "vWanted" );
                error->setErrInfo( infoB.obj() );

                string errMsg = mongoutils::str::stream()
                    << "stale shard version detected before write, received "
                    << request.getShardVersion().toString() << " but local version is "
                    << shardVersion.toString();
                error->setErrMessage( errMsg );

                return false;
            }
        }

        //
        // Not stale, do the actual write
        //

        if ( request.getBatchType() == BatchedCommandRequest::BatchType_Insert ) {

            // Insert
            return doInsert( ns,
                             request.getInsertRequest()->getDocumentsAt( index ),
                             currentOp,
                             stats,
                             error );
        }
        else if ( request.getBatchType() == BatchedCommandRequest::BatchType_Update ) {

            // Update
            return doUpdate( ns,
                             *request.getUpdateRequest()->getUpdatesAt( index ),
                             currentOp,
                             stats,
                             upsertedID,
                             error );
        }
        else {
            dassert( request.getBatchType() ==
                BatchedCommandRequest::BatchType_Delete );

            // Delete
            return doDelete( ns,
                             *request.getDeleteRequest()->getDeletesAt( index ),
                             currentOp,
                             stats,
                             error );
        }
    }