Exemplo n.º 1
0
void updateTree(forTree *var, char *str, int level){

    if(strcmp(var->str, str)>0){
        if(var->left!=NULL){
            updateTree(var->left, str, level);
        }
        else{
            var->left = (forTree *)malloc(sizeof(forTree));
            var->level=level;
            char *temp = (char *) malloc(sizeof(char)*strlen(str));
            strcpy(temp,str);
            var->str = temp;
            return;
        }
    }
    else if(strcmp(var->str, str)<0){
        if(var->right!=NULL){
            updateTree(var->right, str, level);
        }
        else{
            var->right = (forTree *)malloc(sizeof(forTree));
            var->level = level;
            char *temp = (char *) malloc(sizeof(char)*strlen(str));
            strcpy(temp,str);
            var->str = temp;
            return;
        }
    }
    else{
        var->str = str;
        var->level = level;
        return;
    }

}
void updateTree(int x, int l, int r, int v)
{
    if(node[x].l == l && node[x].r == r)
    {
        node[x].sum += v * nodeLength(x);
        node[x].update += v;
    }
    else
    {
        updateTreeNode(x);
        int mid = midium(node[x].l, node[x].r);
        if(r <= mid)
        {
            updateTree(left(x), l, r, v);
        }
        else if(l > mid)
        {
            updateTree(right(x), l, r, v);
        }
        else
        {
            updateTree(left(x), l, mid, v);
            updateTree(right(x), mid + 1, r, v);
        }
        node[x].sum = node[left(x)].sum + node[right(x)].sum;
    }
}
void updateTree(SegTreeNode* root, int i, int val) {
    if (root->start == root->end) {
        root->sum = val;
    } else {
        int mid = root->start + (root->end - root->start) / 2;
        if (i <= mid) {
            updateTree(root->left, i, val);
        } else {
            updateTree(root->right, i, val);
        }
        root->sum = root->left->sum + root->right->sum;
    }
}
 void updateTree(int treeIndex, int lo, int hi, int arrIndex, int val) {
     if (lo == hi) {
         tree[treeIndex] = val;
         return;
     }
     
     int mid = lo + (hi-lo)/2;
     
     if (arrIndex > mid) 
         updateTree(2*treeIndex+2, mid+1, hi, arrIndex, val);
     else if (arrIndex<=mid)
         updateTree(2*treeIndex+1, lo, mid, arrIndex, val);
 
     tree[treeIndex] = tree[2*treeIndex+1] + tree[2*treeIndex+2];
 }
Exemplo n.º 5
0
int main() {
    int n, q;
    geti(n, q);
    for(int i = 1; i < n; i++) {
        int u, v;
        geti(u, v);
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    init(n);
    dfs(0, -1);
    HLD(0, -1);

    while(q--) {
        int type, x;
        geti(type, x);
        x--;
        if(type == 0) {
            updateTree(x);
        } else {
            printf("%d\n", queryTree(x));
        }
    }
}
Exemplo n.º 6
0
//!
//!
//! \return True, if successful loading of ogre mesh
//!            False, otherwise.
//!
bool XmlTreeReaderNode::loadFile()
{
    QString filename = getStringValue("Source File");
    if (filename == "") {
        Log::debug(QString("Source file has not been set yet. (\"%1\")").arg(m_name), "XmlTreeReaderNode::loadFile");
        return false;
    }

    // check if the file exists
    if (!QFile::exists(filename)) {
        Log::error(QString("Source file \"%1\" not found.").arg(filename), "XmlTreeReaderNode::loadFile");
        return false;
    }

	if (!filename.endsWith(".xml") && !filename.endsWith(".txt")) {
        Log::error("The source file has to be a csv or txt.", "XmlTreeReaderNode::loadFile");
        return false;
    }

	// if any, delete previous file
	if (m_xmltree)
		m_xmltree->Delete();

	// create and load new file
	m_xmltree = vtkXMLTreeReader::New();
	m_xmltree->SetFileName(filename.toLatin1().constData());
	m_xmltree->Update();
	updateTree();

    Log::info(QString("Source file \"%1\" loaded.").arg(filename), "XmlTreeReaderNode::loadFile");
	// Log::info(QString("Number rows \"%1\" loaded: ").arg(m_Tree->GetNumberOfRows()), "XmlTreeReaderNode::loadFile");
    return true;
}
Exemplo n.º 7
0
int main()
{
	int n = 0;
	for(int i = 1; i < 11; ++ i) for(int j = 0; j < i; ++ j) cout[i][j] = n ++;
	while(~scanf("%d", &n))
	{
		BuildTree(1, 1, n);
		for(int i = 1; i <= n; ++ i)
			scanf("%d", &ele[i]);

		int q;
		scanf("%d", &q);
		while(q--)
		{
			int t;
			scanf("%d", &t);
			if(t == 1)
			{
				int a, b, k, c;
				scanf("%d %d %d %d", &a, &b, &k, &c);
				updateTree(1, a, b, k, c, a % k);
			}
			else
			{
				int a;
				scanf("%d", &a);
				int ans = queryTree(1, a, 0);
				printf("%d\n", ele[a] + ans);
			}
		}
	}
	return 0;
}
void manager::showTreeGame() {
    std::cout << "showTreeGame()" << std::endl;

//    std::string out = tree_.Print();
    if (gameTreeView) {
        gameTreeView->raise();
        gameTreeView->activateWindow();
        return;
    }
    //create new window
//    std::string out = tree_.Print();
    std::cout << "GTREE" << std::endl
              << tree_.Print()
              << std::endl
              << "END" << std::endl;
    gameTreeView = new GAME_View(tree_);

//    connect();
//    connect();
    connect(this, SIGNAL(movePlayed()), gameTreeView, SLOT(updateTree()));
    connect(gameTreeView, SIGNAL(moveChanged()), this, SLOT(changeCurrent()));
    connect(gameTreeView, SIGNAL(finished(int)), this, SLOT(closeTreeGame()));

    gameTreeView->show();
}
Exemplo n.º 9
0
void GUIImport::on_lineEdit_Filename_textChanged()
{
	m->FileName = this->ui->lineEdit_Filename->text().toStdString();
	this->m->init();

	updateTree();
}
int main()
{
    char op[5];
    int a, b, c;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;++i)
        {
            scanf("%lld", &num[i]);
        }
        createTree(1, 1, n);
        while(m--)
        {
            scanf("%s", &op);
            switch(*op)
            {
            case 'Q':
                scanf("%d%d",&a,&b);
                printf("%lld\n", searchTree(1, a, b));
                break;
            case 'C':
                scanf("%d%d%d",&a,&b,&c);
                updateTree(1, a, b, c);
                break;
            }
        }
    }
    return 0;
}
Exemplo n.º 11
0
void SquareTreeGraphicsScene::stopHighlighting()
{
    if (m_highlightedLine != 0)
    {
        m_highlightedLine->unhighlight();
        m_highlightedLine = 0;
        updateTree();

        if (g_settings->simulationShown)
            m_landscapeView->viewport()->update();
    }

    m_selectionDot.reset();

    if (g_mainWindow->m_historyOrganismWidget->m_organism != 0)
    {
        g_mainWindow->m_historyOrganismWidget->m_organism = 0;
        g_mainWindow->m_historyOrganismWidget->update();
    }

    if (g_mainWindow->m_landscapeHistoryWidget->m_organismPositions != 0)
    {
        g_mainWindow->m_landscapeHistoryWidget->m_organismPositions = 0;
        g_mainWindow->m_landscapeHistoryWidget->update();
    }

    m_selectionDate = -1; //indicates no selected date
    g_mainWindow->clearHistorySpecies();
}
Exemplo n.º 12
0
void ANNModelWrapper::onLayerRemoved(int index)
{
	updateTree();

	beginRemoveRows(createIndex(-1, -1), index, index);
	endRemoveRows();
}
EditeurTache::EditeurTache(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::EditeurTache)
{
    ui->setupUi(this);
    this->setModal(true);
    ui->stackedWidget->setCurrentIndex(0);
    ui->dateEditDispo->setDate(QDate::currentDate());
    ui->dateEditEch->setDate(QDate::currentDate());

    ui->comboBoxProjet->addItem(" ");
    ui->comboBoxMere->addItem(" ");
    //boucle pour remplir la combobox proposant les projets
    for(QMap<QString, Projet*>::const_iterator it= ProjetManager::getInstance().getProjets().cbegin();it!=ProjetManager::getInstance().getProjets().cend(); it++){
        if ((*it)->getDateEcheance()>=QDate::currentDate())
            ui->comboBoxProjet->addItem((*it)->getNom());
    }

    QObject::connect(ui->radioButtonUnit, SIGNAL(clicked(bool)),this,SLOT(showPropUnit(bool)));//affiche la partie demandant les prop des taches unitaire
    QObject::connect(ui->radioButtonComp, SIGNAL(clicked(bool)),this,SLOT(showPropComp(bool)));//affiche la partie demandant les prop des taches composites
    QObject::connect(ui->comboBoxProjet, SIGNAL(currentIndexChanged(QString)), this, SLOT(remplirComboMere(QString))); //affiche les tâches mères possible en fonction du projet séléctionné
    QObject::connect(ui->comboBoxProjet, SIGNAL(currentIndexChanged(QString)), this, SLOT(setDates(QString)));//Par défaut, initialise les dates de dispo et d'échéance en fonction de celles du projet
    QObject::connect(ui->pushButtonAjouter, SIGNAL(clicked()), this, SLOT(choixPrec()));//affiche nouvelle fenetre pour choisir les taches de précédence
    QObject::connect(ui->pushButtonOK, SIGNAL(clicked()), this, SLOT(enregisterTache()));
    QObject::connect(ui->pushButtonOK, SIGNAL(clicked()),parent,SLOT(updateTree()));
    QObject::connect(ui->pushButtonAnnuler, SIGNAL(clicked()),this,SLOT(close()));
    QObject::connect(this, SIGNAL(finished(int)),parent,SLOT(updateTree()));
}
Exemplo n.º 14
0
void MainWindow::on_actionConvertDirectory_triggered()
{
    QString dirName;

    /* request directory name from user */
    dirName = QFileDialog::getExistingDirectory(this,tr("Parse and convert Directory"));

    if(dirName.isEmpty())
    {
        /* no directory selected, return */
        return;
    }

    /* create progress dialog */
    QProgressDialog progress("Convert Directory...", "Abort converting", 0, 100, this);
    progress.setWindowModality(Qt::WindowModal);

    /* go through all files in the directory */
    if(!parseDirectory(dirName,parseTypeMessages,true,true,progress))
    {
        QMessageBox::warning(this,"Converte Directory",parser.getLastError());
        return;
    }

    /* update tree */
    updateTree();

    /* information about end of operation */
    QMessageBox::information(0, QString("DLT Parser"),
                         QString("Parsing and converting directory finished!"));
}
Exemplo n.º 15
0
void MainWindow::on_actionUpdate_IDs_per_application_triggered()
{
    /* start with message id provided by user */
    bool ok;

    uint32_t messageIdStart=1;
    QString text = QInputDialog::getText(this, tr("Update IDs)"),
                                         tr("Start Message Id per App:"), QLineEdit::Normal,
                                         QString("%1").arg(1), &ok);
    if (ok)
        messageIdStart = text.toUInt();
    else
        return;

    uint32_t messageIdEnd=1;
    text = QInputDialog::getText(this, tr("Update IDs)"),
                                         tr("End Message Id per App:"), QLineEdit::Normal,
                                         QString("%1").arg(0xffffffff), &ok);
    if (ok)
        messageIdEnd = text.toUInt();
    else
        return;

    if(!parser.generateId(messageIdStart,messageIdEnd,true))
    {
        QMessageBox::warning(this,"Update IDs per application",parser.getLastError());
    }

    /* update tree */
    updateTree();
}
Exemplo n.º 16
0
CCvProject::CCvProject(CSerialThread* serialThread, QWidget* parent) :
    CGenericProject(serialThread, parent)
{
    Q_ASSERT(serialThread);
    //Q_ASSERT(parent);

    initPlot();
    initFields();

    mp_serialThread = serialThread;
    updateTree();

    // testing
    /*quint16 t;
    union32_t x;
    union32_t y;
    t = 0;
    x.idFl = 0.5;
    y.idFl = 0.001;
    on_received_giveMeasChunkCv(t, x, y);

    t = 1;
    x.idFl = 1;
    y.idFl = 0.005;
    on_received_giveMeasChunkCv(t, x, y);

    t = 2;
    x.idFl = 0.7;
    y.idFl = 0.003;
    on_received_giveMeasChunkCv(t, x, y);

    insertLabels();*/
}
Exemplo n.º 17
0
void MainWindow::on_actionConvertFile_triggered()
{
    QString fileName;

    /* request filename from user */
    fileName = QFileDialog::getOpenFileName(this,
        tr("Parse and convert Source file"), "", tr("Source file (*.c;*.cpp;*.cxx);;All files (*.*)"));

    if(fileName.isEmpty())
    {
        /* no directory selected, return */
        return;
    }

    /* parse and convert file to find all log entries */
    if(!parser.converteFile(fileName))
    {
        QMessageBox::warning(this,"Converte File",parser.getLastError());
        return;
    }

    /* update tree */
    updateTree();

}
Exemplo n.º 18
0
AudioTriggersConfiguration::AudioTriggersConfiguration(VCAudioTriggers *triggers, Doc *doc,
                                                       int bandsNumber, int maxFrequency)
    : QDialog(triggers)
    , m_doc(doc)
    , m_maxFrequency(maxFrequency)
{
    setupUi(this);

    m_triggers = triggers;

    m_nameEdit->setText(m_triggers->caption());

    m_barsNumSpin->setFixedWidth(70);
    m_barsNumSpin->setFixedHeight(30);
    m_barsNumSpin->setValue(bandsNumber);

    connect(m_barsNumSpin, SIGNAL(valueChanged(int)),
            this, SLOT(updateTree()));

    /* External input */
    m_inputSelWidget = new InputSelectionWidget(m_doc, this);
    m_inputSelWidget->setCustomFeedbackVisibility(true);
    m_inputSelWidget->setKeySequence(m_triggers->keySequence());
    m_inputSelWidget->setInputSource(m_triggers->inputSource());
    m_inputSelWidget->setWidgetPage(m_triggers->page());
    m_inputSelWidget->show();
    m_extControlLayout->addWidget(m_inputSelWidget);

    m_tree->setAlternatingRowColors(true);
    m_tree->setRootIsDecorated(false);
    m_tree->setSelectionMode(QAbstractItemView::NoSelection);
    m_tree->setAllColumnsShowFocus(true);

    updateTree();
}
Exemplo n.º 19
0
void MainWindow::on_action_Open_triggered()
{
    QString fileName;

    /* request filename from user */
    fileName = QFileDialog::getOpenFileName(this,
        tr("DLT Non verbose Fibex file"), "", tr("Description Files (*.xml);;All files (*.*)"));

    if(fileName.isEmpty())
    {
        /* no file selected from user */
        return;
    }

    /* update file name */
    fibexFileName = fileName;
    filenameWidget->setText(fibexFileName);

    /* read Fibex file */
    if(!parser.readFibex(fileName))
    {
        QMessageBox::warning(this,"Open Fibex",parser.getLastError());
    }

    /* update tree */
    updateTree();

}
Exemplo n.º 20
0
GUIImport::GUIImport(DM::Module *m, QWidget *parent) :
	QDialog(parent),
	ui(new Ui::GUIImport)
{
	this->m = (Import*) m;
	ui->setupUi(this);
	treeCheckMapper = NULL;

	this->ui->lineEdit_Filename->setText(QString::fromStdString(this->m->FileName));
	this->ui->checkBox_append_existing->setChecked(this->m->append);

	this->ui->lineEdit_wfs_server->setText(QString::fromStdString(this->m->WFSServer));
	this->ui->lineEdit_wfs_username->setText(QString::fromStdString(this->m->WFSUsername));

	oldpwd = this->m->crypto.decryptToString(QString::fromStdString(this->m->WFSPassword));
	this->ui->lineEdit_wfs_password->setText(oldpwd);

	this->ui->epsgCode->setValue(this->m->epsgcode);
	this->ui->checkBox_flip->setChecked(this->m->flip_wfs);
	this->ui->checkBox_linkWithExistingView->setChecked(this->m->linkWithExistingView);

	this->ui->lineEdit_offx->setText(QString::number(this->m->offsetX));
	this->ui->lineEdit_offy->setText(QString::number(this->m->offsetY));

	updateTree();
}
Exemplo n.º 21
0
OutputManager::OutputManager(QWidget* parent, Qt::WindowFlags flags)
	: QWidget(parent, flags)
{
	/* Create a new layout for this widget */
	new QVBoxLayout(this);

	/* Toolbar */
	m_toolbar = new QToolBar(tr("Output Manager"), this);
	m_toolbar->addAction(QIcon(":/edit.png"), tr("Edit Mapping"),
			     this, SLOT(slotEditClicked()));
	layout()->addWidget(m_toolbar);

	/* Tree */
	m_tree = new QTreeWidget(this);
	layout()->addWidget(m_tree);
	m_tree->setRootIsDecorated(false);
	m_tree->setItemsExpandable(false);
	m_tree->setSortingEnabled(false);
	m_tree->setAllColumnsShowFocus(true);

	QStringList columns;
	columns << tr("Universe") << tr("Plugin") << tr("Output");
	m_tree->setHeaderLabels(columns);

	connect(m_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
		this, SLOT(slotEditClicked()));

	updateTree();
}
Exemplo n.º 22
0
void MainWindow::on_actionParseFile_triggered()
{
    QString fileName;

    /* request filename from user */
    fileName = QFileDialog::getOpenFileName(this,
        tr("Parse Source file"), "", tr("Source file (*.c *.cpp *.cxx *.h *.hpp *.hxx);;All files (*.*)"));

    if(fileName.isEmpty())
    {
        /* no directory selected, return */
        return;
    }

    // parse file
    if(!parser.parseFile(fileName))
    {
        QMessageBox::warning(this,"Parse File",parser.getLastError());
        return;
    }

    // update message ids and application/context ids
    if(!parser.parseCheck())
    {
        QMessageBox::warning(this,"Parse File",parser.getLastError());
        return;
    }

    /* update tree */
    updateTree();

}
Exemplo n.º 23
0
void MainWindow::on_action_New_triggered()
{
    /* clear tree of contexts and log entries */
    parser.clear();
    updateTree();
    fibexFileName.clear();
    filenameWidget->setText("");
}
Exemplo n.º 24
0
void updateTree(int now, int l, int r, int k, int c, int lModk)
{
	if(l == TL && r == TR)
	{
		TA[cout[k][lModk]] += c;
		return ;
	}
	if(l <= TM && r >= TM + 1)
	{
		updateTree(LSon, l, TM, k, c, lModk);
		updateTree(RSon, TM + 1, r, k, c, lModk);
	}
	else if(l > TM)
		updateTree(RSon, l, r, k, c, lModk);
	else
		updateTree(LSon, l, r, k, c, lModk);
}
Exemplo n.º 25
0
	void updateTree(TreeNode* root, int row, int col, int val){
		if(root->tlRow == row && root->brRow == row && root->tlCol == col && root->brCol == col){
			root->sum = val;
			return ;
		}
		int midRow = root->tlRow + (root->brRow - root->tlRow) / 2;
		int midCol = root->tlCol + (root->brCol - root->tlCol) / 2;
		if(row <= midRow && col <= midCol)
			updateTree(root->nw, row, col, val);
		else if(row <= midRow && col > midCol)
			updateTree(root->ne, row, col, val);
		else if(row > midRow && col <= midCol)
			updateTree(root->sw, row, col, val);
		else
			updateTree(root->se, row, col, val);
		root->sum = root->nw ? root->nw->sum : 0 + root->ne ? root->ne->sum : 0 + root->sw ? root->sw->sum : 0 + root->se ? root->se->sum : 0;
	}
Exemplo n.º 26
0
// virtual
bool CMathExpression::compile()
{
  mPrerequisites.clear();
  mUsable = true;

  if (!updateTree())
    {
      mUsable = false;
      mCalculationSequence.resize(0);

      return mUsable;
    }

  std::vector< CEvaluationNode * >::iterator it = mpNodeList->begin();
  std::vector< CEvaluationNode * >::iterator end = mpNodeList->end();

  for (; it != end; ++it)
    {
      mUsable &= (*it)->compile(this);

      if ((*it)->mainType() == CEvaluationNode::T_OBJECT &&
          (*it)->subType() == CEvaluationNode::S_POINTER)
        {
          void * pValue = stringToPointer((*it)->getData());

          CMathObject * pMathObject = pMathContainer->getMathObject((C_FLOAT64 *) pValue);

          if (pMathObject != NULL)
            {
              mPrerequisites.insert(pMathObject);
            }
          else
            {
              CCopasiObject * pDataObject = pMathContainer->getDataObject((C_FLOAT64 *) pValue);

              if (pDataObject != NULL)
                {
                  mPrerequisites.insert(pDataObject);
                }
              else
                {
                  // This must never happen
                  fatalError();
                }
            }
        }
    }

  if (mInfix == "@")
    {
      mUsable = true;
    }

  buildCalculationSequence();

  return mUsable;
}
Exemplo n.º 27
0
LRESULT PublicHubsFrame::onClickedConfigure(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	PublicHubListDlg dlg;
	if (dlg.DoModal(m_hWnd) == IDOK)
	{
		updateTree();
	}
	return 0;
}
Exemplo n.º 28
0
void updateTree(int index, int pos, int bl, int br, int val)
{
  if(bl == br)
  {
    tree[index].sum = val;
    tree[index].pref_sum = tree[index].suff_sum = tree[index].ans = max(0, val);
    return;
  }
  int localCenter = bl + (br - bl) / 2;
  if(pos <= localCenter)
  {
    updateTree(index * 2 + 1, pos, bl, localCenter, val);
  }
  else
  {
    updateTree(index * 2 + 2, pos, localCenter + 1, br, val);
  }
  tree[index] = combine(tree[index * 2 + 1], tree[index * 2 + 2]);
}
Exemplo n.º 29
0
void XmlTreeWidget::slotReload()
{
    clear();
    if(m_tree != 0) {
        if(m_tree->root() != 0) {
            updateTree(m_tree->root(), 0);
            topLevelItem(0)->setExpanded(true);
        }
    }
}
Exemplo n.º 30
0
void InputManager::slotEditClicked()
{
    QTreeWidgetItem* item = m_tree->currentItem();
    if (item == NULL)
        return;

    quint32 universe = item->text(KColumnUniverse).toInt() - 1;
    InputPatchEditor ipe(this, universe, m_inputMap);
    if (ipe.exec() == QDialog::Accepted)
        updateTree();
}