BinaryTree* deleteNode1(int val, BinaryTree *tree) { BinaryTree *res=NULL; res = malloc(sizeof(BinaryTree)); if(haveNode(val,tree))//condition : le noeud est présent { if(nodeValue(tree)==val)// si le noeud est trouvée { if(rightChild(tree)==NULL)// sous arbre droit nul on retourne le sous arbre gauche { res=leftChild(tree); } else// sous arbre gauche nul on retourne le sous arbre droit { res=rightChild(tree); } } else// sinon on cherche dans les sous arbres droits et gauches { res=createNodeWithChilds(deleteNode1(val,leftChild(tree)),nodeValue(tree),deleteNode1(val,rightChild(tree))); } } else// si le noeud n'est pas présent, on retourne l'arbre d'entrée { res=tree; } return res; }
/* * Vérificateur */ Bool haveNode(int val, BinaryTree* tree) { Bool res; if(isLeaf(tree))//si l'arbre est une feuille { if(nodeValue(tree)==val)//si la feuille est presente, on retourne vrai { res=TRUE; } else // sinon faux { res=FALSE; } } else { if(nodeValue(tree)==val)//si le noeud est present, on retourne vrai { res=TRUE; } else// appel recursif : la valeur est presente dans le sous arbre droit OU dans le sous arbre gauche { res=(haveNode(val,rightChild(tree)))||(haveNode(val,leftChild(tree))); } } return res; }
BinaryTree* insertNode(int val, BinaryTree *tree) { if(tree == NULL) return createNodeWithChilds(NULL, val, NULL); if(val <= nodeValue(tree)) tree->Left = insertNode(val, tree->Left); else if(val > nodeValue(tree)) tree->Right = insertNode(val, tree->Right); return tree; }
nodeValue declNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions){ nodeValue ret = nodeValue(0); scope->decl(varName, type, (void *) classDefs); ret.varName = varName; ret.type = NVVAR; return ret; }
nodeValue memberNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions){ LSRValue v = scope->resolveMembers((void*) ma, (void *) classDefs); nodeValue ret = nodeValue(); if (!v.getType().compare("int")) { ret = nodeValue(v.intVal); ret.type = NVINT; } else if (!v.getType().compare("str")) { ret.st = v.getStrVal(); ret.strLen = 0; ret.type = NVSTR; } else { ret.objPtr = v.getObjectPointer(); ret.type = NVVAR; } return ret; }
nodeValue strNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions) { nodeValue v = nodeValue(0); v.type=NVSTR; v.st = strVal; v.strLen = 0; return v; }
QVariantList QVariantTree::itemContainerKeys() const { Q_ASSERT(nodeIsContainer()); QVariantTreeElementContainer* containerType = containerOf(nodeType()); Q_ASSERT_X(containerType != 0, "QVariantTree", "cannot find container of type"); return containerType->keys(nodeValue()); }
void QVariantTree::moveToParent() { if (!nodeIsRoot()) { _address.removeLast(); _nodeType = nodeValue().type(); } }
float DTree::probability(vector<bool> l){ vector<bool>::iterator it_node; vector<vector<float> >::iterator it_data; int correct=0, size=0; float value = nodeValue(l); float sum=0.0F, sum2=0.0F, mean, sigma2; if (fieldsType.at(predictee).first == ENU){ for (it_node=l.begin(), it_data=data.begin(); it_data!=data.end(); it_data++, it_node++) if (*it_node){ if (value == it_data->at(predictee)) correct++; size++; } return correct*1.0F/size; cerr << correct << " " << size << endl; }else if(fieldsType.at(predictee).first == FLT){ for (it_node=l.begin(), it_data=data.begin(); it_data!=data.end(); it_data++, it_node++) if (*it_node){ sum += it_data->at(predictee); sum2 += it_data->at(predictee)*it_data->at(predictee); size++; } mean = sum/size; sigma2=sum2/size - mean*mean; if (sigma2==0) return 1; return (1/sqrt(2*PI*sigma2));//*exp(-1*(value-mean)*(value-mean)/(2*sigma2))); // Second part is one } return -1; }
void InspectorNodeFinder::searchUsingDOMTreeTraversal(Node* parentNode) { // Manual plain text search. for (auto node = parentNode; node; node = NodeTraversal::next(node, parentNode)) { switch (node->nodeType()) { case Node::TEXT_NODE: case Node::COMMENT_NODE: case Node::CDATA_SECTION_NODE: { if (node->nodeValue().findIgnoringCase(m_whitespaceTrimmedQuery) != notFound) m_results.add(node); break; } case Node::ELEMENT_NODE: { if (matchesElement(*toElement(node))) m_results.add(node); // Search inside frame elements. if (node->isFrameOwnerElement()) { HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); if (Document* document = frameOwner->contentDocument()) performSearch(document); } break; } default: break; } } }
QVariant QVariantTree::getItemContainer(const QVariant& key, const QVariant& defaultValue) const { Q_ASSERT(nodeIsContainer()); QVariantTreeElementContainer* containerType = containerOf(nodeType()); Q_ASSERT_X(containerType != 0, "QVariantTree", "cannot find container of type"); return containerType->item(nodeValue(), key, defaultValue); }
nodeValue assignNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions){ nodeValue l = lhs.execute(scope, classDefs,functions); nodeValue r = rhs.execute(scope,classDefs,functions); if (lhs.isLValue()) { if (lhs.isMember()) { // safe to downcast... if isMember() is true then it must be a memberNode. memberNode& cast = static_cast<memberNode&>(lhs); scope->memberAssign(cast.ma,r.toVal(scope,classDefs),(void *) classDefs); } else { scope->assign(l.varName,r.toVal(scope,classDefs),(void *) classDefs); } } else { return nodeValue(0); } return nodeValue(0); }
nodeValue printNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions){ nodeValue temp = expr.execute(scope,classDefs,functions); LSRValue val = temp.toVal(scope,classDefs); std::cout << val.toString(); if(printLine) { std::cout << std::endl; } return nodeValue(0); }
nodeValue varNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions){ LSRValue v = scope->resolve(varName); nodeValue ret = nodeValue(); // TODO: add for not just ints. if (!v.getType().compare("int")) { ret = nodeValue(v.intVal); ret.type = NVINT; } else if (!v.getType().compare("str")) { ret.st = v.getStrVal(); ret.strLen = 0; ret.type = NVSTR; } else { ret.objPtr = v.getObjectPointer(); ret.varName = varName; ret.type = NVVAR; } ret.varName = varName; return ret; }
nodeValue binaryExprNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions){ nodeValue ret = nodeValue(); switch(op) { //TODO: implement other operators case PLUS_OP: ret = lhs.execute(scope,classDefs,functions) + rhs.execute(scope,classDefs,functions); ret.type = NVINT; break; } return ret; }
BinaryTree* deleteLeaf(int val, BinaryTree *tree) { BinaryTree *res=NULL; res = malloc(sizeof(BinaryTree)); if((haveNode(val,tree))&&(isLeafInTree(val,tree)))//condition : le noeud est present et c'est une feuille { if(nodeValue(tree)==val)//lorsque la valeur est trouvée, on supprime la feuille { res=NULL; } else// sinon on cherche dans les sous arbres droits et gauches { res=createNodeWithChilds(deleteLeaf(val,leftChild(tree)),nodeValue(tree),deleteLeaf(val,rightChild(tree))); } } else//la valeur n'est pas présente, on retourne l'arbre d'entrée { res=tree; } return res; }
int maxNode(BinaryTree* tree) { int res; if(rightChild(tree)!=NULL) { res=maxNode(rightChild(tree));//la valeur maximale n'st pas encore atteinte, donc on fait un appel recursif } else { res=nodeValue(tree);//on a atteint la valeur max } return res; }
BinaryTree* deleteNode2(int val, BinaryTree *tree) { BinaryTree *res=NULL; res = malloc(sizeof(BinaryTree)); if(haveNode(val,tree))//condition : le noeud est present { if(nodeValue(tree)==val)// on se deplace dans le branches de l'arbre { // on supprime le noeud val dans l'arbre ou a été échangé val et le noeud de valeur maximale dans le sous arbre gauche res=deleteNode1(val,switchNode(val,maxNode(leftChild(tree)),tree)); } else// appel recursif { res=createNodeWithChilds(deleteNode2(val,leftChild(tree)),nodeValue(tree),deleteNode2(val,rightChild(tree))); } } else { res=tree; } return res; }
int numberOfLeaf(BinaryTree* tree, int val) { int res; if(nodeValue(tree)==val)//une fois le noeud touvé { if(rightChild(tree)==NULL && leftChild(tree)==NULL)//cas d'une feuille {res=0;} else if(rightChild(tree)==NULL && leftChild(tree)!=NULL)//cas d'un noeud à 1 fils {res=1;} else if(rightChild(tree)!=NULL && leftChild(tree)==NULL)//cas d'un noeud à 1 fils {res=1;} else//cas d'un noeud à 2 fils {res=2;} } else//on cherche le noeud de valeur val { if(val>=nodeValue(tree)) {res=numberOfLeaf(rightChild(tree),val);}//en se deplacant à droite else {res=numberOfLeaf(leftChild(tree),val);}//en se deplacant à gauche } return res; }
float DTree::correct(vector<bool> l){ vector<bool>::iterator it_node; vector<vector<float> >::iterator it_data; int correct=0, size=0; float value = nodeValue(l); for (it_node=l.begin(), it_data=data.begin(); it_data!=data.end(); it_data++, it_node++) if (*it_node){ if (value == it_data->at(predictee)) correct++; size++; } return correct*1.0F/size; }
float DTree::rmse(vector<bool> l){ vector<bool>::iterator it_node; vector<vector<float> >::iterator it_data; int size=0; float value = nodeValue(l); float error2=0; for (it_node=l.begin(), it_data=data.begin(); it_data!=data.end(); it_data++, it_node++){ if (*it_node){ size++; error2 += (value - it_data->at(predictee))*(value - it_data->at(predictee)); } } return sqrt(error2*1.0F/size); }
nodeValue condNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions){ nodeValue ret = nodeValue(); nodeValue l = lhs.execute(scope,classDefs,functions); nodeValue r = rhs.execute(scope,classDefs,functions); switch (op) { //TODO: implement other operators. case LT_OP: if (l < r) { ret.intVal = 1; } else { ret.intVal = 0; } break; } return ret; }
BinaryTree* setNode(int val, int intoval, BinaryTree* tree) { BinaryTree *res=NULL; res = malloc(sizeof(BinaryTree)); if(tree!=NULL){ if(nodeValue(tree)==val)//une fois le noeud trouvé, on remplace sa valeur { tree->value=intoval; } else//sinon on parcoure les sous arbres droits et gauches { setNode(val,intoval,rightChild(tree)); setNode(val,intoval,leftChild(tree)); } } return tree; }
bool TableFieldBinaryTreeEvalNode::testEvaluator(const QHash<QString, bool>& vals) const { //qDebug(qPrintable(QString("Type(%1) Value(%2)").arg(nodeType()).arg(nodeValue()))); if (m_node == nullptr) { qDebug("NULL Node in the evaluator"); } else if (isValue()) { //qDebug(qPrintable(QString("Returning %1").arg(vals.value(nodeValue())))); return vals.value(nodeValue()); } else if (m_children.size() > 0) { bool rc = m_children.at(0)->testEvaluator(vals); if (isAnd()) { for (int i=1; rc && i<m_children.size(); ++i) { rc = m_children.at(i)->testEvaluator(vals); } } else if (isOr()) { for (int i=1; !rc && i<m_children.size(); ++i) { rc = m_children.at(i)->testEvaluator(vals); } } else if (isNot()) { return !rc; } else { return false; qDebug("Wrong number of arguments in the evaluator."); } return rc; } else { qDebug("No children for the evaluator to evaluate"); } return false; }
nodeValue whileNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions){ // A cond node when executed returns an LSRValue with an intval of 1 if true, 0 if false.; while (cond.execute(scope,classDefs,functions).intVal) { scope = new Scope(scope); *(scope->ptrScope) = new LSRScope(*(scope->ptrScope)); StmtList::iterator it = stmts.begin(); while(it != stmts.end()) { (*it)->execute(scope,classDefs,functions); it++; } Scope *temp = scope; LSRScope * t = (*scope->ptrScope); scope = scope->getParent(); *(scope->ptrScope) = (*(scope->ptrScope))->getParent(); delete t; delete temp; } return nodeValue(0); }
void Reader::dumpNode(bsl::ostream & os) const { const char *name = nodeName(); const char *value = nodeValue(); const char *nsUri = nodeNamespaceUri(); int line = getLineNumber(); int column = getColumnNumber(); int depth = nodeDepth(); NodeType type = nodeType(); bsl::string strPad((bsl::string::size_type)depth*2, ' '); os << strPad << "Node pos=" << line << ":" << column << " type=" << type << "(" << nodeTypeAsString(type) << ") empty=" << isEmptyElement() << " hasValue=" << nodeHasValue() << " name=" << CHK(name) << " value=" << CHK(value) << " uri=" << CHK(nsUri) << bsl::endl; int numAttr = numAttributes(); for (int i = 0; i < numAttr; ++i) { ElementAttribute attr; lookupAttribute(&attr, i); os << strPad << " ATTRIBUTE " << CHK(attr.qualifiedName()) << "=" << CHK(attr.value()) << " uri=" << CHK(attr.namespaceUri()) << bsl::endl; } }
void Text::formatForDebugger(char *buffer, unsigned length) const { String result; String s; s = nodeName(); if (s.length() > 0) { result += s; } s = nodeValue(); if (s.length() > 0) { if (result.length() > 0) result += "; "; result += "value="; result += s; } strncpy(buffer, result.deprecatedString().latin1(), length - 1); }
Bool isLeafInTree(int val, BinaryTree* tree) { Bool res; if(isLeaf(tree)) { if(nodeValue(tree)==val) { res=TRUE; } else { res=FALSE; } } else { res=(isLeafInTree(val,rightChild(tree)))||(isLeafInTree(val,leftChild(tree))); } return res; }
nodeValue intNode::execute(Scope * scope, LSRClassTable * classDefs, LSRFunctionTable * functions) { nodeValue v = nodeValue(intVal); v.type=NVINT; return v; }
nodeValue nodeValue::operator+(const nodeValue &rhs) { //TODO: add for more than intsm atybye? return nodeValue(this->intVal + rhs.intVal); }