void InnerNode::remove( int index ) { PRECONDITION( index >= 1 && index <= last ); LeafNode* lf = getTree(index)->firstLeafNode(); setKey( index, lf->item[0] ); lf->removeItem(0); }
char* CapturedXML::getXML() { char* xml_string; mxml_node_t *xml = getTree(); xml_string = mxmlSaveAllocString(xml, mxmlWhitespaceCB); mxmlDelete(xml); return xml_string; }
void InnerNode::add( Sortable *obj, int index ) { // this is called only from Btree::add() PRECONDITION( index >= 1 ); LeafNode* ln = getTree(index-1)->lastLeafNode(); ln->add( obj, ln->last+1 ); }
void CleanMorphsOper::CleanMorphsOperImpl::operator()() { auto tree = getTree(); if (tree) { auto tree_impl = tree->pimpl; tbb::task_group_context tbbCtx; tbb::task_scheduler_init scheduler; if (tree_impl->threadCnt > 0) { scheduler.terminate(); scheduler.initialize(tree_impl->threadCnt); } assert(tree_impl->candidates.size() == tree_impl->candidatesMask.size()); CleanMorphs filterMorphs(tree_impl, tree_impl->candidates.size(), tree_impl->candidates, tree_impl->candidatesMask, newCandidates); tbb::parallel_for( tbb::blocked_range<size_t>(0, tree_impl->candidates.size()), filterMorphs, tbb::auto_partitioner(), tbbCtx); tree_impl->candidates.swap(newCandidates); tree_impl->candidatesMask.resize(tree_impl->candidates.size()); tree_impl->candidatesMask.assign(tree_impl->candidates.size(), true); assert(tree_impl->candidates.size() == tree_impl->candidatesMask.size()); newCandidates.clear(); newCandidates.shrink_to_fit(); } else { throw std::runtime_error("Cannot filter morphs. No tree associated with this instance."); } }
void Transformer::process(string inputFilename) { // import sentences to be translated ifstream inputFile(inputFilename.c_str()); if (!inputFile) printError("input file `" + inputFilename + "' could not be found"); string line; int lineNo = 1; while (getline(inputFile, line)) // TODO: read in all text into a vector first { //if (showLineNos) cout << '[' << lineNo << "] "; if (line == "") { cout << endl; } else { Tree tr = getTree(line); if (tr.empty()) { cout << line << endl; } else { transduceTree(tr); printPennTree(tr, tr.begin()); cout << endl; } } lineNo++; } inputFile.close(); }
/* Get uncomressed file from archive*/ void Archiver :: uncompress(string& pathOfArchive, string& pathOfUncompressedFile) { ifstream inFile; inFile.open(pathOfArchive.c_str(), ios :: out | ios :: binary); Node* root = getTree(inFile); string data = getData(root, inFile, pathOfUncompressedFile); deleteHuffmanTree(root); }
TreeNode* Solution::flatten(TreeNode* A) { // Do not write main() function. // Do not read input, instead use the arguments to the function. // Do not print the output, instead return values as specified // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details getTree(A); return A; }
int InnerNode::indexOf( const Node *that ) const { // returns a number in the range 0 to this->last // 0 is returned if THAT == tree[0] for( int i = 0; i <= last; i++ ) if( getTree(i) == that ) return i; CHECK( 0 ); }
/*Get Score of given Move*/ int getMoveScore(Game *game, Move *move,Color uCol) { MinimaxNode *root = getTree(game, uCol); int i; int res = 0; for (i = 0; i < root->sonsK; i++) { if (isSameMove(root->sons[i]->move, move)) res = root->sons[i]->val; } freeMinimaxTree(root); return res; }
void CTreeListFrame::SortTree(int nCol, BOOL bAscending, HTREEITEM hParent) { if (m_sortingEnabled) { HTREEITEM hChild; HTREEITEM hPa = hParent; while (hPa != NULL) { if(getTree().ItemHasChildren(hPa)) { hChild = getTree().GetChildItem(hPa); getTree().SortItems(nCol, bAscending, hPa); SortTree(nCol, bAscending, hChild); } hPa = getTree().GetNextSiblingItem(hPa); } } }
void RenderableModelEntityItem::setModelURL(const QString& url) { auto& currentURL = getParsedModelURL(); ModelEntityItem::setModelURL(url); if (currentURL != getParsedModelURL() || !_model) { EntityTreePointer tree = getTree(); if (tree) { QMetaObject::invokeMethod(tree.get(), "callLoader", Qt::QueuedConnection, Q_ARG(EntityItemID, getID())); } } }
Object& InnerNode::found(Sortable* what, Node** which, int* where ) { // recursively look for WHAT starting in the current node for( int i = 1 ; i <= last; i++ ) { if( *getKey(i) == *what ) { // then could go in either item[i].tree or item[i-1].tree // should go in one with the most room, but that's kinda // hard to calculate, so we'll stick it in item[i].tree *which = this; *where = i; return *getKey(i); } if( *getKey(i) > *what ) return getTree(i-1)->found(what, which, where); } // *what > *(*this)[last].key, so recurse on last item.tree return getTree(last)->found( what, which, where ); }
void RenderableModelEntityItem::setCompoundShapeURL(const QString& url) { auto currentCompoundShapeURL = getCompoundShapeURL(); ModelEntityItem::setCompoundShapeURL(url); if (getCompoundShapeURL() != currentCompoundShapeURL || !_model) { EntityTreePointer tree = getTree(); if (tree) { QMetaObject::invokeMethod(tree.get(), "callLoader", Qt::QueuedConnection, Q_ARG(EntityItemID, getID())); } } }
void eff_hs(TString f_name, TString p_name, TString pt) { gStyle->SetTitleStyle(0); gStyle->SetTitleAlign(13); // coord in top left gStyle->SetTitleX(0.); gStyle->SetTitleY(1.); gStyle->SetTitleW(1); gStyle->SetTitleH(0.058); gStyle->SetTitleBorderSize(0); gStyle->SetPadLeftMargin(0.126); gStyle->SetPadRightMargin(0.04); gStyle->SetPadTopMargin(0.06); gStyle->SetPadBottomMargin(0.13); gStyle->SetOptStat(0); gStyle->SetMarkerStyle(1); // efficiency vs half-strip - separate odd-even TCut ok_eta = "TMath::Abs(eta)>1.64 && TMath::Abs(eta)<2.12"; TTree *t = getTree(f_name); TH1F* ho = draw_eff(t, " GEM reconstruction efficiency CMS Simulation;LCT half-strip number;Efficiency", "h_odd", "(130,0.5,130.5)", "hs_lct_odd", ok_lct1 && ok_eta , ok_pad1, "", kRed); TH1F* he = draw_eff(t, " GEM reconstruction efficiency CMS Simulation;LCT half-strip number;Efficiency", "h_evn", "(130,0.5,130.5)", "hs_lct_even", ok_lct2 && ok_eta , ok_pad2, "same"); TLegend *leg = new TLegend(0.25,0.23,.75,0.5, NULL, "brNDC"); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->SetTextSize(0.06); leg->AddEntry((TObject*)0,"muon p_{T} = " + pt + " GeV/c",""); leg->AddEntry(he, "\"Close\" chamber pairs","l"); leg->AddEntry(ho, "\"Far\" chamber pairs","l"); leg->Draw(); // TLegend *leg = new TLegend(0.35,0.2,.65,0.4, NULL, "brNDC"); // leg->SetBorderSize(0); // leg->SetTextSize(0.06); // leg->SetFillStyle(0); // leg->AddEntry((TObject*)0,"muon p_{T} = " + pt + " GeV/c",""); // leg->AddEntry(ho,"odd chambers","l"); // leg->AddEntry(he,"even chambers","l"); // leg->Draw(); TLatex* tex2 = new TLatex(.67,.8," L1 Trigger"); tex2->SetTextSize(0.05); tex2->SetNDC(); tex2->Draw(); TLatex * tex = new TLatex(.66,.73,"1.64<|#eta|<2.12"); tex->SetTextSize(0.05); tex->SetNDC(); tex->Draw(); gPad->Print(p_name); }
bool IndexFile::check(int level) { printf("Checking FileAllocator...\n"); try { if (fa.dump(level)) printf("FileAllocator OK\n"); else { printf("FileAllocator ERROR\n"); return false; } NameIterator names; bool have_name; unsigned long channels = 0; unsigned long total_nodes=0, total_used_records=0, total_records=0; unsigned long nodes, records; stdString dir; for (have_name = getFirstChannel(names); have_name; have_name = getNextChannel(names)) { ++channels; AutoPtr<RTree> tree(getTree(names.getName(), dir)); if (!tree) { printf("%s not found\n", names.getName().c_str()); return false; } printf("."); fflush(stdout); if (!tree->selfTest(nodes, records)) { printf("RTree for channel '%s' is broken\n", names.getName().c_str()); return false; } total_nodes += nodes; total_used_records += records; total_records += nodes * tree->getM(); } printf("\nAll RTree self-tests check out fine\n"); printf("%ld channels\n", channels); printf("Total: %ld nodes, %ld records out of %ld are used (%.1lf %%)\n", total_nodes, total_used_records, total_records, total_used_records*100.0/total_records); } catch (GenericException &e) { printf("Exception:\n%s\n", e.what()); } return true; }
TreeNode *getTree(vector<int> &pre, vector<int> &in, int prestart, int preend, int instart, int inend) { if (instart > inend) { return NULL; } int midval = pre[prestart]; int mid; for (int i = instart; i <= inend; i++) { if (in[i] == midval) { mid = i; break; } } TreeNode* root = new TreeNode(midval); int leftn = mid - instart; root->left = getTree(pre, in, prestart +1, prestart + leftn, instart, instart + leftn -1); root->right = getTree(pre, in, prestart + leftn +1, preend, instart + leftn +1, inend); return root; }
long InnerNode::findRank( Sortable* what ) const { // recursively look for WHAT starting in the current node if ( *what < *getKey(1) ) return getTree(0)->findRank(what); long sum = getNofKeys(0); for( int i = 1; i < last; i++ ) { if( *what == *getKey(i) ) return sum; sum++; if( *what < *getKey(i+1) ) return sum + getTree(i)->findRank(what); sum += getNofKeys(i); } if( *what == *getKey(last) ) return sum; sum++; // *what > getKey(last), so recurse on last item.tree return sum + getTree(last)->findRank(what); }
void BulletMLParserTinyXML::parseImpl(TiXmlDocument& doc) { if (doc.Error()) { throw BulletMLError(doc.Value() + ": " + doc.ErrorDesc()); } TiXmlNode* node; for (node = doc.FirstChild(); node; node = node->NextSibling()) { if (node->ToElement() != 0) { getTree(node); break; } } }
SNodeArray &StmtList::removeUnusedAssignments() { DISABLEDEBUGSTRING(*this); bool stable; do { stable = true; const size_t childCount = size(), stmtCount = childCount-1; for(size_t i = 0; i < stmtCount; i++) { SNode assign = (*this)[i]; SNode expr = assign.right(); if(expr.isName()) { getTree().unmarkAll(); assign.left().mark(); getTree().traverseTree(NameSubstituter(assign.left().getName(), expr.getName())); getTree().unmarkAll(); remove(i); stable = false; break; } } } while(!stable); for(int i = (int)size()-1; i--;) { // Remove unused assignments const SNode &stmt = (*this)[i]; const String &varName = stmt.left().getName(); bool isUsed = false; for(size_t j = i+1; j < size(); j++) { if((*this)[j].dependsOn(varName)) { isUsed = true; break; } } if(!isUsed) { remove(i); } } ENABLEDEBUGSTRING(*this); return *this; }
void CTreeListFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { CRect m_treeRect; getTree().GetClientRect(&m_treeRect); if(pScrollBar == &m_horScrollBar) { int m_nCurPos = m_horScrollBar.GetScrollPos(); int m_nPrevPos = m_nCurPos; switch(nSBCode) { case SB_LEFT: m_nCurPos = 0; break; case SB_RIGHT: m_nCurPos = m_horScrollBar.GetScrollLimit()-1; break; case SB_LINELEFT: m_nCurPos = max(m_nCurPos-6, 0); break; case SB_LINERIGHT: m_nCurPos = min(m_nCurPos+6, m_horScrollBar.GetScrollLimit()-1); break; case SB_PAGELEFT: m_nCurPos = max(m_nCurPos-m_treeRect.Width(), 0); break; case SB_PAGERIGHT: m_nCurPos = min(m_nCurPos+m_treeRect.Width(), m_horScrollBar.GetScrollLimit()-1); break; case SB_THUMBTRACK: case SB_THUMBPOSITION: if(nPos==0) m_nCurPos = 0; else m_nCurPos = min(StretchWidth(nPos, 6), m_horScrollBar.GetScrollLimit()-1); break; } // 6 is Microsoft's step in a CListCtrl for example m_horScrollBar.SetScrollPos(m_nCurPos); getTree().m_nOffset = -m_nCurPos; // smoothly scroll the tree control { CRect m_scrollRect; getTree().GetClientRect(&m_scrollRect); getTree().ScrollWindow(m_nPrevPos - m_nCurPos, 0, &m_scrollRect, &m_scrollRect); } CRect m_headerRect; getTree().m_wndHeader.GetWindowRect(&m_headerRect); CRect m_wndRect; GetClientRect(&m_wndRect); getTree().m_wndHeader.SetWindowPos(&wndTop, getTree().m_nOffset, 0, max(StretchWidth(getTree().GetColumnsWidth(),m_treeRect.Width()),m_wndRect.Width()), m_headerRect.Height(), SWP_SHOWWINDOW); } CWnd::OnHScroll(nSBCode, nPos, pScrollBar); }
void BulletMLParserTinyXML::getTree(TiXmlNode* node) { if (node->ToComment() != 0) return; translateNode(node); TiXmlNode* child; for (child = node->FirstChild(); child; child = child->NextSibling()) { TiXmlText* text; if ((text = child->ToText()) != 0) { curNode_->setValue(text->Value()); break; } getTree(child); } curNode_ = curNode_->getParent(); }
SpatiallyNestableWeakPointer InterfaceParentFinder::find(QUuid parentID, bool& success, SpatialParentTree* entityTree) const { SpatiallyNestableWeakPointer parent; if (parentID.isNull()) { success = true; return parent; } // search entities if (entityTree) { parent = entityTree->findByID(parentID); } else { auto treeRenderer = qApp->getEntities(); EntityTreePointer tree = treeRenderer ? treeRenderer->getTree() : nullptr; parent = tree ? tree->findEntityByEntityItemID(parentID) : nullptr; } if (!parent.expired()) { success = true; return parent; } // search avatars QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>(); parent = avatarManager->getAvatarBySessionID(parentID); if (!parent.expired()) { success = true; return parent; } if (parentID == AVATAR_SELF_ID) { success = true; return avatarManager->getMyAvatar(); } // search overlays auto& overlays = qApp->getOverlays(); auto overlay = overlays.getOverlay(parentID); parent = std::dynamic_pointer_cast<SpatiallyNestable>(overlay); // this will return nullptr for non-3d overlays if (!parent.expired()) { success = true; return parent; } success = false; return parent; }
Object& InnerNode::operator[]( long idx ) const { for( int j=0; j <= last; j++ ) { long R; if( idx < (R = getNofKeys(j)) ) return (*getTree(j))[idx]; if( idx == R ) { if( j == last ) return NOOBJECT; else return *getKey(j+1); } idx -= R+1; // +1 because of the key in the node } return NOOBJECT; }
std::unique_ptr<char, void(*)(void*)> getXML(lib::Span<const Driver * const> drivers, lib::Span<const GatorCpu> clusters) { const auto xml = getTree(clusters); // Add dynamic events from the drivers mxml_node_t *events = mxmlFindElement(xml.get(), xml.get(), TAG_EVENTS, NULL, NULL, MXML_DESCEND); if (!events) { logg.logError("Unable to find <events> node in the events.xml, please ensure the first two lines of events XML are:\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<events>"); handleException(); } for (const Driver *driver : drivers) { driver->writeEvents(events); } return {mxmlSaveAllocString(xml.get(), mxmlWhitespaceCB), &free}; }
void mapCallback(const nav_msgs::OccupancyGrid& msg) { ROS_DEBUG("I heard frame_id: [%s]", msg.header.frame_id.c_str()); float resolution = msg.info.resolution; float width = msg.info.width; float height = msg.info.height; float posx = msg.info.origin.position.x; float posy = msg.info.origin.position.y; cloud_xyz = boost::shared_ptr< pcl::PointCloud<pcl::PointXYZ> >(new pcl::PointCloud<pcl::PointXYZ>()); //cloud_xyz->width = 100; // 100 cloud_xyz->height = 1; cloud_xyz->is_dense = false; cloud_xyz->header.stamp = ros::Time(0); cloud_xyz->header.frame_id = "/map"; pcl::PointXYZ point_xyz; //for (unsigned int i = 0; i < cloud_xyz->width ; i++) for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) { //@TODO if (msg.data[x + y * width] == 100) { point_xyz.x = (.5f + x) * resolution + posx; point_xyz.y = (.5f + y) * resolution + posy; point_xyz.z = 0; cloud_xyz->points.push_back(point_xyz); } } cloud_xyz->width = cloud_xyz->points.size(); mapTree = getTree(cloud_xyz); pcl::toROSMsg (*cloud_xyz, *output_cloud); ROS_DEBUG("Publishing PointXYZ cloud with %ld points in frame %s", cloud_xyz->points.size(),output_cloud->header.frame_id.c_str()); we_have_a_map = true; }
char *EventsXML::getXML() { mxml_node_t *xml = getTree(); // Add dynamic events from the drivers mxml_node_t *events = mxmlFindElement(xml, xml, "events", NULL, NULL, MXML_DESCEND); if (!events) { logg->logError("Unable to find <events> node in the events.xml, please ensure the first two lines of events XML are:\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<events>"); handleException(); } for (Driver *driver = Driver::getHead(); driver != NULL; driver = driver->getNext()) { driver->writeEvents(events); } char *string = mxmlSaveAllocString(xml, mxmlWhitespaceCB); mxmlDelete(xml); return string; }
TreeOfNodes& GpModel::worstTournament( int k ) { if (k <= 0) { k = getTournamentSelection(); } TreeOfNodes** tournament = new TreeOfNodes*[k]; for (int i = 0; i < k; ++i) { tournament[i] = &getTree(_rnd_tournament.nextInt(0, getPopulationSize())); } TreeOfNodes* result = NULL; double fitness = isLowerFitnessBetter() ? -1.0 / 0.0 : 1.0 / 0.0; for (int i = 0; i < k; ++i) { if (!isBetter(tournament[i]->getFitness(), fitness)) { fitness = tournament[i]->getFitness(); result = tournament[i]; } } for (int i = 0; i < k; ++i) { tournament[i] = NULL; } delete [] tournament; return *result; }
bool RenderableModelEntityItem::isReadyToComputeShape() { ShapeType type = getShapeType(); if (type == SHAPE_TYPE_COMPOUND) { if (!_model || _model->getCollisionURL().isEmpty()) { EntityTreePointer tree = getTree(); if (tree) { QMetaObject::invokeMethod(tree.get(), "callLoader", Qt::QueuedConnection, Q_ARG(EntityItemID, getID())); } return false; } if (_model->getURL().isEmpty()) { // we need a render geometry with a scale to proceed, so give up. return false; } const QSharedPointer<NetworkGeometry> collisionNetworkGeometry = _model->getCollisionGeometry(); const QSharedPointer<NetworkGeometry> renderNetworkGeometry = _model->getGeometry(); if ((collisionNetworkGeometry && collisionNetworkGeometry->isLoaded()) && (renderNetworkGeometry && renderNetworkGeometry->isLoaded())) { // we have both URLs AND both geometries AND they are both fully loaded. if (_needsInitialSimulation) { // the _model's offset will be wrong until _needsInitialSimulation is false PerformanceTimer perfTimer("_model->simulate"); _model->simulate(0.0f); _needsInitialSimulation = false; } return true; } // the model is still being downloaded. return false; } return true; }
int runInterpreter(void) { AST M = getTree("main"); if(M != NULL) { AST R = simplify(M); if((R->kind == ACTION_NK) || ((R->kind == BASIC_FUNC_NK) && ((R->extra == PRILST_FK) || (R->extra == PRINT_FK) || (R->extra == PROD_FK) || (R->extra == READI_FK) || (R->extra == READC_FK)))) { AST ret = performAction(R); if(ret->kind != EMPTYLIST) { if(ret->kind == CONS_NK) displayList(ret); else displayAST(ret); } } else { AST S = simplify(R); if(S->kind != EMPTYLIST) { if(S->kind == CONS_NK) displayList(S); else displayAST(R); } } printf("\n"); } return 0; }
void eff_hs_overlap(TString f_name, TString p_name, TString pt) { // efficiency vs half-strip - including overlaps in odd&even TCut ok_eta = "TMath::Abs(eta)>1.64 && TMath::Abs(eta)<2.12"; TTree *t = getTree(f_name); TH1F* ho = draw_eff(t, " GEM reconstruction efficiency CMS Simulation;LCT half-strip number;Efficiency", "h_odd", "(130,0.5,130.5)", "hs_lct_odd", ok_lct1 && ok_eta , ok_pad1_overlap, "", kRed); TH1F* he = draw_eff(t, " GEM reconstruction efficiency CMS Simulation;LCT half-strip number;Efficiency", "h_evn", "(130,0.5,130.5)", "hs_lct_even", ok_lct2 && ok_eta , ok_pad2_overlap, "same"); TF1 fo("fo", "pol0", 6., 123.); ho->Fit("fo","RN"); TF1 fe("fe", "pol0", 6., 123.); he->Fit("fe","RN"); TLegend *leg = new TLegend(0.25,0.23,.75,0.5, NULL, "brNDC"); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->SetTextSize(0.06); leg->AddEntry((TObject*)0,"muon p_{T} = " + pt + " GeV/c",""); leg->AddEntry(he, "\"Close\" chamber pairs","l"); leg->AddEntry(ho, "\"Far\" chamber pairs","l"); leg->Draw(); // Print additional information TLatex* tex2 = new TLatex(.67,.8," L1 Trigger"); tex2->SetTextSize(0.05); tex2->SetNDC(); tex2->Draw(); TLatex * tex = new TLatex(.66,.73,"1.64<|#eta|<2.12"); tex->SetTextSize(0.05); tex->SetNDC(); tex->Draw(); gPad->Print(p_name); }