• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ buildTree函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中buildTree函数的典型用法代码示例。如果您正苦于以下问题:C++ buildTree函数的具体用法?C++ buildTree怎么用?C++ buildTree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了buildTree函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: buildTree

void Universe::updateGeometry(atlas::utils::Time const &dt) {

	mTree = buildTree();
	Planet* mReferencePlanet;
	QuadTreeNode* mActualNode = mTree;

	for (int i = 0; i < numPlanets; i++) {
		mReferencePlanet = Planets[i];
		calculatePlanetsAcceleration(mReferencePlanet, mActualNode);
	}

	for (int i = 0; i < numPlanets; i++) {
		Planets[i]->updateGeometry(dt);
	}
	
	mTree->~QuadTreeNode();
}
开发者ID:ra139233,项目名称:Project-CSC-473,代码行数:17,代码来源:Universe.cpp


示例2: findLadders

 vector<vector<string>> findLadders(string beginWord, string endWord, unordered_set<string> &dict) {
       vector<vector<string> > paths;
       vector<string> path(1, beginWord);
       if (beginWord == endWord){  //corner case;
             paths.push_back(path);
             return paths;
       }
       unordered_set<string> forward, backward;
       forward.insert(beginWord);
       backward.insert(endWord);
       unordered_map<string, vector<string>> tree;
       //make sure the tree generating direction is consistent, since we have to start from the smaller set to accelerate;
       bool reversed = false; 
       if (buildTree(forward, backward, dict, tree, reversed))
       	getPath(beginWord, endWord, tree, path, paths);
       return paths;
 }
开发者ID:wszk1992,项目名称:LeetCode-Team,代码行数:17,代码来源:126.+Word+Ladder+II.cpp


示例3: er

//
// Stage 0: Check if it is a Msg. This is deleted by Msg::deleteMsg( ObjId )
// Stage 1: mark for deletion. This is done by setting cinfo = 0
// Stage 2: Clear out outside-going msgs
// Stage 3: delete self and attached msgs, 
void Neutral::destroy( const Eref& e, int stage )
{
	if ( e.element()->cinfo()->isA( "Msg" ) ) {
		Msg::deleteMsg( e.objId() );
		return;
	}
	vector< Id > tree;
	Eref er( e.element(), ALLDATA );
	unsigned int numDescendants = buildTree( er, tree );
	/*
	cout << "Neutral::destroy: id = " << e.id() << 
		", name = " << e.element()->getName() <<
		", numDescendants = " << numDescendants << endl;
		*/
	assert( numDescendants == tree.size() );
	Element::destroyElementTree( tree );
}
开发者ID:NeuroArchive,项目名称:moose,代码行数:22,代码来源:Neutral.cpp


示例4: clear

bool RegressionTree::train_(RegressionData &trainingData){
    
    //Clear any previous model
    clear();
    
    const unsigned int M = trainingData.getNumSamples();
    const unsigned int N = trainingData.getNumInputDimensions();
    const unsigned int T = trainingData.getNumTargetDimensions();
    
    if( M == 0 ){
        Regressifier::errorLog << "train_(RegressionData &trainingData) - Training data has zero samples!" << std::endl;
        return false;
    }
    
    numInputDimensions = N;
    numOutputDimensions = T;
    inputVectorRanges = trainingData.getInputRanges();
    targetVectorRanges = trainingData.getTargetRanges();
    
    //Scale the training data if needed
    if( useScaling ){
        //Scale the training data between 0 and 1
        trainingData.scale(0, 1);
    }
    
    //Setup the valid features - at this point all features can be used
    Vector< UINT > features(N);
    for(UINT i=0; i<N; i++){
        features[i] = i;
    }
    
    //Build the tree
    UINT nodeID = 0;
    tree = buildTree( trainingData, NULL, features, nodeID );
    
    if( tree == NULL ){
        clear();
        Regressifier::errorLog << "train_(RegressionData &trainingData) - Failed to build tree!" << std::endl;
        return false;
    }
    
    //Flag that the algorithm has been trained
    trained = true;
    
    return true;
}
开发者ID:sboettcher,项目名称:grt,代码行数:46,代码来源:RegressionTree.cpp


示例5: initialize

/**************************************************
 * This function opens the file and reads each    *
 * line into the buildArray function. It then     *
 * calls the rest of the functions to sort the    *
 * array and build the balanced binary tree.      *
 * EXIT 2 for file input error                    *
 * EXIT 1 for memory error                        *
 **************************************************/
void initialize(char *filename)
{
    FILE *fp;
    char buffer[21], **names;
    int count = 0, *count_ptr = &count, size = 2, *size_ptr = &size;
    BNODE* root;

    if ((fp = fopen(filename, "r")) == NULL)
    {
        printf("Error: Filename does not exist\n");
        exit(2);
    }
    
    if ((names = malloc(2 * sizeof(char*))) == NULL)
    {
        printf("Error: Unable to allocate memory\n");
        exit(1);
    }

    while (fgets(buffer, sizeof(buffer), fp) != NULL)
    {
        /* Double the size of the array after it is full */
        if (count == size)
            names = resizeArray(names, size_ptr);

        names = buildArray(names, buffer, count_ptr);
    }

    fclose(fp);

    names = sortArray(names, count_ptr);

    root = buildTree(names, 0, count-1);

    printf("\n preorder: ");
    preorder(root);
    printf("\n\n");

    printf("  inorder: ");
    inorder(root);
    printf("\n\n");

    printf("postorder: ");
    postorder(root);
    printf("\n");
}
开发者ID:rghamilton3,项目名称:c_programs,代码行数:54,代码来源:binaryTree-lib.c


示例6: genHash

void genHash(char file[])
{
	mdstr *a;
	char term[KEYSIZE]; // max chars in word
	FILE *fp;
	
	fp = fopen(file,"r+");
		
	if(!fp)
		printf("--Unable to open file: %s--\n\n",file);
	else
	{
		//printf("opened");
		doc_len = 0;
		while(fscanf(fp,"%s",term) != EOF) //Read word by word in file	
		{
			/*
				Do Stemming Optimization
			*/
			
			if(isSW(term)) continue;

			term[strlen(term)]='\0';
			doc_len++;

			a = (mdstr *)do_test(term);//finding md5 hash
			strcpy(g_hex,"\0");
			strcpy(g_hex,a->hash);
			g_hex[32]='\0';
			free(a);

			//printf("Hex value: %s",g_hex);
			strcpy(g_key,"\0");
			strcpy(g_key,term);
			g_key[strlen(g_key)]='\0';
			toBinary();//hash2Bin();
			
			buildTree();
			
		}
		printf("Finished Indexing %s\n",g_ifile);
		fclose(fp);

	}
}
开发者ID:girish979,项目名称:searchengine,代码行数:45,代码来源:driver.c


示例7: log2f

 KdTree<Primitive>::KdTree(const std::vector<Primitive>& primitives, const int inters_cost,
                           const int trav_cost, const int max_depth, const uint min_num_prims,
                           const float empty_bonus): m_max_depth{max_depth}, m_actual_depth{0},
                           m_min_num_prims{glm::max(min_num_prims, 1u)},
                           m_avg_prims_per_leaf{0.0f}, m_inters_cost{inters_cost},
                           m_trav_cost{trav_cost}, m_empty_bonus{empty_bonus},
                           m_next_node_id{0}, m_n_alloc_nodes{0}, m_leaf_count{0},
                           m_prims{primitives.data()} {
     const uint n{static_cast<uint>(primitives.size())};
     if (m_max_depth < 0) {
         // Maximal depth = 8 + 1.3 * log2(n)
         m_max_depth = static_cast<int>(8 + 1.3f * log2f(static_cast<float>(n)));
     }
     printInfo("Constructing k-d tree for %u primitives.", n);
     printInfo("Maximal tree depth: %i.", m_max_depth);
     const auto t_begin = HighResTimer::now();
     // Reserve memory
     m_prim_boxes = new BBox[n];
     uint* prims_bottom{new uint[n]};
     uint* prims_top{new uint[n * (m_max_depth + 1)]};
     for (auto axis = 0; axis < 3; ++axis) { m_edges[axis] = new BoundEdge[2 * n]; }
     // Each primitive overlaps the root node
     for (uint i = 0; i < n; ++i) {
         prims_bottom[i] = i;
         m_prim_boxes[i] = m_prims[i].computeBBox();
         m_tree_box.extend(m_prim_boxes[i]);
     }
     // Recursively build the tree
     buildTree(0, m_tree_box, prims_bottom, n, 0, 0, prims_bottom, prims_top);
     // Cleaning up
     m_nodes.resize(m_next_node_id);
     m_nodes.shrink_to_fit();
     for (auto axis = 0; axis < 3; ++axis) { delete[] m_edges[axis]; }
     delete[] prims_top;
     delete[] prims_bottom;
     delete[] m_prim_boxes;
     // Compute and print statistics
     m_avg_prims_per_leaf /= m_leaf_count;
     const auto t_diff = HighResTimer::now() - t_begin;
     const auto t_us   = std::chrono::duration_cast<std::chrono::microseconds>(t_diff).count();
     printInfo("k-d tree construction complete after %.2f ms.", t_us * 0.001f);
     printInfo("Actual tree depth: %i.", m_actual_depth);
     printInfo("Average number of primitives per leaf: %.2f.", m_avg_prims_per_leaf);
     printInfo("k-d tree consists of %u nodes.", m_next_node_id);
 }
开发者ID:lieff,项目名称:GIGL,代码行数:45,代码来源:KdTree.hpp


示例8: CPPUNIT_ASSERT_EQUAL

void TestASTMatcher::testMatchSubTree()
{	
	CPPUNIT_ASSERT_EQUAL(true, matcher.matchSubTree(NULL, NULL));
	CPPUNIT_ASSERT_EQUAL(true, matcher.matchSubTree(testNode, NULL));
	CPPUNIT_ASSERT_EQUAL(false, matcher.matchSubTree(NULL, testNode));

	ASTNode* node = buildTree();
	CPPUNIT_ASSERT_EQUAL(true, matcher.matchSubTree(testNode, node));

	node = buildSubTree();
	CPPUNIT_ASSERT_EQUAL(true, matcher.matchSubTree(testNode, node));

	node = buildSubTreeWithDiffValue();
	CPPUNIT_ASSERT_EQUAL(false, matcher.matchSubTree(testNode, node));

	node = buildSubTreeWithDiffStruct();
	CPPUNIT_ASSERT_EQUAL(false, matcher.matchSubTree(testNode, node));
}
开发者ID:kwajunyong,项目名称:chocolate-muffins,代码行数:18,代码来源:TestASTMatcher.cpp


示例9: BTreeBase

void Expression::compileExpression( const QString & expression )
{
	// Make a tree to put the expression in.
	BTreeBase *tree = new BTreeBase();
	BTreeNode *root = new BTreeNode();

	// parse the expression into the tree
	buildTree(expression,tree,root,0);
	// compile the tree into assembly code
	tree->setRoot(root);
	tree->pruneTree(tree->root());
	traverseTree(tree->root());
	
	// Note deleting the tree deletes all nodes, so the root
	// doesn't need deleting separately.
	delete tree;
	return;
}
开发者ID:ktechlab,项目名称:ktechlab,代码行数:18,代码来源:expression.cpp


示例10: main

int main(int argc, const char * argv[]) {
    
    std::vector<int> v;
    
    v.push_back(1);
    v.push_back(2);
    v.push_back(4);
    v.push_back(7);
    v.push_back(8);
    v.push_back(11);
    v.push_back(13);
    
    
    node<int> *head = buildTree(v, 0, 6);
    
    printTree(head);
    return 0;
}
开发者ID:GalitMiller,项目名称:sandbox,代码行数:18,代码来源:main.cpp


示例11: while

void OutlineTree::buildTree( QListViewItem *parentItem, const QDomElement &parentElement )
{
    QListViewItem *thisItem = 0;
    QDomNode node = parentElement.firstChild();
    while ( !node.isNull() ) {
	if ( node.isElement() && node.nodeName() == "outline" ) {
	    // add a new list view item for the outline
	    if ( parentItem == 0 )
		thisItem = new QListViewItem( this, thisItem );
	    else
		thisItem = new QListViewItem( parentItem, thisItem );
	    thisItem->setText( 0, node.toElement().attribute( "text" ) );
	    // recursive build of the tree
	    buildTree( thisItem, node.toElement() );
	}
	node = node.nextSibling();
    }
}
开发者ID:nightfly19,项目名称:renyang-learn,代码行数:18,代码来源:outlinetree.cpp


示例12: main

int main(void)
{
	scanf("%d %d", &N, &Q);
	for (unsigned i = 0; i != N; ++i)
	{
		scanf("%d", &val[i]);
	}
	buildTree(0, N - 1, 0);
	for (unsigned i = 0; i != Q; ++i)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		traverse(a - 1, b - 1, 0);
		printf("%d\n", maxVal - minVal);
		maxVal = 0;
		minVal = 1 << 30;
	}
}
开发者ID:Grillnov,项目名称:AlgorithmsPractise,代码行数:18,代码来源:POJ+3264.cpp


示例13: maxDepth

KdTreeAccel::KdTreeAccel(const vector<Shape*> &prims, int md, int mp,
	Float eb) : maxDepth(md), maxPrims(mp), emptyBonus(eb)
{
	int np = prims.size();
	primitives = prims;
	//Initialize tree depth
	if (maxDepth <= 0)
	{
		maxDepth = roundToInt(8 + 1.3 * logToInt(static_cast<Float>(np)));
	}
	// If no node in vector, terminate initialization
	if (np == 0)
	{
		root = nullptr;
		return;
	}
	//Initialize bouding box for all primitives in stack
	for (int i = 0; i < np; ++i)
	{
		treeBound.Union(prims[i]->ObjBound);
	}
	//Allocate bound edge info
	BoundEdge* edges[3];
	for (int i = 0; i < 3; ++i)
	{
		edges[i] = new BoundEdge[np * 2];
	}
	//Create stack to record primitive indices
	vector<int> primNum(np);
	for (int i = 0; i < np; ++i)
	{
		primNum[i] = i;
	}
	//Start recursively build the tree
	root = new KdAccelNode;
	buildTree(root, treeBound, primNum, maxDepth, edges);

	//Clean data
	for (int i = 0; i < 3; ++i)
	{
		delete[] edges[i];
		edges[i] = nullptr;
	}
}
开发者ID:ShenyaoKe,项目名称:Kaguya,代码行数:44,代码来源:KdTreeAccel.cpp


示例14: doTheScripting

// This function is finding the right thing to do based on the time that we are in
void doTheScripting(long itime)
{	
	while (itime >= sceneStartTime + sceneDuration)
	{
		sceneStartTime += sceneDuration;
		sceneNumber++;
	}

	int sceneID = sceneNumber; // That's the easiest thing, really
	int sceneTime = itime - sceneStartTime;

	// Create the stuff based on the current timing thing
	transformationSeed = sceneID;
	createTransforms((float)sceneTime / 44100.0f);
	buildTree();
	generateParticles();
	transformationSeed = sceneID;
	generateOGLTransforms((float)sceneTime / (float)sceneDuration);
}
开发者ID:chock-mostlyharmless,项目名称:mostlyharmless,代码行数:20,代码来源:intro.cpp


示例15: ShareException

void ShareManager::addDirectory(const string& realPath, const string& virtualName) {
	if(realPath.empty() || virtualName.empty()) {
		throw ShareException(_("No directory specified"));
	}

	if (!checkHidden(realPath)) {
		throw ShareException(_("Directory is hidden"));
	}

	if(Util::stricmp(SETTING(TEMP_DOWNLOAD_DIRECTORY), realPath) == 0) {
		throw ShareException(_("The temporary download directory cannot be shared"));
	}

	{
		Lock l(cs);

		for(auto& i: shares) {
			if(Util::strnicmp(realPath, i.first, i.first.length()) == 0) {
				// Trying to share an already shared directory
				throw ShareException(_("Directory already shared"));
			} else if(Util::strnicmp(realPath, i.first, realPath.length()) == 0) {
				// Trying to share a parent directory
				throw ShareException(_("Remove all subdirectories before adding this one"));
			}
		}
	}

	HashManager::HashPauser pauser;

	auto dp = buildTree(realPath);

	string vName = validateVirtual(virtualName);
	dp->setName(vName);

	Lock l(cs);

	shares[realPath] = move(vName);

	merge(dp, realPath);

	rebuildIndices();
	setDirty();
}
开发者ID:bmdc-team,项目名称:bmdc,代码行数:43,代码来源:ShareManager.cpp


示例16: runProvider

void runProvider(int argc, char **argv)
{
   int port;

   ember_init(onThrowError, onFailAssertion, malloc, free);
   initializePpmStreams();
   buildTree(&_root);

   if(argc >= 2)
   {
      port = atoi(argv[1]);

      printf_s("accepting client on port %d\n", port);
      acceptClient(port);
   }

   sampleNode_free(&_root);
   freePpmStreams();
}
开发者ID:blackhearted,项目名称:ember-plus,代码行数:19,代码来源:__sample_provider.c


示例17: main

int main(){
	int frequencies[UniqueSymbols] = {0};
	const char *ptr = SampleString;
	while (*ptr != '\0')
		++frequencies[*ptr++];

	iNode *root = buildTree(frequencies);

	HuffCodeMap codes;
	generateCodes(root, HuffCode(), codes);
	delete root;

	for (HuffCodeMap::const_iterator it = codes.begin(); it != codes.end(); it++){
		std::cout << it->first << " ";
		std::copy(it->second.begin(), it->second().end(), std::ostream_iterator<bool>(std::cout));
		std::cout << std::endl;
	}
	return 0;
}
开发者ID:mvwicky,项目名称:NotesMiscellanea,代码行数:19,代码来源:huffman.cpp


示例18: main

int main() {
    int nStudents,nInstructs;
    while(~scanf("%d%d",&nStudents,&nInstructs)) {
//        for(int i=1; i<=nStudents; i++)
//            scanf("%d",&arr[i]);
        buildTree(1,1,nStudents);
        //puts("..");
        char ch;
        int i,j;
        while(nInstructs--) {
            scanf("%c %d%d",&ch,&i,&j);
            getchar();
           // printf("ch = %c i = %d j = %d\n",ch,i,j);
            if(ch == 'Q') printf("%d\n",query(1,i,j));
            if(ch == 'U') update(1,i,j);
        }
    }
    return 0;
}
开发者ID:ToRapture,项目名称:ACM-Template,代码行数:19,代码来源:hdu+1754+I+Hate+It(线段树+单点更新+区间最值).cpp


示例19: doc

void PluginDialog::replyFinished(QNetworkReply *reply)
{
    QString replyText = reply->readAll();
    if(reply->error() != QNetworkReply::NoError)
    {
        //Parse servers response
        QDomDocument doc("error");
        if (!doc.setContent(replyText)) {
            //No XML to parse, user is probably disconnected
            return;
        }else
        {
            QDomElement docElem = doc.documentElement();
            QDomElement message = docElem.firstChildElement("message");
            if(!message.text().isEmpty())
            {
                WARNING("Failed to get plugin list from server. Error was: " + message.text());
                QMessageBox::warning(this, "Failed to get plugin list", "Failed to get plugin list from server.\nError was: " + message.text());
            }
        }
    }else
    {
        //No error in request
        addDefaultNodes();
        QDomDocument doc("response");
        if(!doc.setContent(replyText))
        {
            WARNING("Failed to get plugin list from " + reply->request().url().toString() + ".\n Failed to parse reply as XML");
            QMessageBox::warning(this, "Failed to get plugin list", "Failed to get plugin list from " + reply->request().url().toString() + ". Failed to parse reply as XML.");
        }
        QDomElement docElem = doc.documentElement();
        QDomNode pluginNode = docElem.firstChild();
        while(!pluginNode.isNull())
        {
            parsePluginNode(pluginNode);
            pluginNode = pluginNode.nextSibling();
        }
        //Show the plugins in the tree
        stdModel.removeRow(0);
        buildTree();
    }
}
开发者ID:Nothing4You,项目名称:screencloud,代码行数:42,代码来源:plugindialog.cpp


示例20: while

RWSegmentVector::RWSegmentVector(AbstractGenPointChain<int>& aChain,
				 double minDeviation) 
{
  if (aChain.empty())
    {
      return;  // Nothing to do
    }

  // Convert chain to a vector of points

  vector<Point> myChain;
  aChain.setToBegin();

  while (!aChain.isAtEnd())
    {
      myChain.push_back(aChain.accessCurrent());
      aChain.moveNext();
    }

  // Build the tree
  _root = buildTree(myChain, 0, (myChain.size() - 1), minDeviation);

  // And now, construct the vector of Segments we want to retrieve
  if (_root != 0)
    {
      addSegmentIfTerminalNode(_root, myChain);
    }

  // Post-processing : Can we simplify?
  // Based on an idea by Rosin and West...
  // *** WAIT AND SEE ***
  
  // Delete auxiliary data structures
  if (_root != 0)
    {
      delete _root;
    }

  _indexes.erase(_indexes.begin(), _indexes.end());
//  _significance.erase(_significance.begin(), _significance.end());
}
开发者ID:rentpath,项目名称:qgar,代码行数:41,代码来源:RWSegmentVector.cpp



注:本文中的buildTree函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ build_all_zonelists函数代码示例发布时间:2022-05-30
下一篇:
C++ buildFrom函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap