Find the leaf of a cluster, to get the final cluster assignment.
<p>
In contrast to {@link #insert}, this does not modify the tree.

@param nv Object data
@return Leaf this vector should be assigned to
188656
public ClusteringFeature findLeaf(NumberVector nv) {
    if(root == null) {
      throw new IllegalStateException("CFTree not yet built.");
    }
    return findLeaf(root, nv);
  }
646130
public Tree<T> addLeaf( T child )
    {
        Tree<T> leaf = new Tree<T>( child );
        leaf.parent = this;
        children.add( leaf );
        return leaf;
    }
202154
public ResourceList getResourcesWithLeafName(final String leafName) {
        if (closed.get()) {
            throw new IllegalArgumentException("Cannot use a ScanResult after it has been closed");
        }
        final ResourceList allWhitelistedResources = getAllResources();
        if (allWhitelistedResources.isEmpty()) {
            return ResourceList.EMPTY_LIST;
        } else {
            final ResourceList filteredResources = new ResourceList();
            for (final Resource classpathResource : allWhitelistedResources) {
                final String relativePath = classpathResource.getPath();
                final int lastSlashIdx = relativePath.lastIndexOf('/');
                if (relativePath.substring(lastSlashIdx + 1).equals(leafName)) {
                    filteredResources.add(classpathResource);
                }
            }
            return filteredResources;
        }
    }
1069991
private KdTree.Node createLeaf(List<P> points , GrowQueue_I32 indexes ) {
		int index = indexes == null ? -1 : indexes.get(0);
		return memory.requestNode(points.get(0),index);
	}
1143809
public Node getRoot(Node node)
  {

    Node root = null;

    while (node != null)
    {
      root = node;
      node = getParentOfNode(node);
    }

    return root;
  }
1071302
public TreeElement findNode(String nodeName)
    {
        TreeElement root = getRoot(this);
        return root.findNodeRecurse(nodeName, nodeName);
    }
374444
def _cut_tree(tree, n_clusters, membs):
    
    ## starting from root,
    ## a node is added to the cut_set or 
    ## its children are added to node_set
    assert(n_clusters >= 2)
    assert(n_clusters <= len(tree.leaves()))

    cut_centers = dict() #np.empty(shape=(n_clusters, ndim), dtype=float)
    
    for i in range(n_clusters-1):
        if i==0:
            search_set = set(tree.children(0))
            node_set,cut_set = set(), set()
        else:
            search_set = node_set.union(cut_set)
            node_set,cut_set = set(), set()

        if i+2 == n_clusters:
            cut_set = search_set
        else:
            for _ in range(len(search_set)):
                n = search_set.pop()
            
                if n.data['ilev'] is None or n.data['ilev']>i+2:
                    cut_set.add(n)
                else:
                    nid = n.identifier
                    if n.data['ilev']-2==i:
                        node_set = node_set.union(set(tree.children(nid)))
   
    conv_membs = membs.copy()
    for node in cut_set:
        nid = node.identifier
        label = node.data['label']
        cut_centers[label] = node.data['center']
        sub_leaves = tree.leaves(nid)
        for leaf in sub_leaves:
            indx = np.where(conv_membs == leaf)[0]
            conv_membs[indx] = nid

    return(conv_membs, cut_centers)
342925
public static <N extends AbstractDTNode<?, ?, ?, N>> Iterator<N> leafIterator(N root) {
        return Iterators.filter(nodeIterator(root), AbstractDTNode::isLeaf);
    }
958425
@Nullable
  public static <T> T findEnclosingNode(TreePath path, Class<T> klass) {
    path = findPathFromEnclosingNodeToTopLevel(path, klass);
    return (path == null) ? null : klass.cast(path.getLeaf());
  }
876217
protected VertexType getNextSearchTreeRoot() {
        // FIXME: slow linear search, should improve
        for (Iterator<VertexType> i = graph.vertexIterator(); i.hasNext();) {
            VertexType vertex = i.next();
            if (visitMe(vertex)) {
                return vertex;
            }
        }
        return null;
    }
864210
public int getInsertOffset(XtendTypeDeclaration container) {
		if (container.getMembers().isEmpty()) {
			final ICompositeNode node = NodeModelUtils.findActualNodeFor(container);
			final ILeafNode openingBraceNode = IterableExtensions.findFirst(node.getLeafNodes(),
					lnode -> "{".equals(lnode.getText())); //$NON-NLS-1$
			if (openingBraceNode != null) {
				return openingBraceNode.getOffset() + 1;
			}
			return node.getEndOffset();
		}
		final EObject lastFeature = IterableExtensions.last(container.getMembers());
		final ICompositeNode node = NodeModelUtils.findActualNodeFor(lastFeature);
		return node.getEndOffset();
	}
878559
function getVariable (name, leafNode) {
  let node = leafNode

  while (node != null) {
    const variables = node.variables
    const variable = variables && variables.find(v => v.id.name === name)

    if (variable != null) {
      return variable
    }

    node = node.parent
  }

  return null
}
1313403
public NaryTree getLeafAt(int idx) {
        NaryTree leaf = null;
        for (NaryTree l : this.getLeaves()) {
            if (l.start <= idx && idx < l.end) {
                leaf = l;
            }
        }
        return leaf;
    }
869213
public LeafNode<K, V> prevNode() {
		if (leftid == NULL_ID) {
			return null;
		}
		return (LeafNode<K, V>) tree.getNode(leftid);
	}
258261
private Node findBestLeafNode(ClusKernel newPoint) {
    	double minDist = Double.MAX_VALUE;
    	Node bestFit = null;
    	for (Node e: collectLeafNodes(root)){
    		if (newPoint.calcDistance(e.nearestEntry(newPoint).getData())<minDist){
    			bestFit = e;
    			minDist = newPoint.calcDistance(e.nearestEntry(newPoint).getData());
    		}
    	}
    	if (bestFit!=null)
    		return bestFit;
    	else
    		return root;
	}
1297333
static SquareNode findSeedNode(List<SquareNode> cluster) {
		SquareNode seed = null;

		for (int i = 0; i < cluster.size(); i++) {
			SquareNode n = cluster.get(i);
			int numConnections = n.getNumberOfConnections();
			if( numConnections == 0 || numConnections > 2 )
				continue;
			seed = n;
			break;
		}
		return seed;
	}
1222813
public synchronized K lastKey() {
		if (!validState) {
			throw new InvalidStateException();
		}
		final LeafNode<K, V> node = findSideLeafNode(false);
		if (node == null) {
			return null;
		}
		return node.keys[node.allocated - 1];
	}