Lines Matching refs:NodeId
39 SrcToDst = std::make_unique<NodeId[]>(Size);
40 DstToSrc = std::make_unique<NodeId[]>(Size);
43 void link(NodeId Src, NodeId Dst) {
47 NodeId getDst(NodeId Src) const { return SrcToDst[Src]; }
48 NodeId getSrc(NodeId Dst) const { return DstToSrc[Dst]; }
49 bool hasSrc(NodeId Src) const { return getDst(Src).isValid(); }
50 bool hasDst(NodeId Dst) const { return getSrc(Dst).isValid(); }
53 std::unique_ptr<NodeId[]> SrcToDst, DstToSrc;
71 NodeId getMapped(const std::unique_ptr<SyntaxTree::Impl> &Tree,
72 NodeId Id) const {
81 bool identical(NodeId Id1, NodeId Id2) const;
84 bool isMatchingPossible(NodeId Id1, NodeId Id2) const;
87 bool haveSameParents(const Mapping &M, NodeId Id1, NodeId Id2) const;
91 void addOptimalMapping(Mapping &M, NodeId Id1, NodeId Id2) const;
95 double getJaccardSimilarity(const Mapping &M, NodeId Id1, NodeId Id2) const;
98 NodeId findCandidate(const Mapping &M, NodeId Id1) const;
134 std::vector<NodeId> Leaves;
137 std::vector<NodeId> NodesBfs;
140 NodeId getRootId() const { return 0; }
144 const Node &getNode(NodeId Id) const { return Nodes[Id]; }
145 Node &getMutableNode(NodeId Id) { return Nodes[Id]; }
146 bool isValidNodeId(NodeId Id) const { return Id >= 0 && Id < getSize(); }
148 int getNumberOfDescendants(NodeId Id) const;
149 bool isInSubtree(NodeId Id, NodeId SubtreeRoot) const;
150 int findPositionInParent(NodeId Id, bool Shifted = false) const;
156 std::string getNodeValue(NodeId Id) const;
192 NodeId Parent;
197 template <class T> std::tuple<NodeId, NodeId> PreTraverse(T *ASTNode) {
198 NodeId MyId = Id;
215 void PostTraverse(std::tuple<NodeId, NodeId> State) {
216 NodeId MyId, PreviousParent;
229 for (NodeId Child : N.Children)
281 static std::vector<NodeId> getSubtreePostorder(const SyntaxTree::Impl &Tree,
282 NodeId Root) {
283 std::vector<NodeId> Postorder;
284 std::function<void(NodeId)> Traverse = [&](NodeId Id) {
286 for (NodeId Child : N.Children)
294 static std::vector<NodeId> getSubtreeBfs(const SyntaxTree::Impl &Tree,
295 NodeId Root) {
296 std::vector<NodeId> Ids;
300 for (NodeId Child : Tree.getNode(Ids[Expanded++]).Children)
309 std::function<void(NodeId)> PostorderTraverse = [&](NodeId Id) {
310 for (NodeId Child : getNode(Id).Children)
320 for (NodeId Leaf : Leaves) {
322 NodeId Parent, Cur = Leaf;
331 int SyntaxTree::Impl::getNumberOfDescendants(NodeId Id) const {
335 bool SyntaxTree::Impl::isInSubtree(NodeId Id, NodeId SubtreeRoot) const {
339 int SyntaxTree::Impl::findPositionInParent(NodeId Id, bool Shifted) const {
340 NodeId Parent = getNode(Id).Parent;
409 std::string SyntaxTree::Impl::getNodeValue(NodeId Id) const {
491 std::vector<NodeId
498 Subtree(const SyntaxTree::Impl &Tree, NodeId SubtreeRoot) : Tree(Tree) {
504 NodeId getIdInRoot(SNodeId Id) const {
516 NodeId getPostorderOffset() const {
567 const SyntaxTree::Impl &T2, NodeId Id1, NodeId Id2)
579 std::vector<std::pair<NodeId, NodeId>> getMatchingNodes() {
580 std::vector<std::pair<NodeId, NodeId>> Matches;
618 NodeId Id1 = S1.getIdInRoot(Row);
619 NodeId Id2 = S2.getIdInRoot(Col);
712 bool operator()(NodeId Id1, NodeId Id2) const {
723 std::vector<NodeId> Container;
724 PriorityQueue<NodeId, std::vector<NodeId>, HeightLess> List;
730 void push(NodeId id) { List.push(id); }
732 std::vector<NodeId> pop() {
734 std::vector<NodeId> Result;
750 void open(NodeId Id) {
751 for (NodeId Child : Tree.getNode(Id).Children)
757 bool ASTDiff::Impl::identical(NodeId Id1, NodeId Id2) const {
770 bool ASTDiff::Impl::isMatchingPossible(NodeId Id1, NodeId Id2) const {
774 bool ASTDiff::Impl::haveSameParents(const Mapping &M, NodeId Id1,
775 NodeId Id2) const {
776 NodeId P1 = T1.getNode(Id1).Parent;
777 NodeId P2 = T2.getNode(Id2).Parent;
782 void ASTDiff::Impl::addOptimalMapping(Mapping &M, NodeId Id1,
783 NodeId Id2) const {
788 std::vector<std::pair<NodeId, NodeId>> R = Matcher.getMatchingNodes();
790 NodeId Src = Tuple.first;
791 NodeId Dst = Tuple.second;
797 double ASTDiff::Impl::getJaccardSimilarity(const Mapping &M, NodeId Id1,
798 NodeId Id2) const {
802 for (NodeId Src = Id1 + 1; Src <= N1.RightMostDescendant; ++Src) {
803 NodeId Dst = M.getDst(Src);
816 NodeId ASTDiff::Impl::findCandidate(const Mapping &M, NodeId Id1) const {
817 NodeId Candidate;
819 for (NodeId Id2 : T2) {
834 std::vector<NodeId> Postorder = getSubtreePostorder(T1, T1.getRootId());
835 for (NodeId Id1 : Postorder) {
847 N1.Children, [&](NodeId Child) { return M.hasSrc(Child); });
850 NodeId Id2 = findCandidate(M, Id1);
871 for (NodeId Id : L1.pop())
876 for (NodeId Id : L2.pop())
880 std::vector<NodeId> H1, H2;
883 for (NodeId Id1 : H1) {
884 for (NodeId Id2 : H2) {
891 for (NodeId Id1 : H1) {
895 for (NodeId Id2 : H2) {
918 for (NodeId Id1 : T1) {
924 for (NodeId Id2 : T2) {
930 for (NodeId Id1 : T1.NodesBfs) {
931 NodeId Id2 = M.getDst(Id1);
941 for (NodeId Id2 : T2.NodesBfs) {
942 NodeId Id1 = M.getSrc(Id2);
966 NodeId ASTDiff::getMapped(const SyntaxTree &SourceTree, NodeId Id) const {
978 const Node &SyntaxTree::getNode(NodeId Id) const {
983 NodeId SyntaxTree::getRootId() const { return TreeImpl->getRootId(); }
989 int SyntaxTree::findPositionInParent(NodeId Id) const {
1009 std::string SyntaxTree::getNodeValue(NodeId Id) const {