See if the node being considered is a new nearest-neighbor
193385
private void checkBestDistance(KdTree.Node node, FastQueue<KdTreeResult> neighbors) {
		double distSq = distance.distance((P)node.point,target);
		// <= because multiple nodes could be at the bestDistanceSq
		if( distSq <= mostDistantNeighborSq) {
			if( neighbors.size() < searchN ) {
				// the list of nearest neighbors isn't full yet so it doesn't know what the distance will be
				// so just keep on adding them to the list until it is full
				KdTreeResult r = neighbors.grow();
				r.distance = distSq;
				r.node = node;
				if( neighbors.size() == searchN ) {
					// find the most distant
					mostDistantNeighborSq = -1;
					for( int i = 0; i < searchN; i++ ) {
						r = neighbors.get(i);
						if( r.distance > mostDistantNeighborSq ) {
							mostDistantNeighborSq = r.distance;
							mostDistantNeighborIndex = i;
						}
					}
				}
			} else {
				for( int i = 0; i < searchN; i++ ) {
					KdTreeResult r = neighbors.get(i);
					if( r.distance > mostDistantNeighborSq ) {
						throw new RuntimeException("Most distant isn't the most distant");
					}
				}

				// Write over the most distant neighbor since we known this node must be closer
				// and update the maximum distance
				KdTreeResult r = neighbors.get(mostDistantNeighborIndex);
				r.node = node;
				r.distance = distSq;

				// If there are multiple points then there can be more than one point with the value of
				// 'bestDistanceSq', which is why two searches are required
				mostDistantNeighborSq = -1;
				for( int i = 0; i < searchN; i++ ) {
					r = neighbors.get(i);
					if( r.distance > mostDistantNeighborSq ) {
						mostDistantNeighborSq = r.distance;
						mostDistantNeighborIndex = i;
					}
				}
			}
		}
	}
801436
function check(node) {
            const body = nearestBody(),
                valid = ((body.type === "Program" && body.distance === 1) ||
                    body.distance === 2);

            if (!valid) {
                context.report({
                    node,
                    message: "Move {{type}} declaration to {{body}} root.",
                    data: {
                        type: (node.type === "FunctionDeclaration" ? "function" : "variable"),
                        body: (body.type === "Program" ? "program" : "function body")
                    }
                });
            }
        }
100401
private void calculateNearestNeighbors(int nn) {
        int n = this.dimension;
        if ((nn > 0) && (nn < n)) {
            nearestNeighbors = new int[n][nn];

            Neighbor[] neighbors = new Neighbor[n];
            for (int i = 0; i < n; i++) neighbors[i] = new Neighbor();

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    neighbors[j].id = j;
                    neighbors[j].distance = this.distances[i][j];
                }
                neighbors[i].distance = Integer.MAX_VALUE;
                Arrays.sort(neighbors);
                for (int j = 0; j < nn; j++) nearestNeighbors[i][j] = neighbors[j].id;
            }
        }
     }
399230
def node_insert_after(self, node, new_node):
        """"""

        assert(not self.node_is_on_list(new_node))
        assert(node is not new_node)

        next = self.node_next(node)
        assert(next is not None)
        self.node_set_next(node, new_node)
        self.node_set_prev(new_node, node)

        self.node_set_next(new_node, next)
        self.node_set_prev(next, new_node)
82550
def on_compare(self, node):  # ('left', 'ops', 'comparators')
        """"""
        lval = self.run(node.left)
        out = True
        for op, rnode in zip(node.ops, node.comparators):
            rval = self.run(rnode)
            out = op2func(op)(lval, rval)
            lval = rval
            if self.use_numpy and isinstance(out, numpy.ndarray) and out.any():
                break
            elif not out:
                break
        return out
223450
def visit_lambda(self, node, parent):
        """"""
        newnode = nodes.Lambda(node.lineno, node.col_offset, parent)
        newnode.postinit(self.visit(node.args, newnode), self.visit(node.body, newnode))
        return newnode
509881
def is_sibling_of(self, node):
        
        return self.get_siblings().filter(pk=node.pk).exists()
1140332
def add_neighbor(self, edge: "Edge") -> None:
        
        if edge is None or (edge.source != self and edge.target != self):
            return

        if edge.source == self:
            other: Node = edge.target
        elif edge.target == self:
            other: Node = edge.source
        else:
            raise ValueError("Tried to add a neighbor with an invalid edge.")

        edge_key: Tuple(int, int) = edge.key

        # The graph is considered undirected, check neighbor existence accordingly.
        if self._neighbors.get(edge_key) or self._neighbors.get((edge_key[1], edge_key[0])):
            return  # The neighbor is already added.

        self._neighbors[edge_key] = edge
        self.dispatch_event(NeighborAddedEvent(other))
884978
def new_edge(self, node_a, node_b, cost=1):
        """"""
        edge_id = super(UndirectedGraph, self).new_edge(node_a, node_b, cost)
        self.nodes[node_b]['edges'].append(edge_id)
        return edge_id
1191890
def _find_closest(self, n0):
        
        dmin = np.inf
        nclose = None

        ds = []
        nodes = []

        ds.append(np.inf)
        nodes.append(self)

        for n in self:
            if n is n0:
                continue
            try:
                if n._in_same_observation(n0):
                    continue
                ds.append(n.distance(n0))
                nodes.append(n)
            except AttributeError:
                pass

        inds = np.argsort(ds)
        ds = [ds[i] for i in inds]
        nodes = [nodes[i] for i in inds]

        for d,n in zip(ds, nodes):
            try:
                if d < n.resolution or n.resolution==-1:
                    return n
            except AttributeError:
                pass

        # If nothing else works
        return self
544522
def visit_Num(self, node):
        
        if isinstance(node.n, int):
            return self.add(node, Interval(node.n, node.n))
        return UNKNOWN_RANGE
305231
function () {

            // This check looks a little strange, but it suits what we're trying
            // to do: as we're walking through the children, a child node that has moved
            // from one parent to another will be found but would look like some kind
            // of insert. The check that we're doing here is looking up the current
            // child's ID in the *old* map and seeing if this child used to have a
            // different parent.
            var possiblyMovedElement = oldNodeMap[newChild.tagID];
            if (possiblyMovedElement &&
                    newParent.tagID !== getParentID(possiblyMovedElement)) {
                newEdit = {
                    type: "elementMove",
                    tagID: newChild.tagID,
                    parentID: newChild.parent.tagID
                };
                moves.push(newEdit.tagID);
                newEdits.push(newEdit);

                // this element in the new tree was a move to this spot, so we can move
                // on to the next child in the new tree.
                newIndex++;
                return true;
            }
            return false;
        }
1325944
def check_node_parent(
        self, resource_id, new_parent_id, db_session=None, *args, **kwargs
    ):
        
        return self.service.check_node_parent(
            resource_id=resource_id,
            new_parent_id=new_parent_id,
            db_session=db_session,
            *args,
            **kwargs
        )
226764
function(node){
    var nodeName = node.nodeName;
    while ((node = node.previousSibling)) if (node.nodeName == nodeName) return false;
    return true;
  }
943621
NodeAVL getNextNode(NodeAVL n) {

        if (n == null) {
            n = nPrimaryNode;
        } else {
            n = n.nNext;
        }

        return n;
    }
846454
def visit_If(self, node):
        
        currs = (node,)
        raises = ()

        # true branch
        for n in node.body:
            self.result.add_node(n)
            for curr in currs:
                self.result.add_edge(curr, n)
            currs, nraises = self.visit(n)
            raises += nraises
        if is_true_predicate(node.test):
            return currs, raises

        # false branch
        tcurrs = currs
        currs = (node,)
        for n in node.orelse:
            self.result.add_node(n)
            for curr in currs:
                self.result.add_edge(curr, n)
            currs, nraises = self.visit(n)
            raises += nraises
        return tcurrs + currs, raises
1172687
def find_neighbors(self, grid, node, diagonal_movement=None):
        '''
        
        '''
        if not diagonal_movement:
            diagonal_movement = self.diagonal_movement
        return grid.neighbors(node, diagonal_movement=diagonal_movement)