本文整理汇总了C++中TreeNode::attachVariable方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeNode::attachVariable方法的具体用法?C++ TreeNode::attachVariable怎么用?C++ TreeNode::attachVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeNode
的用法示例。
在下文中一共展示了TreeNode::attachVariable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createRandomTree
static TreeNode* createRandomTree( const GlobalContext* ctx, const strus::utils::Document& doc, std::size_t& docitr, unsigned int depth=0)
{
TreeNode* rt = 0;
if (RANDINT( 1,5-depth) == 1)
{
if (docitr >= doc.itemar.size()) return 0;
rt = new TreeNode( termId( strus::utils::Token, doc.itemar[ docitr].termid));
}
else
{
unsigned int argc = ctx->randomArgc();
unsigned int range = argc + ctx->randomRange();
unsigned int cardinality = 0; //... it seems currently too difficult to handle other than the default cardinality in this test
TreeNode::JoinOperation op = ctx->randomOp();
std::vector<TreeNode*> args;
unsigned int rangesum = 0;
unsigned int ai;
for (ai=0; docitr < doc.itemar.size() && ai<argc; ++ai,++docitr)
{
TreeNode* arg = createRandomTree( ctx, doc, docitr, depth+1);
if (arg == 0)
{
TreeNode::deleteTreeAr( args);
return 0;
}
args.push_back( arg);
rangesum += arg->range();
}
if (argc == 1
&& (op == strus::PatternMatcherInstanceInterface::OpSequenceStruct
|| op == strus::PatternMatcherInstanceInterface::OpWithinStruct)
&& args[0]->term() == termId( strus::utils::SentenceDelim, 0))
{
// ... add another node for a sequence of size 1, if we have a sequence of length 1 with a delimiter element only (prevent anomaly)
TreeNode* arg = createRandomTree( ctx, doc, docitr, depth+1);
if (arg == 0)
{
TreeNode::deleteTreeAr( args);
return 0;
}
args.push_back( arg);
rangesum += arg->range();
}
range += rangesum;
if (ai < argc)
{
TreeNode::deleteTreeAr( args);
return 0;
}
switch (op)
{
case strus::PatternMatcherInstanceInterface::OpSequence:
case strus::PatternMatcherInstanceInterface::OpSequenceImm:
{
break;
}
case strus::PatternMatcherInstanceInterface::OpSequenceStruct:
{
TreeNode* delim = new TreeNode( termId( strus::utils::SentenceDelim, 0));
args.insert( args.begin(), delim);
++argc;
break;
}
case strus::PatternMatcherInstanceInterface::OpWithin:
{
for (int ii=0; ii<3; ii++)
{
unsigned int r1 = RANDINT(0,argc);
unsigned int r2 = RANDINT(0,argc);
if (r1 != r2) std::swap( args[r1], args[r2]);
}
break;
}
case strus::PatternMatcherInstanceInterface::OpWithinStruct:
{
for (int ii=0; ii<3; ii++)
{
unsigned int r1 = RANDINT(0,argc);
unsigned int r2 = RANDINT(0,argc);
if (r1 != r2) std::swap( args[r1], args[r2]);
}
TreeNode* delim = new TreeNode( termId( strus::utils::SentenceDelim, 0));
args.insert( args.begin(), delim);
++argc;
break;
}
case strus::PatternMatcherInstanceInterface::OpAny:
cardinality = 0;
break;
case strus::PatternMatcherInstanceInterface::OpAnd:
throw std::runtime_error( "operator 'And' not implemented yet");
}
rt = new TreeNode( op, args, range, cardinality);
}
if (RANDINT(1,10) == 1)
{
rt->attachVariable( RANDINT(1,10));
}
return rt;
}