Search method to find the closest node to a location specified by a test offset

@param nodes
The nodes to search within
@param offSet
The offset to match a node to
@return The node closest to the offset or null
513006
public static INode search(List<INode> nodes, int offSet,
			IVdmSourceUnit source)
	{
		synchronized (seacher)
		{
			if (DEBUG_PRINT)
			{
				System.out.println("Search start");
			}
			seacher.init();
			seacher.offSet = offSet;
			seacher.sourceFile = source.getSystemFile();
			try
			{
				for (INode node : nodes)
				{
					node.apply(seacher);
				}
			} catch (AnalysisException e)
			{
				// We found what we are looking for
			}

			return seacher.bestHit != null ? seacher.bestHit
					: seacher.bestAlternativeHit;
		}

	}
649149
static Edge selectClosest( NodeInfo a , NodeInfo b , boolean checkSide ) {

		double bestScore = Double.MAX_VALUE;
		Edge bestEdgeA = null;

		Edge edgeAB = a.findEdge(b);
		double distAB = a.distance(b);

		if( edgeAB == null ) {
			return null;// TODO BUG! FIX!
		}

		for (int i = 0; i < a.edges.size; i++) {
			Edge edgeA = a.edges.get(i);
			NodeInfo aa = a.edges.get(i).target;
			if( aa.marked ) continue;

			for (int j = 0; j < b.edges.size; j++) {
				Edge edgeB = b.edges.get(j);
				NodeInfo bb = b.edges.get(j).target;
				if( bb.marked ) continue;

				if( aa == bb ) {
//					System.out.println("center "+aa.ellipse.center);
					if( checkSide && UtilAngle.distanceCW(edgeAB.angle,edgeA.angle) > Math.PI*0.75 )
						continue;

					double angle = UtilAngle.dist(edgeA.angle,edgeB.angle);

					if( angle < 0.3 )
						continue;

					double da = EllipsesIntoClusters.axisAdjustedDistanceSq(a.ellipse,aa.ellipse);
					double db = EllipsesIntoClusters.axisAdjustedDistanceSq(b.ellipse,aa.ellipse);

					da = Math.sqrt(da);
					db = Math.sqrt(db);

					// see if they are approximately the same distance
					double diffRatio = Math.abs(da-db)/Math.max(da,db);
					if( diffRatio > 0.3 )
						continue;

					// TODO reject if too far
					double d = (da+db)/distAB + 0.1*angle;

					if( d < bestScore ) {
						bestScore = d;
						bestEdgeA = a.edges.get(i);
					}
					break;
				}
			}
		}

		return bestEdgeA;
	}
262772
function(ast, offset) {
			var found = null;
			var dom = ast;
			var missingTagClose = false;
			if (!Array.isArray(ast) && ast.children){
				dom = ast.children;
			}
			 Visitor.visit(dom, {
	            visitNode: function(node) {
					if(node.range[0] <= offset) {
						found = node;
					} else {
					    return Visitor.BREAK;
					}      
	            },
	            endVisitNode: function(node) {
	            	if(found && !missingTagClose && offset >= found.range[1] && offset > node.range[0]) {
	            		found = node;
	            		// If at the boundary of a tag range and there is a missing end tag, return the innermost tag  <a><b></a>
	            		if (offset === found.range[1] && found.endrange && found.openrange && found.endrange[1] === found.openrange[1]){
	            			missingTagClose = true;
	            		}
	            	}
	            }
	        });
	        return found;
		}
1111558
public Set<Weighted<DirectedEdge>> directedEdges(Map<NodeId, Node> nodes) {
        return Collections.emptySet();
    }
594966
public INode getLastCompleteNodeByOffset(INode node, int offsetPosition, int completionOffset) {
		return internalGetLastCompleteNodeByOffset(node.getRootNode(), offsetPosition);
	}
722005
@Pure
	private static boolean isOutsideNodeBuildingBounds(AbstractGISTreeSetNode<?, ?> node,
			Rectangle2afp<?, ?, ?, ?, ?, ?> location) {
		final Rectangle2d b2 = getNormalizedNodeBuildingBounds(node, location);
		if (b2 == null) {
			return false;
		}
		return Rectangle2afp.classifiesRectangleRectangle(
				b2.getMinX(), b2.getMinY(), b2.getMaxX(), b2.getMaxY(),
				location.getMinX(), location.getMinY(), location.getMaxX(), location.getMaxY()) != IntersectionType.INSIDE;
	}
962603
protected void orderNode(SquareNode target, SquareNode node, boolean pointingX) {

		int index0 = findIntersection(target,node);
		int index1 = (index0+1)%4;

		int index2 = (index0+2)%4;
		int index3 = (index0+3)%4;

		if( index0 < 0 )
			throw new RuntimeException("Couldn't find intersection.  Probable bug");

		lineCenters.a = target.center;
		lineCenters.b = node.center;
		UtilLine2D_F64.convert(lineCenters,general);

		Polygon2D_F64 poly = target.square;
		if( pointingX ) {
			if (sign(general, poly.get(index0)) > 0) {
				ordered[1] = poly.get(index1);
				ordered[2] = poly.get(index0);
			} else {
				ordered[1] = poly.get(index0);
				ordered[2] = poly.get(index1);
			}
			if (sign(general, poly.get(index2)) > 0) {
				ordered[3] = poly.get(index2);
				ordered[0] = poly.get(index3);
			} else {
				ordered[3] = poly.get(index3);
				ordered[0] = poly.get(index2);
			}
		} else {
			if (sign(general, poly.get(index0)) > 0) {
				ordered[2] = poly.get(index1);
				ordered[3] = poly.get(index0);
			} else {
				ordered[2] = poly.get(index0);
				ordered[3] = poly.get(index1);
			}
			if (sign(general, poly.get(index2)) > 0) {
				ordered[0] = poly.get(index2);
				ordered[1] = poly.get(index3);
			} else {
				ordered[0] = poly.get(index3);
				ordered[1] = poly.get(index2);
			}
		}
	}
502791
function getNodeForCharacterOffset(root, offset) {
  var node = getLeafNode(root);
  var nodeStart = 0;
  var nodeEnd = 0;

  while (node) {
    if (node.nodeType === TEXT_NODE$3) {
      nodeEnd = nodeStart + node.textContent.length;

      if (nodeStart <= offset && nodeEnd >= offset) {
        return {
          node: node,
          offset: offset - nodeStart
        };
      }

      nodeStart = nodeEnd;
    }

    node = getLeafNode(getSiblingNode(node));
  }
}
551870
protected void obtainEndpoints(List<Node> nodes, List<EndpointInfo> endpoints) {
        for (int i = 0; i < nodes.size(); i++) {
            Node node = nodes.get(i);

            if (node.getUri() != null) {
                EndpointInfo ei=new EndpointInfo();
                ei.setEndpoint(EndpointUtil.encodeEndpoint(node.getUri(), node.getOperation()));

                if (!endpoints.contains(ei)) {
                    initEndpointInfo(ei);
                    endpoints.add(ei);
                }
            }

            if (node instanceof ContainerNode) {
                obtainEndpoints(((ContainerNode) node).getNodes(), endpoints);
            }
        }
    }
1068311
public void add(ImprintNode... nodes) throws HashException {
        notNull(nodes, "Nodes");
        for (ImprintNode node : nodes) {
            add(node);
        }
    }
137015
private void search(Node node, E q, int k, List<Neighbor<E, E>> neighbors) {
        int d = (int) distance.d(node.object, q);

        if (d <= k) {
            if (node.object != q || !identicalExcluded) {
                neighbors.add(new Neighbor<>(node.object, node.object, node.index, d));
            }
        }

        if (node.children != null) {
            int start = Math.max(1, d-k);
            int end = Math.min(node.children.size(), d+k+1);
            for (int i = start; i < end; i++) {
                Node child = node.children.get(i);
                if (child != null) {
                    search(child, q, k, neighbors);
                }
            }
        }
    }
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;
					}
				}
			}
		}
	}
1346464
protected int findIntersection( SquareNode target , SquareNode node ) {
		lineCenters.a = target.center;
		lineCenters.b = node.center;

		for (int i = 0; i < 4; i++) {
			int j = (i+1)%4;

			lineSide.a = target.square.get(i);
			lineSide.b = target.square.get(j);

			if(Intersection2D_F64.intersection(lineCenters,lineSide,dummy) != null ) {
				return i;
			}
		}
		return -1;
	}
575629
public static void recycleNodes(AccessibilityNodeInfoCompat... nodes) {
        if (nodes == null) {
            return;
        }

        for (AccessibilityNodeInfoCompat node : nodes) {
            if (node != null) {
                node.recycle();
            }
        }
    }
372640
private List<INodeEntry> select(final int count, final Collection<INodeEntry> nodes) {
        List<INodeEntry> source = new ArrayList<>(nodes);
        List<INodeEntry> selected = new ArrayList<>();
        int total = Math.min(count, nodes.size());
        for (int i = 0; i < total; i++) {
            selected.add(source.remove(random.nextInt(source.size())));
        }
        return selected;
    }
1251172
@SuppressWarnings("unchecked")
	@Override
	public T getEndpoint(String nodeID) {
		Endpoint[] array;
		if (nodeID == null && preferLocal) {
			array = getEndpointsByNodeID(this.nodeID);
			if (array.length == 0) {
				array = endpoints;
			}
		} else {
			array = getEndpointsByNodeID(nodeID);
		}
		if (array.length == 0) {
			return null;
		}
		if (array.length == 1) {
			return (T) array[0];
		}
		return (T) next(array);
	}
368286
public static void getTopicLinkIds(final Node node, final Set<String> linkIds) {
        // If the node is null then there isn't anything to find, so just return.
        if (node == null) {
            return;
        }

        if (node.getNodeName().equals("xref") || node.getNodeName().equals("link")) {
            final NamedNodeMap attributes = node.getAttributes();
            if (attributes != null) {
                final Node idAttribute = attributes.getNamedItem("linkend");
                if (idAttribute != null) {
                    final String idAttributeValue = idAttribute.getNodeValue();
                    linkIds.add(idAttributeValue);
                }
            }
        }

        final NodeList elements = node.getChildNodes();
        for (int i = 0; i < elements.getLength(); ++i) {
            getTopicLinkIds(elements.item(i), linkIds);
        }
    }