本文整理汇总了C++中InternalNode类的典型用法代码示例。如果您正苦于以下问题:C++ InternalNode类的具体用法?C++ InternalNode怎么用?C++ InternalNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InternalNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void CipherText::compute_node(element_t& v, Node* node){//v amounts to s
if(node->getType() == LEAF){
Leaf* leaf = (Leaf*)node;
leaf->compute(&v, this->pub, this->p);
// printf("leaf: %d, %d, computed\n", leaf->getK(), leaf->getNum());
} else if (node->getType() == INTERNAL_NODE){
InternalNode* internalNode = (InternalNode*)node;
int num = internalNode->getNum();
int k = internalNode->getK();
Node** sons = internalNode->getSons();//??
// printf("internal Node: %d, %d\n", k, num);
element_t* ys = (element_t*)malloc(sizeof(element_t) * (num + 1));
element_init_Zr(ys[0], *(this->p));
element_set(ys[0], v); //set ys[0] to v
computePoints(ys, k, num); //compute other num point,
int i = 1;
for (i = 1; i <= num; i++){
compute_node(ys[i], sons[i - 1]);
}
}
}
示例2: processNode
virtual void processNode(InternalNode &V)
{
V.setLeftSubstMatrix(Q.instantiate(V.getLeftDistance()));
V.setRightSubstMatrix(Q.instantiate(V.getRightDistance()));
int id=V.getID();
if(id>largestID) largestID=id;
++numNodes;
}
示例3: getRightSibling
void InternalNode::borrowRight()
{
InternalNode * rightSib = (InternalNode *) getRightSibling();
insert(rightSib->children[0]); //add min value from sibling to borrower
rightSib->removeDriver(0); //remove min value from sibling
if(parent)
parent->resetMinimum(rightSib);
} //InternalNode::borrowRight()
示例4: getLeftSibling
void InternalNode::borrowLeft()
{
InternalNode * leftSib = (InternalNode *) getLeftSibling();
int max = leftSib->getMaximum();
insert(leftSib->children[count-1]); //add max value from sibling to front of borrower
leftSib->removeDriver(getPosition(max)); //remove the max value from sibling
if(parent)
parent->resetMinimum(this);
} //InternalNode::borrowLeft()
示例5: printf
Policy::Policy(unsigned char* buf, pairing_t* p) {
//get nodeNum
int pos = 0;
int numberOfNode = Utility::str2int(buf);
pos += 4;
// printf("node num is %d\n", numberOfNode);
this->nodeNum = numberOfNode;
//reconstruct access tree form bytes
Node** nodes = (Node**)malloc(sizeof(Node*) * this->nodeNum); //store all nodes
int index = 0;
Node* node = NULL;
int nodeSize = 0;
for(index = 0; index < numberOfNode; index++){
printf("index: %d\n", index);
//get father position
int father = Utility::str2int(buf + pos);
pos += 4;
printf("father is %d\t", father);
//get node size to indentify node type
nodeSize = Utility::str2int(buf + pos);
pos += 4;
//printf("node size is %d\t", nodeSize);
if(nodeSize == -1){
nodeSize = INTERNAL_NODE_SIZE;
node = new InternalNode(buf + pos);
printf("internal node\t");
InternalNode* t = (InternalNode*)node;
printf("%d, %d\t", t->getK(), t->getNum());
} else if(nodeSize == -2){
nodeSize = LEAF_SIZE;
node = new Leaf(buf + pos, p);
// printf("leaf\t");
} else {
node = new ExLeaf((char*)(buf + pos), nodeSize);
// printf("ex leaf\t");
}
pos += nodeSize;
nodes[index] = node;
if(father == -1){
this->root = node;
} else {
this->addSon(nodes[father],node);
}
// printf("add son to node %d\n", father);
}
// printf("reconstruct node ok\n");
free(nodes);
}
示例6: context
bool DendrogramTest::run()
{
context("triangle.pairs");
Graph *graph = new Graph("data/triangle.pairs");
Dendrogram *dendro = new Dendrogram(graph);
testcase(dendro != NULL, "Initialized Dendrogram is NULL!");
testcase(dendro->getRoot() != NULL, "Dendrogram has NULL root");
testcase(((InternalNode *)(dendro->getRoot()))->getLeft() != NULL, "Dendrogram root has NULL left child");
testcase(((InternalNode *)(dendro->getRoot()))->getRight() != NULL, "Dendrogram root has NULL right child");
for (NodeList::iterator iterator=dendro->nodes.begin(); iterator!=dendro->nodes.end(); iterator++) {
DendrogramNode *node = *iterator;
if (node != dendro->getRoot()) {
test_not_equal(node->parent,NULL,"Non-root node has NULL parent");
}
if (node->type == NODE_INTERNAL) {
InternalNode *internal = (InternalNode *)node;
if (internal->getLeft() != NULL) {
test_equal(internal, internal->getLeft()->parent, "Left child of X does not have X as parent");
}
if (internal->getRight() != NULL) {
test_equal(internal, internal->getRight()->parent, "Right child of X does not have X as parent");
}
}
}
delete dendro;
delete graph;
context("triangle.weights");
graph = new Graph("data/triangle.weights");
testcase(graph->isValid(), "failed to load valid graph from data/triangle.weights");
dendro = new Dendrogram(graph);
testcase(dendro != NULL, "Initialized Dendrogram is NULL!");
testcase(dendro->getRoot() != NULL, "Dendrogram has NULL root");
for (int i=0; i<100; i++) {
dendro->sample();
}
testcase(dendro->likelihood() < 0.0f, "Invalid likelihood for post-sampled dendrogram");
graph->addNode(99);
graph->addEdge(99,1,0.9);
std::set<Node> nodes_ab, nodes_z;
nodes_ab.insert(1);
nodes_ab.insert(2);
nodes_z.insert(99);
testcase(graph->linksBetween(nodes_ab,nodes_z) == 0.9, "Incorrect link weight between [A,B] , [Z]");
dendro->addLeaf(99,1);
testcase(graph->linksBetween(nodes_ab,nodes_z) == 0.9, "Incorrect link weight between [A,B] , [Z]");
return this->didPass();
}
示例7: InternalNode
void BTree::insert(const int value)
{
BTreeNode *ptr = root->insert(value);
if(ptr) // root split
{
InternalNode *IPtr = new InternalNode(internalSize, leafSize,
NULL, NULL, NULL);
IPtr->insert(root, ptr);
root = IPtr;
} // if root split
} // BTree::insert()
示例8: while
void BTree::remove(int value)
{ // To be written by students
root = root->remove(value);
InternalNode* ptr = dynamic_cast<InternalNode*>(root);
while(root->getCount() <= 1 && ptr != NULL) {
if(ptr != NULL) root = ptr->getChildren()[0];
ptr = dynamic_cast<InternalNode*>(root);
}
} // BTree::remove()
示例9: processNode
virtual void processNode(InternalNode &u) {
int id=u.getID();
PhylogenyNode *left=u.getLeft(), *right=u.getRight();
NthOrdSubstMatrix &leftPt=*u.getLeftSubstMatrix();
NthOrdSubstMatrix &rightPt=*u.getRightSubstMatrix();
Array2D<double>::RowIn2DArray<double> row=L[id];
for(Symbol a=0 ; a<numAlpha ; ++a) {
row[a]=
processInternalChild(a,left,leftPt,&u)+
processInternalChild(a,right,rightPt,&u);
}
}
示例10: InternalNode
void BTree::insert(const int value)
{
//cout << "Root insert\n";
BTreeNode *ptr = root->insert(value);
if(ptr) //split
{
//cout << "[Root] Split\n";
InternalNode *nroot = new InternalNode (internalSize, leafSize, NULL, NULL, NULL);
nroot->insert(root,ptr);
root = nroot;
}
} // BTree::insert()
示例11: InternalNode
InternalNode* InternalNode::split(BTreeNode* nodeCausingSplit)
{
int i;
//cout << "SPLIT : " << nodeCausingSplit << " : " << nodeCausingSplit->getMinimum() << endl;
InternalNode* newRight =
new InternalNode(internalSize, leafSize, this->parent, this, this->rightSibling);
/*(internalSize + 1) / 2 gives index of last value guaranteed to move to newRight
((internalSize + 1) / 2) - 1 gives the value that could go depending on if the
new value or the old value stored at that position in keys[] is larger */
for (i = internalSize - 1; i >= (internalSize + 1) / 2; i--)
{
newRight->insert(children[i]);
(children[i])->setParent(newRight);
}
if (nodeCausingSplit->getMinimum() > keys[((internalSize + 1) / 2) - 1] ) // given value is greater than middle position
{
nodeCausingSplit->setParent(newRight);
newRight->insert(nodeCausingSplit);
(children[i + 1])->setLeftSibling(nodeCausingSplit);
nodeCausingSplit->setRightSibling(children[i + 1]);
nodeCausingSplit->setLeftSibling(children[((internalSize + 1) / 2) - 1]);
(children[((internalSize + 1) / 2) - 1])->setRightSibling(nodeCausingSplit);
}
else
{
newRight->insert( children[((internalSize + 1) / 2) - 1] );
(children[((internalSize + 1) / 2) - 1])->setParent(newRight);
(children[i + 1])->setLeftSibling(children[((internalSize + 1) / 2) - 1]);
(children[((internalSize + 1) / 2) - 1])->setRightSibling(children[i + 1]);
(children[((internalSize + 1) / 2) - 1])->setLeftSibling(nodeCausingSplit);
nodeCausingSplit->setRightSibling(children[((internalSize + 1) / 2) - 1]);
children[((internalSize + 1) / 2) - 1] = nodeCausingSplit;
keys[((internalSize + 1) / 2) - 1] = nodeCausingSplit->getMinimum();
}
/*if (internalSize % 2 == 0)*/
count = ((internalSize + 1) / 2);
/*else
count = ((internalSize + 1) / 2) + 1;*/
if (rightSibling)
rightSibling->setLeftSibling(newRight);
rightSibling = newRight;
return newRight;
} // LeafNode::split()
示例12: remove
void BTree::remove(int value)
{
BTreeNode *ptr = root-> remove(value);
if(ptr==root)
{
InternalNode *IPtr = static_cast < InternalNode * > (ptr);
ptr = IPtr->firstChild();
ptr->setParent(NULL);
root = ptr;
}
// To be written by students
} // BTree::remove()
示例13: processNode
virtual void processNode(InternalNode &u)
{
int id=u.getID();
Array2D<double>::RowIn2DArray<double> row=L[id];
Taxon *taxon=static_cast<Taxon*>(u.getDecoration());
SubstitutionMatrix &leftPt=getMatrix(*taxon,LEFT);
SubstitutionMatrix &rightPt=getMatrix(*taxon,RIGHT);
int left=u.getLeft()->getID(), right=u.getRight()->getID();
for(Symbol a=0 ; a<numAlpha ; ++a)
if(a!=gap) row[a]=
processInternalChild(a,left,leftPt)+
processInternalChild(a,right,rightPt);
}
示例14: InternalNode
/*分裂内部结点,此种情况发生在原先结点的keyNum=MAX_KEY下*/
void InternalNode::splitNode(FatherNode* parentNode, int childIndex) {
InternalNode* newNode = new InternalNode(); //分裂后的新结点
newNode->setKeyNum(MIN_KEY);
int i;
for (i = 0; i < MIN_KEY; ++i) {
newNode->setKeyValue(i, m_KeyValues[i + MIN_CHILD]);
} //向新结点中拷贝键值
for (i = 0; i < MIN_CHILD; ++i) {
newNode->setChild(i, m_Childs[i + MIN_CHILD]);
} //向新结点中拷贝指针
setKeyNum(MIN_KEY); //更新原先结点中的键值个数
((InternalNode*)parentNode)->insert(childIndex, childIndex + 1, m_KeyValues[MIN_KEY], newNode); //将新结点插入树中
}
示例15: processNode
virtual void processNode(InternalNode &u) {
int id=u.getID();
Array2D<double>::RowIn2DArray<double> row=L[id];
int left=u.getLeft()->getID(), right=u.getRight()->getID();
NthOrdSubstMatrix &leftPt=*u.getLeftSubstMatrix();
NthOrdSubstMatrix &rightPt=*u.getRightSubstMatrix();
Sequence nmer;
for(int i=0 ; i<numNmers ; ++i) {
nmer.fromInt(i,numCols,alphabetMap);
row[i]=
processInternalChild(nmer,left,leftPt)+
processInternalChild(nmer,right,rightPt);
}
}