Confirms that both clusters have the same number of nodes by comparing
set of node Ids between clusters.

@param lhs
@param rhs
329773
public static void validateClusterNodeCounts(final Cluster lhs, final Cluster rhs) {
        if(!lhs.getNodeIds().equals(rhs.getNodeIds())) {
            throw new VoldemortException("Node ids are not the same [ lhs cluster node ids ("
                                         + lhs.getNodeIds()
                                         + ") not equal to rhs cluster node ids ("
                                         + rhs.getNodeIds() + ") ]");
        }
    }
122375
void mergeClusters_(int cluster_1, int cluster2) {
		// dbg_check_cluster_(cluster_1);
		// dbg_check_cluster_(cluster2);
		int eventQnode = getClusterEventQNode(cluster2);
		if (eventQnode != -1) {
			m_event_q.deleteNode(eventQnode, -1);
			setClusterEventQNode_(cluster2, -1);
		}

		int firstEdge1 = getClusterFirstEdge(cluster_1);
		int firstEdge2 = getClusterFirstEdge(cluster2);

		if (firstEdge2 != -1) {// scope
			int edge2 = firstEdge2;
			int lastEdge = firstEdge2;
			boolean bForceContinue = false;
			// Delete edges that connect cluster_1 and cluster2.
			do {
				// dbg_check_edge_(edge2);
				bForceContinue = false;
				// assert(!StridedIndexTypeCollection.isValidElement(getEdgeSweepNode(edge2)));
				int end = getEdgeEnd(edge2, cluster2);
				int nextEdge2 = getNextEdgeEx(edge2, end);
				if (getEdgeCluster(edge2, (end + 1) & 1) == cluster_1) { // Snapping
																			// clusters
																			// that
																			// are
																			// connected
																			// with
																			// an
																			// edge
																			// Delete
																			// the
																			// edge.
					disconnectEdge_(edge2);
					int edgeOrigins2 = getEdgeOriginVertices(edge2);
					m_edge_vertices.deleteList(edgeOrigins2);
					deleteEdge_(edge2);
					if (edge2 == nextEdge2) {// deleted last edge connecting to
												// the cluster2 (all connections
												// are degenerate)
						firstEdge2 = -1;
						break;
					}
					if (firstEdge2 == edge2) {
						firstEdge2 = getClusterFirstEdge(cluster2);
						lastEdge = nextEdge2;
						bForceContinue = true;
					}
				} else {
					assert (edge2 != getClusterFirstEdge(cluster_1));
				}
				edge2 = nextEdge2;
			} while (edge2 != lastEdge || bForceContinue);

			if (firstEdge2 != -1) {
				// set the cluster to the edge ends
				do {
					int end = getEdgeEnd(edge2, cluster2);
					int nextEdge2 = getNextEdgeEx(edge2, end);
					assert (edge2 != getClusterFirstEdge(cluster_1));
					setEdgeCluster_(edge2, end, cluster_1);
					edge2 = nextEdge2;
				} while (edge2 != lastEdge);

				firstEdge1 = getClusterFirstEdge(cluster_1);
				if (firstEdge1 != -1) {
					int next1 = getNextEdge(firstEdge1, cluster_1);
					int next2 = getNextEdge(firstEdge2, cluster_1);
					if (next1 == firstEdge1) {
						setClusterFirstEdge_(cluster_1, firstEdge2);
						addEdgeToClusterImpl_(firstEdge1, cluster_1);
						setClusterFirstEdge_(cluster_1, firstEdge1);
					} else if (next2 == firstEdge2) {
						addEdgeToClusterImpl_(firstEdge2, cluster_1);
					}

					setNextEdge_(firstEdge2, cluster_1, next1);
					setPrevEdge_(next1, cluster_1, firstEdge2);
					setNextEdge_(firstEdge1, cluster_1, next2);
					setPrevEdge_(next2, cluster_1, firstEdge1);
				} else {
					setClusterFirstEdge_(cluster_1, firstEdge2);
				}
			}
		}

		int vertices1 = getClusterVertices(cluster_1);
		int vertices2 = getClusterVertices(cluster2);
		// Update cluster info on vertices.
		for (int vh = m_cluster_vertices.getFirst(vertices2); vh != -1; vh = m_cluster_vertices
				.getNext(vh)) {
			int v = m_cluster_vertices.getElement(vh);
			m_shape.setUserIndex(v, m_vertex_cluster_index, cluster_1);
		}
		m_cluster_vertices.concatenateLists(vertices1, vertices2);
		deleteCluster_(cluster2);
		// dbg_check_cluster_(cluster_1);
	}
1094914
public void setNodeSnapshots(java.util.Collection<NodeSnapshot> nodeSnapshots) {
        if (nodeSnapshots == null) {
            this.nodeSnapshots = null;
            return;
        }

        this.nodeSnapshots = new com.amazonaws.internal.SdkInternalList<NodeSnapshot>(nodeSnapshots);
    }
533882
private boolean compareBytes(byte[] lhs, byte[] rhs, int rhsOffset)
   {
      boolean result = true;
      for (int loop = 0; loop < lhs.length; loop++)
      {
         if (lhs[loop] != rhs[rhsOffset + loop])
         {
            result = false;
            break;
         }
      }
      return (result);
   }
657630
protected void determineNumberOfClusters() {
        if (!m_numberOfClustersDetermined
                && (m_cobwebTree != null)) {
            int[] numClusts = new int[1];
            numClusts[0] = 0;
            //  try {
            m_cobwebTree.assignClusterNums(numClusts);
            // }
            // catch (Exception e) {
//	e.printStackTrace();
//	numClusts[0] = 0;
            // }
            m_numberOfClusters = numClusts[0];

            m_numberOfClustersDetermined = true;
        }
    }
433919
private Map<Integer, Integer> getNodeIdToPrimaryCount(Cluster cluster) {
        Map<Integer, Integer> nodeIdToPrimaryCount = Maps.newHashMap();
        for(Node node: cluster.getNodes()) {
            nodeIdToPrimaryCount.put(node.getId(), node.getPartitionIds().size());
        }

        return nodeIdToPrimaryCount;
    }
938951
public void process(Clustering<?> result1, Clustering<?> result2) {
    // Get the clusters
    final List<? extends Cluster<?>> cs1 = result1.getAllClusters();
    final List<? extends Cluster<?>> cs2 = result2.getAllClusters();

    // Initialize
    size1 = cs1.size();
    size2 = cs2.size();
    contingency = new int[size1 + 2][size2 + 2];
    noise1 = BitsUtil.zero(size1);
    noise2 = BitsUtil.zero(size2);

    // Fill main part of matrix
    {
      final Iterator<? extends Cluster<?>> it2 = cs2.iterator();
      for(int i2 = 0; it2.hasNext(); i2++) {
        final Cluster<?> c2 = it2.next();
        if(c2.isNoise()) {
          BitsUtil.setI(noise2, i2);
        }
        contingency[size1 + 1][i2] = c2.size();
        contingency[size1 + 1][size2] += c2.size();
      }
    }
    final Iterator<? extends Cluster<?>> it1 = cs1.iterator();
    for(int i1 = 0; it1.hasNext(); i1++) {
      final Cluster<?> c1 = it1.next();
      if(c1.isNoise()) {
        BitsUtil.setI(noise1, i1);
      }
      final DBIDs ids = DBIDUtil.ensureSet(c1.getIDs());
      contingency[i1][size2 + 1] = c1.size();
      contingency[size1][size2 + 1] += c1.size();

      final Iterator<? extends Cluster<?>> it2 = cs2.iterator();
      for(int i2 = 0; it2.hasNext(); i2++) {
        final Cluster<?> c2 = it2.next();
        int count = DBIDUtil.intersectionSize(ids, c2.getIDs());
        contingency[i1][i2] = count;
        contingency[i1][size2] += count;
        contingency[size1][i2] += count;
        contingency[size1][size2] += count;
      }
    }
  }
471337
boolean sameKAMs(Kam... kams) {
        Set<Kam> set = new HashSet<Kam>(kams.length);
        for (int i = 0; i < kams.length; i++) {
            set.add(kams[i]);
        }
        if (set.size() == 1) {
            return true;
        }
        return false;
    }
1323441
@GwtIncompatible("incompatible method")
    private void appendArray(final Object lhs, final Object rhs) {
        // First we compare different dimensions, for example: a boolean[][] to a boolean[]
        // then we 'Switch' on type of array, to dispatch to the correct handler
        // This handles multi dimensional arrays of the same depth
        if (lhs.getClass() != rhs.getClass()) {
            this.setEquals(false);
        } else if (lhs instanceof long[]) {
            append((long[]) lhs, (long[]) rhs);
        }
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 );
				}
			}
		}
	}
509691
public void setReplicationInstances(java.util.Collection<ReplicationInstance> replicationInstances) {
        if (replicationInstances == null) {
            this.replicationInstances = null;
            return;
        }

        this.replicationInstances = new java.util.ArrayList<ReplicationInstance>(replicationInstances);
    }
170315
public static void scanForLeaves(List<RPNode> nodes,RPNode current) {
        if(current.getLeft() == null && current.getRight() == null)
            nodes.add(current);
        if(current.getLeft() != null)
            scanForLeaves(nodes,current.getLeft());
        if(current.getRight() != null)
            scanForLeaves(nodes,current.getRight());
    }
209351
@GwtIncompatible("incompatible method")
    private static void register(final Object lhs, final Object rhs) {
        Set<Pair<IDKey, IDKey>> registry = getRegistry();
        if (registry == null) {
            registry = new HashSet<>();
            REGISTRY.set(registry);
        }
        final Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs);
        registry.add(pair);
    }
864694
public static void validateClusterZonesSame(final Cluster lhs, final Cluster rhs) {
        Set<Zone> lhsSet = new HashSet<Zone>(lhs.getZones());
        Set<Zone> rhsSet = new HashSet<Zone>(rhs.getZones());
        if(!lhsSet.equals(rhsSet))
            throw new VoldemortException("Zones are not the same [ lhs cluster zones ("
                                         + lhs.getZones() + ") not equal to rhs cluster zones ("
                                         + rhs.getZones() + ") ]");
    }
325299
public boolean equalsOnlyNames(NodeSchema otherSchema) {
        if (otherSchema == null) {
            return false;
        }

        if (otherSchema.size() != size()) {
            return false;
        }

        for (int colIndex = 0; colIndex < size(); colIndex++ ) {
            SchemaColumn col1 = otherSchema.getColumn(colIndex);
            SchemaColumn col2 = m_columns.get(colIndex);
            if (col1.compareNames(col2) != 0) {
                return false;
            }
        }

        return true;
    }
26588
@SuppressWarnings("unchecked")
  public <E> boolean isEqualsCollections(Collection<E> coll1, Collection<E> coll2, boolean isOrdered,
      ISrvIsEquals<E> srvIsEquals) {
    if((coll1 == null && coll2 != null) ||
        (coll1 != null && coll2 == null)) {
      return false;
    }
    if(coll1 != null && coll2 != null) {
      if(coll1.size() != coll2.size()) {
        return false;
      }
      if(isOrdered) {
        Object[] arr1 = coll1.toArray();
        Object[] arr2 = coll2.toArray();
        for(int i=0; i < coll1.size(); i++) {
          if(!srvIsEquals.getIsEquals((E)arr1[i], (E)arr2[i])) {
            return false;
          }
        }
      }
      else {
        outer:
        for(E e1 : coll1) {
          for(E e2 : coll2) {
            if(srvIsEquals.getIsEquals(e1, e2)) {
              continue outer;
            }
          }
          return false;
        }
      }
    }
    return true;  
  }
999198
protected void processCluster( List<SquareNode> cluster ) {
		invalid = false;
		// handle a special case
		if( cluster.size() == 1 ) {
			SquareNode n = cluster.get(0);
			if( n.getNumberOfConnections() == 0 ) {
				SquareGrid grid = grids.grow();
				grid.reset();
				grid.columns = grid.rows = 1;
				grid.nodes.add(n);
				return;
			}
		}

		for (int i = 0; i < cluster.size(); i++) {
			cluster.get(i).graph = SquareNode.RESET_GRAPH;
		}

		SquareNode seed = findSeedNode(cluster);

		if( seed == null )
			return;

		// find the first row
		List<SquareNode> firstRow;
		if( seed.getNumberOfConnections() == 1 ) {
			firstRow = firstRow1(seed);
		} else if( seed.getNumberOfConnections() == 2 ) {
			firstRow = firstRow2(seed);
		} else {
			throw new RuntimeException("BUG");
		}
		if( invalid || firstRow == null )
			return;

		// Add the next rows to the list, one after another
		List<List<SquareNode>> listRows = new ArrayList<>();// TODO remove memory declaration here
		listRows.add(firstRow);
		while(true ) {
			List<SquareNode> previous = listRows.get(listRows.size()-1);
			if( !addNextRow(previous.get(0),listRows)) {
				break;
			}
		}

		if( invalid || listRows.size() < 2)
			return;

		// re-organize into a grid data structure
		SquareGrid grid = assembleGrid(listRows);

		// check the grids connectivity
		if( grid == null || !checkEdgeCount(grid) ) {
			grids.removeTail();
		}
	}