std::vector<PtNode *> ParseTree::getSingleObjAndNodes() { ParseTree &pt(*this); std::vector<PtNode *> sobj; for ( int i = 0; i < nodeSet().size(); ++i ) { PtNode * n = getNodeSet()[i]; if ( n->idx()[PtNode::IDX_TYPE] != static_cast<int>(Node::T_NODE) ) continue; // Bottom-up: tnode -> and-node -> or-node -> single obj and-node PtNode * a1 = n->getInEdge(0, pt)->getFromNode(pt); PtNode * o = a1->getInEdge(0, pt)->getFromNode(pt); PtNode * a2 = o->getInEdge(0, pt)->getFromNode(pt); if ( a2->idx()[PtNode::IDX_VALID] <= 0 ) continue; bool found = false; for ( int j = 0; j < sobj.size(); ++j ) { if ( a2 == sobj[j] ) { found = true; break; } } if ( !found ) { sobj.push_back(a2); } } return sobj; }
int ParseTree::addNode(int gNode, int type) { int idx = nodeSet().size(); // for ( int i = 0; i < idx; ++i ) { // if ( nodeSet()[i]->idx()[PtNode::IDX_G] == gNode ) { // RGM_LOG(error, "duplicated pt node" ); // return -1; // } // } getNodeSet().push_back( new PtNode(gNode) ); getNodeSet().back()->getIdx()[PtNode::IDX_MYSELF] = idx; getNodeSet().back()->getIdx()[PtNode::IDX_TYPE] = type; return idx; }
int ParseTree::addEdge(int fromNode, int toNode, int gEdge) { int idx = edgeSet().size(); for ( int i = 0; i < idx; ++i ) { if ( edgeSet()[i]->idx()[PtEdge::IDX_FROM] == fromNode && edgeSet()[i]->idx()[PtEdge::IDX_TO] == toNode ) { RGM_LOG(error, "duplicated pt edge" ); return -1; } } getEdgeSet().push_back( new PtEdge(fromNode, toNode, gEdge)); getEdgeSet().back()->getIdx()[PtEdge::IDX_MYSELF] = idx; getNodeSet()[fromNode]->getIdxOutEdges().push_back(idx); getNodeSet()[toNode]->getIdxInEdges().push_back(idx); return idx; }
nsresult txResultRecycler::getNonSharedNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult) { if (aNodeSet->mRefCnt > 1) { return getNodeSet(aNodeSet, aResult); } *aResult = aNodeSet; NS_ADDREF(*aResult); return NS_OK; }
std::vector<PtNode *> ParseTree::getNode(const int idxG) { std::vector<PtNode *> n; for ( int i = 0; i < nodeSet().size(); ++i ) { if ( nodeSet()[i]->idx()[PtNode::IDX_G] == idxG ) { n.push_back(getNodeSet()[i]); } } return n; }
CostScalar EstLogProp::getCardOfBusiestStream(const PartitioningFunction* partFunc, Lng32 numOfParts, GroupAttributes * groupAttr, Lng32 countOfCPUs, NABoolean isUnderNestedJoin) { // if there are no histograms available, return rowCount / number of // partitions as the probesPerStream ColStatDescList &colStatsList = this->colStats(); if ((colStatsList.entries() == 0) || (groupAttr && groupAttr->getIsProbeCacheable())) { return ( getResultCardinality() / numOfParts).minCsOne(); } CostScalar cardinalityPerStream; if (NOT isUnderNestedJoin) cardinalityPerStream = colStatsList.getCardOfBusiestStream( partFunc, numOfParts, groupAttr, countOfCPUs); else { CANodeIdSet* outerNodeSet = getNodeSet(); cardinalityPerStream = colStatsList.getCardOfBusiestStreamForUnderNJ( outerNodeSet, partFunc, numOfParts, groupAttr, countOfCPUs); } return cardinalityPerStream; } // EstLogProp::getCardOfBusiestStream
JNIEXPORT jobjectArray JNICALL Java_com_ireeed_XPathApplier_htmlEvalXPaths(JNIEnv *env, jobject jobj, jstring page, jobjectArray xpaths){ jboolean isCopy; const char *data = env->GetStringUTFChars(page,&isCopy); xmlDocPtr doc = parseHTML(data,strlen(data)); //inform jvm to release the allocated data, no matter copied is true or false env->ReleaseStringUTFChars(page,data); xmlXPathObjectPtr result; xmlNodeSetPtr nodeset; std::vector<std::vector<std::string> > ret; jsize xpathNum = env->GetArrayLength(xpaths); if(doc){ for(int index = 0; index < xpathNum; index++){ jstring string = (jstring)env->GetObjectArrayElement(xpaths,index); const char* xpath = env->GetStringUTFChars(string, &isCopy); std::vector<std::string> output; if(xpath){ result = getNodeSet(doc,xpath); if(result){ nodeset = result->nodesetval; for(int i = 0; i < nodeset->nodeNr; i++){ xmlNodePtr nodePtr = nodeset->nodeTab[i]; std::string record; getTextInNode(nodePtr,record); output.push_back(record); } xmlXPathFreeObject(result); } //inform jvm to release the allocated data, no matter copied is true or false env->ReleaseStringUTFChars(string,xpath); } ret.push_back(output); } xmlFreeDoc(doc); } /* construct std::vector<std::vector<std::string> > back to java type(array of array) construct the final result in order according to the order of given xpaths */ jclass stringArrayCls = env->FindClass("java/lang/Object"); jobjectArray elemObj = env->NewObjectArray(0,env->FindClass("java/lang/String"),env->NewStringUTF("")); jobjectArray retVal = env->NewObjectArray(ret.size(),stringArrayCls,elemObj); for(int i = 0; i < ret.size(); i++){ std::vector<std::string> &elem = ret[i]; elemObj = env->NewObjectArray(elem.size(),env->FindClass("java/lang/String"),env->NewStringUTF("")); for(int j = 0; j < elem.size(); j++){ std::string &elemField = elem[j]; //create java string env->SetObjectArrayElement(elemObj,j,env->NewStringUTF(elemField.c_str())); } env->SetObjectArrayElement(retVal,i,elemObj); } return retVal; }
void SSDPParser::parse(const char * buffer, int size) { xmlDocPtr doc; xmlNodePtr root; xmlChar* xpathDevice = (xmlChar*) "//ns:device"; xmlChar* xpathUDN = (xmlChar*) "///ns:UDN"; xmlXPathObjectPtr deviceList; xmlXPathObjectPtr serviceList; xmlXPathObjectPtr udnNodeList; xmlChar* udn = 0; xmlBufferPtr configBuf = 0; const xmlChar* ns = 0; xmlKeepBlanksDefault(0); doc = xmlParseMemory(buffer, size); if (!doc) return; root = xmlDocGetRootElement(doc); if (root) ns = root->ns->href; deviceList = getNodeSet(doc, ns, xpathDevice); if (deviceList) { int i; xmlNodeSetPtr nodeSet = deviceList->nodesetval; udnNodeList = getNodeSet(doc, ns, xpathUDN); if (!udnNodeList) return; /* Loop on <device> contains in the <deviceList> element */ for (i = 0; i < nodeSet->nodeNr; i++) { char xpathService[32]; xmlNodePtr udnNode = udnNodeList->nodesetval->nodeTab[i]; xmlNodePtr deviceNode = xmlCopyNode(nodeSet->nodeTab[i], 1); udn = xmlNodeListGetString(doc, udnNode->xmlChildrenNode, 1); sprintf(xpathService, "//ns:device[%d]//ns:service", i+1); configBuf = xmlBufferCreate(); if (!configBuf) break; xmlNodeDump(configBuf, doc, deviceNode, 1, 1); serviceList = getNodeSet(doc, ns, (xmlChar*)xpathService); if (serviceList) { /* Loop on <service> contains in the <serviceList> element */ parseServiceList(doc, ns, udn, serviceList->nodesetval, configBuf); xmlXPathFreeObject(serviceList); } if (udn) xmlFree(udn); xmlBufferFree(configBuf); xmlFreeNode(deviceNode); } xmlXPathFreeObject(udnNodeList); xmlXPathFreeObject(deviceList); } xmlFreeDoc(doc); xmlCleanupParser(); }
FilterSpec parseSpecFile(const char* filename) { FilterSpec spec; xmlDocPtr doc; doc = xmlParseFile(filename); if (doc == NULL) { throw OptfirException(std::string("Error: file ") + filename + " not found"); } xmlXPathObjectPtr result = getNodeSet(doc, BAD_CAST "/amplitudespec"); if(result != NULL) { xmlNodeSetPtr nodeset = result->nodesetval; xmlChar* temp; temp = xmlGetProp(nodeset->nodeTab[0], BAD_CAST "order"); if (temp != NULL) { spec.order = atoi((const char*)temp); } temp = xmlGetProp(nodeset->nodeTab[0], BAD_CAST "symmetric"); if (temp != NULL) { spec.symmetric = std::string("yes") == (const char*)temp; } temp = xmlGetProp(nodeset->nodeTab[0], BAD_CAST "max_coeff_abs_value"); if (temp != NULL) { spec.maxCoeffAbsValue = atof((const char*)temp); } temp = xmlGetProp(nodeset->nodeTab[0], BAD_CAST "max_gain"); if (temp != NULL) { spec.maxGain = atof((const char*)temp); } xmlXPathFreeObject(result); result = getNodeSet(doc, BAD_CAST "/amplitudespec/sample"); if (result != NULL) { nodeset = result->nodesetval; for (int i=0; i < nodeset->nodeNr; i++) { if ((temp = xmlGetProp(nodeset->nodeTab[i], BAD_CAST "omega")) != NULL) { double& sample = spec.samples[atof((const char*)temp)]; temp = xmlGetProp(nodeset->nodeTab[i], BAD_CAST "gain"); if (temp != NULL) { sample = atof((const char*)temp); } } } xmlXPathFreeObject(result); } } else { throw OptfirException(std::string("Error: file ") + filename + " not a valid specfile"); } xmlFreeDoc(doc); xmlCleanupParser(); return spec; }
void *getxmlvalue( xmlDocPtr doc, char *tranid, char *name, int i, void *rvalue ) { xml_element ele; int ret; void *value; ret=getxmlele( tranid, name, &ele); if (ret) { printf("%d\n", ret); return NULL; } xmlXPathObjectPtr result; printf("tranid=[%s]name=[%s],path=[%s]\n", tranid, name, ele.path); result = getNodeSet( doc, ele.path ); if (!result) { printf("%s\n", ele.path); return NULL; } if (i>result->nodesetval->nodeNr) { printf("nodeNr=%d need=%d\n", result->nodesetval->nodeNr, i ); return NULL; } if (!strcmp( "content", ele.type )) { xmlNodePtr cur; cur = result->nodesetval->nodeTab[i]; if(cur) value=(char *)xmlNodeGetContent(cur); } else if (!strcmp( "prop", ele.type )) { xmlNodePtr cur; cur = result->nodesetval->nodeTab[i]; if(cur) value=xmlGetProp(cur,(const xmlChar *)ele.prop); } else if (!strcmp( "nodenr", ele.type )) { value=(void *)result->nodesetval->nodeNr; if (rvalue) *(int *)rvalue=(int)value; return value; } else { printf("type err tranid=[%s] name=[%s] type=[%s]\n", tranid, name, ele.type); return NULL; } if (value) { if (rvalue) { strcpy( rvalue, value ); xmlFree(value); return rvalue; } else return value; } return NULL; }