Makes sure the found grid is the same size as the original cluster.  If it's not then.
not all the nodes were used.  All lists must have he same size too.
337482
static boolean checkGridSize(List<List<NodeInfo>> grid ,
								 int clusterSize ) {
		int total = 0;
		int expected = grid.get(0).size();
		for (int i = 0; i < grid.size(); i++) {
			if( expected != grid.get(i).size() )
				return false;
			total += grid.get(i).size();
		}

		return total == clusterSize;
	}
864600
private void updatePairs(GvmCluster<S,K> cluster) {
		GvmClusterPair<S,K>[] pairs = cluster.pairs;
		//accelerated path
		if (count == bound) {
			int limit = count - 1;
			for (int i = 0; i < limit; i++) {
				this.pairs.reprioritize(pairs[i]);
			}
		} else {
			int limit = bound - 1;
			for (int i = 0; i < limit; i++) {
				GvmClusterPair<S,K> pair = pairs[i];
				if (pair.c1.removed || pair.c2.removed) continue;
				this.pairs.reprioritize(pair);
			}
		}
	}
1257564
def is_full(self):
        
        if len(self.grid) == 0:
            return False

        for i in range(len(self.grid)):
            for j in range(len(self.grid[0])):
                if self.grid[i][j] is None:
                    return False
        return True
146353
public boolean isCompleteExceptIgnoredNodes() {
        synchronized (nodeStack) {
            if (nodeStack.isEmpty() && retainedNodes.isEmpty()) {
                return true;
            } else {
                // Check that remaining nodes can be ignored
                for (int i=0; i < nodeStack.size(); i++) {
                    if (!ignoredNodes.contains(nodeStack.get(i))) {
                        return false;
                    }
                }
                for (int i=0; i < retainedNodes.size(); i++) {
                    if (!ignoredNodes.contains(retainedNodes.get(i))) {
                        return false;
                    }
                }
                return true;
            }
        }
    }
975839
def initialise_clusters(self, input_, clustercount):
        
        # initialise the clusters with empty lists
        self.__clusters = []
        for _ in range(clustercount):
            self.__clusters.append([])

        # distribute the items into the clusters
        count = 0
        for item in input_:
            self.__clusters[count % clustercount].append(item)
            count += 1
44378
public static void validateCurrentFinalCluster(final Cluster currentCluster,
                                                   final Cluster finalCluster) {
        validateClusterPartitionCounts(currentCluster, finalCluster);
        validateClusterNodeState(currentCluster, finalCluster);

        return;
    }
41361
public void process( List<List<SquareNode>> clusters ) {

		valid.reset();
		for( int i = 0; i < clusters.size(); i++ ) {
			List<SquareNode> graph = clusters.get(i);

			if( graph.size() < minimumElements )
				continue;

			switch( checkNumberOfConnections(graph) ) {
				case 1:orderIntoLine(graph); break;
				case 2:orderIntoGrid(graph); break;
//				default: System.out.println("Failed number of connections. size = "+graph.size());
			}
		}
	}
1166523
def _are_cmd_nodes_same(node1, node2):
  

  # Everything in node1 should be in node2
  for propertytype in node1:
    if (not propertytype in node2 or
        node1[propertytype] != node2[propertytype]):
      return False
  return True
792733
private static boolean handleNotEqualNodeSizes(int configNodeSize, int actualNodeSize) {
        if (configNodeSize != actualNodeSize) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Node list and configuration's partition hosts sizes : {} <> {}, rescheduling",
                        actualNodeSize, configNodeSize);
            }
            return true;
        }
        return false;
    }
82157
def _build_clusters(tile)
      used_ids = []
      clusters = []

      _adapter.in_tile(*tile.children).find_each do |child|
        cluster = _adapter.build_from(tile.depth, child)
        clusters << cluster
        used_ids << child.id
      end

      return [used_ids, clusters]
    end
121252
private boolean getGoodNode(Set<Node> candidateNodes,
                              boolean considerLoad,
                              long blockSize,
                              List<DatanodeDescriptor> results) {
    List<DatanodeDescriptor> sorted = new ArrayList<DatanodeDescriptor>();
    for (Node n : candidateNodes) {
      sorted.add((DatanodeDescriptor)n);
    }
    final long blocksize = blockSize;
    Collections.sort(sorted, new Comparator<DatanodeDescriptor>() {
      public int compare(DatanodeDescriptor n1, DatanodeDescriptor n2) {
        long ret = (n2.getRemaining() - (n2.getBlocksScheduled() * blocksize)) -
                   (n1.getRemaining() - (n1.getBlocksScheduled() * blocksize));
        return ret == 0 ? 0 : (ret > 0) ? 1 : -1;
      }
    });
    // Also, add some randomness. We are doing so because it seems
    // that if there are many copies scheduled at the same time, namenode
    // does not have the uptodate information. So, we need to add some
    // randomness so that there is not a lot of copies targeted to
    // the same node, which will overload the hosts and may lead to
    // timeouts.
    int count = sorted.size() / 2;
    Collections.shuffle(sorted.subList(0, count));
    for (DatanodeDescriptor n : sorted) {
      if (this.isGoodTarget((DatanodeDescriptor)n,
                            blocksize,
                            1, // MaxTargerPerLoc (per rack)
                            considerLoad,
                            results)) {
        results.add((DatanodeDescriptor)n);
        return true;
      }
    }
    return false;
  }
1000725
@Override
  protected DatanodeDescriptor chooseTarget(int numOfReplicas,
      DatanodeDescriptor writer, HashMap<Node, Node> excludedNodes,
      long blocksize, int maxNodesPerRack, List<DatanodeDescriptor> results,
      boolean newBlock) {

    if (numOfReplicas == 0 || clusterMap.getNumOfLeaves() == 0) {
      return writer;
    }

    int numOfResults = results.size();
    if (writer == null && !newBlock) {
      writer = results.get(0);
    }

    try {
      if (numOfResults == 0) {
        writer = chooseLocalNode(writer, excludedNodes, blocksize,
            maxNodesPerRack, results);
        if (--numOfReplicas == 0) {
          return writer;
        }
      }
      if (numOfResults <= 1) {
        // If we have a replication factor of 2, place both replicas on the
        // same rack.
        if (numOfReplicas == 1) {
          chooseLocalRack(results.get(0), excludedNodes, blocksize,
              maxNodesPerRack, results);
        } else {
          chooseFirstInRemoteRack(results.get(0), excludedNodes, blocksize,
              maxNodesPerRack, results);
        }
        if (--numOfReplicas == 0) {
          return writer;
        }
      }
      chooseRemainingReplicas(numOfReplicas, excludedNodes, blocksize,
            maxNodesPerRack, results);
    } catch (NotEnoughReplicasException e) {
      LOG.warn("Not able to place enough replicas, still in need of "
              + numOfReplicas);
    }
    return writer;
  }
319119
protected void rebuild() {
		// Checks if the number of nodes in the tree exceeds the maximum number
		while (this.rootCount > this.maxNumClusterFeatures) {
			// Doubles the global threshold
			this.T *= 2.0;
			this.root.setThreshold(calcRSquared(1));
			// Adds all nodes to the ClusteringFeature tree again
			Queue<ClusteringTreeNode> Q = new LinkedList<ClusteringTreeNode>();
			Q.addAll(this.root.getChildren());
			this.root.clearChildren();
			this.rootCount = 0;
			while (!Q.isEmpty()) {
				ClusteringTreeNode x = Q.element();
				Q.addAll(x.getChildren());
				x.clearChildren();
				bicoCFUpdate(x);
				Q.remove();
			}
		}
	}
648384
void connect(List<EllipseInfo> ellipses) {
		for (int i = 0; i < ellipses.size(); i++) {
			EllipseInfo info1 = ellipses.get(i);
			EllipseRotated_F64 e1 = info1.ellipse;
			Node node1 = nodes.get(i);

			// Only search the maximum of the major axis times two
			// add a fudge factor.  won't ever be perfect
			double maxDistance = e1.a * maxDistanceToMajorAxisRatio;
			maxDistance *= maxDistance;

			searchResults.reset();
			search.findNearest( ellipses.get(i), maxDistance, Integer.MAX_VALUE, searchResults );

			// if this node already has a cluster look it up, otherwise create a new one
			List<Node> cluster1;

			if( node1.cluster == -1 ) {
				node1.cluster = clusters.size;
				cluster1 = clusters.grow();
				cluster1.clear();
				cluster1.add( node1 );
			} else {
				cluster1 = clusters.get( node1.cluster );
			}

			double edge1 = info1.averageOutside-info1.averageInside;

			// only accept ellipses which have a similar size
			for (int j = 0; j < searchResults.size(); j++) {
				NnData<EllipseInfo> d = searchResults.get(j);
				EllipseInfo info2 = ellipses.get(d.index);
				EllipseRotated_F64 e2 = info2.ellipse;
				if( e2 == e1 )
					continue;

				// see of they are already connected
				if( node1.connections.indexOf(d.index) != -1 ) {
					continue;
				}

				// test the appearance of the ellipses edge
				double edge2 = info2.averageOutside-info2.averageInside;
				double intensityRatio = Math.abs(edge1-edge2)/Math.max(edge1,edge2);

				if( intensityRatio > edgeIntensitySimilarityTolerance)
					continue;

				// the initial search was based on size of major axis.  Now prune and take in account the distance
				// from the minor axis
				if( axisAdjustedDistanceSq(e1,e2) > maxDistance ) {
					continue;
				}

				// TODO take in in account how similar their orientation is, but less important when they are circular
				//      somehow work into aspect ratio test?

				// smallest shape divided by largest shape
				double ratioA = e1.a > e2.a ? e2.a / e1.a : e1.a / e2.a;
				double ratioB = e1.b > e2.b ? e2.b / e1.b : e1.b / e2.b;

				if( ratioA < sizeSimilarityTolerance && ratioB < sizeSimilarityTolerance ) {
					continue;
				}

				// axis ratio similarity check
				double ratioC = (e1.a*e2.b)/(e1.b*e2.a);
				if( ratioC > 1 ) ratioC = 1.0/ratioC;

				if( ratioC < ratioSimilarityTolerance ) {
					continue;
				}

				// Apply rule which combines two features
				if( intensityRatio + (1-ratioC) >
						(edgeIntensitySimilarityTolerance/1.5+(1-ratioSimilarityTolerance)) )
					continue;

				int indexNode2 = d.index;
				Node node2 = nodes.get(indexNode2);

				// node2 isn't in a cluster already.  Add it to this one
				if( node2.cluster == -1 ) {
					node2.cluster = node1.cluster;
					cluster1.add( node2 );
					node1.connections.add( indexNode2 );
					node2.connections.add( i );
				} else if( node2.cluster != node1.cluster ) {
					// Node2 is in a different cluster.  Merge the clusters
					joinClusters( node1.cluster , node2.cluster );
					node1.connections.add( indexNode2 );
					node2.connections.add( i );
				} else {
					node1.connections.add( indexNode2 );
					node2.connections.add( i );
				}
			}
		}
	}
3265
def _calculate_cluster_distance(end_iter):
    
    out = []
    sizes = []
    for x in end_iter:
        out.append(x)
        sizes.append(x.end1 - x.start1)
        sizes.append(x.end2 - x.start2)
    distance = sum(sizes) // len(sizes)
    return distance, out
798754
private static boolean namedNodeMapsAreEqual(final NamedNodeMap a, final NamedNodeMap b) {
        if (a == b) {
            return true;
        }
        if ((a == null) || (b == null)) {
            return false;
        }
        if (a.getLength() != b.getLength()) {
            return false;
        }

        List<Node> listA = new ArrayList<Node>(a.getLength());
        List<Node> listB = new ArrayList<Node>(a.getLength());

        for (int i = 0; i < a.getLength(); ++i) {
            listA.add(a.item(i));
            listB.add(b.item(i));
        }

        Collections.sort(listA, ATTRIBUTE_NODE_COMPARATOR);
        Collections.sort(listB, ATTRIBUTE_NODE_COMPARATOR);
        for (Node n1 : listA) {
            if (!nodesAreEqual(n1, listB.remove(0))) {
                return false;
            }
        }
        return true;
    }
325629
private int updateSizes(DBIDs ids, WritableDataStore<ModifiableDBIDs> labels, WritableIntegerDataStore newSizes) {
    // to count the unclustered all over
    int countUnmerged = 0;
    for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
      // checking the point's new cluster size after the clustering step
      int newClusterSize = labels.get(iter).size();
      newSizes.putInt(iter, newClusterSize);
      // the point is alone in the cluster --> not merged with other points
      if(newClusterSize == 1) {
        countUnmerged++;
      }
    }
    return countUnmerged;
  }