1 #ifndef ROSE_EditDistance_LinearEditDistance_H
2 #define ROSE_EditDistance_LinearEditDistance_H
4 #include <EditDistance/Levenshtein.h>
7 namespace EditDistance {
38 namespace LinearEditDistance {
45 unsigned first_, second_;
49 ASSERT_not_null(node);
51 if (SgAsmInstruction *insn = isSgAsmInstruction(node)) {
52 second_ = insn->get_anyKind();
64 return first_==other.first_ && second_==other.second_;
70 template<
class NodeType>
72 std::vector<NodeType> &nodes_;
74 size_t minDepth_, maxDepth_;
77 NodeSelector(std::vector<NodeType> &nodes ,
SgFile *containingFile,
size_t minDepth,
size_t maxDepth)
78 : nodes_(nodes), containingFile_(containingFile), minDepth_(minDepth), maxDepth_(maxDepth) {
79 ASSERT_require(minDepth <= maxDepth);
84 bool isSelected = (depth >= minDepth_ && depth <= maxDepth_ &&
85 (!containingFile_ || (nodeInfo && nodeInfo->isSameFile(containingFile_))));
87 nodes_.push_back(NodeType(node));
103 template<
typename NodeType = Node>
106 std::vector<NodeType> nodes1_, nodes2_;
123 return setTree(ast1_=ast, file, minDepth, maxDepth, nodes1_);
126 return setTree(ast2_=ast, file, minDepth, maxDepth, nodes2_);
144 return compute(target, targetFile);
170 size_t n = std::max(nodes1_.size(), nodes2_.size());
171 return n ? 1.0 * cost_ / n : 1.0 * cost_;
176 Analysis& setTree(
SgNode *ast,
SgFile *file,
size_t minDepth,
size_t maxDepth, std::vector<NodeType> &nodes ) {
179 nodeSelector.traverse(ast, 0);