本文整理汇总了C++中SuffixTree::deleteUselessNode方法的典型用法代码示例。如果您正苦于以下问题:C++ SuffixTree::deleteUselessNode方法的具体用法?C++ SuffixTree::deleteUselessNode怎么用?C++ SuffixTree::deleteUselessNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SuffixTree
的用法示例。
在下文中一共展示了SuffixTree::deleteUselessNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanTreeDfs
int cleanTreeDfs(unsigned int v, unsigned int parent, SuffixTree &tree) {
int leaf = tree[v].leaf;
for (unsigned int i = 0; i < tree[v].size(); ++i) {
unsigned int u = tree[v][i];
int newLeaf = cleanTreeDfs(u, i, tree);
if (leaf == -1) {
leaf = newLeaf;
}
}
unsigned int freeCell = 0;
for (unsigned int i = 0; i < tree[v].size(); ++i) {
if (tree[v][i] != -1) {
tree[v][freeCell] = tree[v][i];
++freeCell;
}
}
tree[v].resize(freeCell);
if (tree[v].size() <= 1 && tree[v].leaf == -1 && v != tree.root) {
tree.deleteUselessNode(v, parent, leaf);
}
return leaf;
}
示例2: decompressDfs
int decompressDfs(unsigned int v, unsigned int inParentIndex, SuffixTree &tree,
const vector <int> &input, unsigned int depth
) {
int leaf = -1;
unsigned int oldDepth = tree[v].depth;
tree[v].depth = depth;
for (unsigned int i = 0; i < tree[v].size(); ++i) {
unsigned int u = tree[v][i];
int newLeaf = decompressDfs(u, i, tree, input,
depth + tree[u].lengthOfEdge(tree, oldDepth) * 2
- (tree[u].lastIndex(tree, oldDepth) == input.size() / 2 + 1)
);
if (leaf == -1) {
leaf = newLeaf;
}
}
tree[v].indexOfParentEdge *= 2;
if (tree[v].leaf != -1) {
tree[v].leaf = min(tree[v].leaf * 2, static_cast<int>(input.size()));
}
vector <unsigned int> myNewChildren;
if (tree[v].size()) {
vector <unsigned int> similarKids;
unsigned int firstKidIndex = 0;
similarKids.push_back(tree[v][0]);
for (unsigned int i = 1; i <= tree[v].size(); ++i) {
if (i != tree[v].size()) {
unsigned int current = tree[v][i];
unsigned int previous = tree[v][i - 1];
while (i < tree[v].size()
&& input[tree[current].indexOfParentEdge]
== input[tree[previous].indexOfParentEdge]
) {
similarKids.push_back(current);
++i;
previous = current;
if (i != tree[v].size()) {
current = tree[v][i];
}
}
}
if (similarKids.size() != 1) {
unsigned int newNodeIndex = tree.splitEdge(v, firstKidIndex, 1);
auto &newNode = tree[newNodeIndex];
for (unsigned int j = 1; j < similarKids.size(); ++j) {
auto ¤tChild = tree[similarKids[j]];
currentChild.parent = newNodeIndex;
++currentChild.indexOfParentEdge;
newNode.push_back(similarKids[j]);
}
if (newNode.size()
&& tree[newNode[0]].lengthOfEdge(tree) == 0
) {
newNode.leaf = tree[newNode[0]].leaf;
tree.deleteUselessNode(newNode[0], 0, newNode.leaf);
newNode.deleteFirstChild();
}
myNewChildren.push_back(newNodeIndex);
tree.checkNode(tree[newNodeIndex]);
} else {
myNewChildren.push_back(similarKids.back());
}
if (i != tree[v].size()) {
similarKids.clear();
similarKids.push_back(tree[v][i]);
firstKidIndex = i;
}
}
}
tree[v].renewChildren(myNewChildren);
if (tree[v].size() == 1 && v != tree.root && tree[v].leaf == -1) {
tree.deleteUselessNode(v, inParentIndex, leaf);
}
if (tree[v].leaf != -1) {
leaf = tree[v].leaf;
}
return leaf;
}