You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-dev@hadoop.apache.org by "Lisheng Sun (Jira)" <ji...@apache.org> on 2019/10/25 07:18:00 UTC

[jira] [Created] (HADOOP-16671) Optimize InnerNodeImpl#getLeaf

Lisheng Sun created HADOOP-16671:
------------------------------------

             Summary: Optimize InnerNodeImpl#getLeaf
                 Key: HADOOP-16671
                 URL: https://issues.apache.org/jira/browse/HADOOP-16671
             Project: Hadoop Common
          Issue Type: Improvement
            Reporter: Lisheng Sun


{code:java}
@Override
public Node getLeaf(int leafIndex, Node excludedNode) {
  int count=0;
  // check if the excluded node a leaf
  boolean isLeaf = !(excludedNode instanceof InnerNode);
  // calculate the total number of excluded leaf nodes
  int numOfExcludedLeaves =
      isLeaf ? 1 : ((InnerNode)excludedNode).getNumOfLeaves();
  if (isLeafParent()) { // children are leaves
    if (isLeaf) { // excluded node is a leaf node
      if (excludedNode != null &&
          childrenMap.containsKey(excludedNode.getName())) {
        int excludedIndex = children.indexOf(excludedNode);
        if (excludedIndex != -1 && leafIndex >= 0) {
          // excluded node is one of the children so adjust the leaf index
          leafIndex = leafIndex>=excludedIndex ? leafIndex+1 : leafIndex;
        }
      }
    }
    // range check
    if (leafIndex<0 || leafIndex>=this.getNumOfChildren()) {
      return null;
    }
    return children.get(leafIndex);
  } else {
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-dev-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-dev-help@hadoop.apache.org