mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
A more scalable implementation of getCommonAncestor. Performance is roughly proportional
to the distance of the common ancestor from the compared nodes. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4265 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1709,24 +1709,43 @@ public class AVMRepository
|
|||||||
throw new AVMNotFoundException("Node not found.");
|
throw new AVMNotFoundException("Node not found.");
|
||||||
}
|
}
|
||||||
List<AVMNode> leftHistory = new ArrayList<AVMNode>();
|
List<AVMNode> leftHistory = new ArrayList<AVMNode>();
|
||||||
while (lNode != null)
|
|
||||||
{
|
|
||||||
leftHistory.add(lNode);
|
|
||||||
lNode = lNode.getAncestor();
|
|
||||||
}
|
|
||||||
List<AVMNode> rightHistory = new ArrayList<AVMNode>();
|
List<AVMNode> rightHistory = new ArrayList<AVMNode>();
|
||||||
while (rNode != null)
|
while (lNode != null || rNode != null)
|
||||||
{
|
{
|
||||||
rightHistory.add(rNode);
|
boolean checkRight = false;
|
||||||
rNode = rNode.getAncestor();
|
if (lNode != null)
|
||||||
}
|
|
||||||
for (AVMNode l : leftHistory)
|
|
||||||
{
|
|
||||||
for (AVMNode r : rightHistory)
|
|
||||||
{
|
{
|
||||||
if (l.equals(r))
|
leftHistory.add(lNode);
|
||||||
|
checkRight = true;
|
||||||
|
lNode = lNode.getAncestor();
|
||||||
|
}
|
||||||
|
boolean checkLeft = false;
|
||||||
|
if (rNode != null)
|
||||||
|
{
|
||||||
|
rightHistory.add(rNode);
|
||||||
|
checkLeft = true;
|
||||||
|
rNode = rNode.getAncestor();
|
||||||
|
}
|
||||||
|
if (checkRight)
|
||||||
|
{
|
||||||
|
AVMNode check = leftHistory.get(leftHistory.size() - 1);
|
||||||
|
for (AVMNode node : rightHistory)
|
||||||
{
|
{
|
||||||
return l.getDescriptor("", "", "");
|
if (node.equals(check))
|
||||||
|
{
|
||||||
|
return node.getDescriptor("", "", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (checkLeft)
|
||||||
|
{
|
||||||
|
AVMNode check = rightHistory.get(rightHistory.size() - 1);
|
||||||
|
for (AVMNode node : leftHistory)
|
||||||
|
{
|
||||||
|
if (node.equals(check))
|
||||||
|
{
|
||||||
|
return node.getDescriptor("", "", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user