当前位置: 首页>>代码示例>>C++>>正文


C++ NodePtr::as_string方法代码示例

本文整理汇总了C++中NodePtr::as_string方法的典型用法代码示例。如果您正苦于以下问题:C++ NodePtr::as_string方法的具体用法?C++ NodePtr::as_string怎么用?C++ NodePtr::as_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NodePtr的用法示例。


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

示例1: concat_with

NodePtr Node::concat_with(NodePtr other) {
	NodePtr result = concat(this, other);
#ifdef SLOW_ASSERTS
	assert(result->as_string() == this->as_string()+other->as_string());
#endif
	return result;
}
开发者ID:Vlad-Shcherbina,项目名称:Morph-Endo-Legacy,代码行数:7,代码来源:treap_rope.cpp

示例2: concat

NodePtr concat(NodePtr left, NodePtr right) {
	if (//left->is_leaf() && right->is_leaf() &&
		left->length() + right->length() <= CONCAT_THRESHOLD) 
			return new Leaf(left->as_string()+right->as_string());

	int new_key = rand()%MAX_HEAP_KEY;
	return merge(new_key, left, right);

	//return new InnerNode(std::min(left->heap_key, right->heap_key), left, right); // unbalanced implementation
}
开发者ID:Vlad-Shcherbina,项目名称:Morph-Endo-Legacy,代码行数:10,代码来源:treap_rope.cpp

示例3: check_node

bool check_node(NodePtr node) {
	std::string s = node->as_string();
	assert(s.length() == node->length());
	Iterator iter = Iterator(node);
	for (std::string::iterator i = s.begin(); i != s.end(); i++, iter.advance(1))
		assert(iter.current() == *i);
	assert(!iter.valid);
	return true;
}
开发者ID:Vlad-Shcherbina,项目名称:Morph-Endo-Legacy,代码行数:9,代码来源:treap_rope.cpp

示例4: merge

NodePtr merge(int new_key, NodePtr left, NodePtr right) {
	if (left->length()+right->length() <= CONCAT_THRESHOLD)
		return new Leaf(left->as_string()+right->as_string());

	if (new_key <= left->heap_key && new_key <= right->heap_key)
		return new InnerNode(new_key, left, right);
	if (left->heap_key < right->heap_key ||
		left->heap_key == right->heap_key && (rand()%2)) {
		assert(!left->is_leaf());
		return new InnerNode(
			left->heap_key, 
			((InnerNode*)left)->left, 
			merge(new_key, ((InnerNode*)left)->right, right) );
	}
	else {
		assert(!right->is_leaf());
		return new InnerNode(
			right->heap_key,
			merge(new_key, left, ((InnerNode*)right)->left),
			((InnerNode*)right)->right);
	}
}
开发者ID:Vlad-Shcherbina,项目名称:Morph-Endo-Legacy,代码行数:22,代码来源:treap_rope.cpp

示例5: test

void test() {
	NodePtr hello = new Leaf("hello");
	NodePtr world = new Leaf("world");
	//check_node(hello);
	NodePtr hw = hello->concat_with(world);
	//hw->debug_print();
	check_node(hw);

	//concatenation
	for (int i = 0; i<100; i++) {
		if (i%20 == 0)
			std::cout<<i<<std::endl;
		hw = hw->concat_with(hello);
		//hw->debug_print();
		assert(check_node(hw));
	}
	assert(check_node(hw));
	hw->debug_print();

	//random access
	for (int i = 0; i<100; i++) {
		Iterator iter = Iterator(hw);
		int pos = 0;
		std::string s = hw->as_string();
		while (pos < hw->length()) {
			//std::cout<<pos<<" ";
			assert(s[pos] == iter.current());
			int d = rand()%100;
			pos += d;
			iter.advance(d);
		}
		assert(!iter.valid);
		//std::cout<<std::endl;
	}

	//slices
	for (int i = 0; i<100; i++) {
		int begin = rand()%(hw->length()+1);
		int end = begin+rand()%(hw->length()-begin+1);
		NodePtr slice = hw->slice(begin, end);
		assert(check_node(slice));
		std::cout<<begin<<" "<<end<<std::endl;
	}
	std::cout<<"hw depth "<<hw->depth()<<std::endl;
}
开发者ID:Vlad-Shcherbina,项目名称:Morph-Endo-Legacy,代码行数:45,代码来源:treap_rope.cpp


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