returns the spamsum distance between ssA and ssB
    if they use a different block size, assume maximum distance
    otherwise returns the LevDistance
171623
def SpamsumDistance(ssA, ssB):
    '''
    
    '''
    mA = re.match('^(\d+)[:](.*)$', ssA)
    mB = re.match('^(\d+)[:](.*)$', ssB)

    if mA == None or mB == None:
      raise "do not appear to be spamsum signatures"

    if mA.group(1) != mB.group(1):
      return max([len(mA.group(2)), len(mB.group(2))])
    else:
      return LevDistance(mA.group(2), mB.group(2))
196579
@Override
	public int getMinPrefixLengthForBlock() {
		int count = getDivisionCount();
		int totalPrefix = getBitCount();
		for(int i = count - 1; i >= 0 ; i--) {
			AddressDivisionBase div = getDivision(i);
			int segBitCount = div.getBitCount();
			int segPrefix = div.getMinPrefixLengthForBlock();
			if(segPrefix == segBitCount) {
				break;
			} else {
				totalPrefix -= segBitCount;
				if(segPrefix != 0) {
					totalPrefix += segPrefix;
					break;
				}
			}
		}
		return totalPrefix;
	}
907121
public long getEstimateSplitSize(String[] blocks)
	{
		String parts[] = null, lastParts[] = null;
		
		long totalSize = 0;
		
		for (String block : blocks) {
			lastParts = parts;
			parts = block.split("\t");
			
			if ((lastParts != null) && (parts.length >= 3) && (lastParts.length >= 3)) {
				// If same shard, simply subtract
				long newOffset = Long.parseLong(parts[2]);
				
				if (parts[1].equals(lastParts[1])) {
					long lastOffset = Long.parseLong(lastParts[2]);
					totalSize += (newOffset - lastOffset);
				} else {
					totalSize += newOffset;
					//TODO: Compute size of all in between shards
					//computeBlockSizeDiff();
				}
			}
		}
		
		return totalSize;
	}
1124753
private boolean fromScratchDistanceMatrixComputation() {
		logger.fine("Propagating (cube) with (#TPs,#cons) = (" + this.MAX_USED + "," + this.theNetwork.getConstraints().length + ") (call num.: " + (++cubePropCount) + ")");
		//*
		//This code is not tested thoroughly but seems to work
		for (int i = 0; i < MAX_USED+1; i++) {
			for (int j = i; j < MAX_USED+1; j++) {
				if (i != j) {
					long dij = H;//APSPSolver.INF;
					long dji = H;//APSPSolver.INF;

					if(tPoints[i].getOut(j) != null) {
						dij = Math.min(dij, +tPoints[i].getOut(j).getMaximum());
						dji = Math.min(dji, -tPoints[i].getOut(j).getMinimum());
					}
					if(tPoints[j].getOut(i) != null) {
						dij = Math.min(dij, -tPoints[j].getOut(i).getMinimum());
						dji = Math.min(dji, +tPoints[j].getOut(i).getMaximum());
					}

					if(-dji > +dij) {
						return false;
					}

					distance[i][j] = dij;
					distance[j][i] = dji;

				}
				else distance[i][j] = 0;
			}
		}

		for (int k = 0; k < MAX_USED+1; k++) {
			if (tPoints[k].isUsed() == true) {
				for (int i = 0; i < MAX_USED+1; i++) {
					if (tPoints[i].isUsed() == true) {
						for (int j = 0; j < MAX_USED+1; j++) { 
							if (tPoints[j].isUsed() == true) {
								long temp = sum(distance[i][k],distance[k][j]);
								if (distance[i][j] > temp)
									distance[i][j] = temp;
							}
							if (i == j && distance[i][j] < 0) return false;
						}
					}
				}
			}
		}

		return true;
	}
94144
public static int levenshteinDistance(String o1, String o2) {
    // Let o1 be the shorter one:
    if(o1.length() > o2.length()) {
      return levenshteinDistance(o2, o1);
    }
    final int l1 = o1.length(), l2 = o2.length();
    // Exploit that Java caches the hash code of strings:
    if(l1 == l2 && o1.hashCode() == o2.hashCode() && o1.equals(o2)) {
      return 0;
    }
    // Determine prefix and postfix lengths:
    final int prefix = prefixLen(o1, o2);
    if(prefix == l1 || prefix == l2) {
      return Math.abs(l1 - l2);
    }
    final int postfix = postfixLen(o1, o2, prefix);
    return // Prefix and postfix are a complete object:
    (prefix + postfix == l1 || prefix + postfix == l2) ? Math.abs(l1 - l2) : //
    // Exactly one char difference optimization:
        (l1 == l2 && prefix + postfix + 1 == l1) ? 1 : //
        // Default case, compute
            levenshteinDistance(o1, o2, prefix, postfix);
  }
473775
@Override
	public long blocksAccessed() {
		double rpb = (double) (Buffer.BUFFER_SIZE / RecordPage.slotSize(p.schema()));
		return (int) Math.ceil(p.recordsOutput() / rpb);
	}
889673
def block_size(self):
        
        bs = self.attributes['block_size']
        if isinstance(bs, six.string_types):
            bs = shlex.split(bs)
        bs = [str(e) for e in bs]
        return bs
831988
public static int cusparseSbsrmm(
        cusparseHandle handle, 
        int dirA, 
        int transA, 
        int transB, 
        int mb, 
        int n, 
        int kb, 
        int nnzb, 
        Pointer alpha, 
        cusparseMatDescr descrA, 
        Pointer bsrSortedValA, 
        Pointer bsrSortedRowPtrA, 
        Pointer bsrSortedColIndA, 
        int blockSize, 
        Pointer B, 
        int ldb, 
        Pointer beta, 
        Pointer C, 
        int ldc)
    {
        return checkResult(cusparseSbsrmmNative(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockSize, B, ldb, beta, C, ldc));
    }
277229
private boolean shrinkBlock() throws StructureException,
			RefinerFailedException {

		// Let shrink moves only if the repeat is larger enough
		if (repeatCore <= Lmin)
			return false;

		// Select column by maximum distance
		updateMultipleAlignment();
		Matrix residueDistances = MultipleAlignmentTools
				.getAverageResidueDistances(msa);

		double maxDist = Double.MIN_VALUE;
		double[] colDistances = new double[length];
		int res = 0;
		for (int col = 0; col < length; col++) {
			int normalize = 0;
			for (int s = 0; s < order; s++) {
				if (residueDistances.get(s, col) != -1) {
					colDistances[col] += residueDistances.get(s, col);
					normalize++;
				}
			}
			colDistances[col] /= normalize;
			if (colDistances[col] > maxDist) {
				// geometric distribution
				if (rnd.nextDouble() > 0.5) {
					maxDist = colDistances[col];
					res = col;
				}
			}
		}

		for (int su = 0; su < order; su++) {
			Integer residue = block.get(su).get(res);
			block.get(su).remove(res);
			if (residue != null)
				freePool.add(residue);
			Collections.sort(freePool);
		}
		length--;
		checkGaps();
		return true;
	}
243175
public static int cusparseScsr2gebsr_bufferSize(
        cusparseHandle handle, 
        int dirA, 
        int m, 
        int n, 
        cusparseMatDescr descrA, 
        Pointer csrSortedValA, 
        Pointer csrSortedRowPtrA, 
        Pointer csrSortedColIndA, 
        int rowBlockDim, 
        int colBlockDim, 
        int[] pBufferSizeInBytes)
    {
        return checkResult(cusparseScsr2gebsr_bufferSizeNative(handle, dirA, m, n, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, rowBlockDim, colBlockDim, pBufferSizeInBytes));
    }
64043
private int hammingDistance(String simHash1, String simHash2) {
        if (simHash1.length() != simHash2.length()) {
            return -1;
        }
        int distance = 0;
        int len = simHash1.length();
        for (int i = 0; i < len; i++) {
            if (simHash1.charAt(i) != simHash2.charAt(i)) {
                distance++;
            }
        }
        return distance;
    }
335873
function difference(arrayA, arrayB) {
  var maxLength = _.max([ arrayA.length, arrayB.length ]);

  for (var i = 0, j = 0; i < maxLength; i += 1, j += 1) {
    if (arrayA[i] !== arrayB[j]) {
      if (arrayB[i-1] === arrayA[i]) {
        j -= 1;
      } else if (arrayB[i+1] === arrayA[i]) {
        j += 1;
      } else {
        return arrayA[i];
      }
    }
  }
}
231386
private void read_block_sizes_from_disk(boolean coalesce_blocks)
    throws IOException
    {
        long addr = FIRST_TAIL;
        int length;
        long new_tail = tail_ptr;

        while (addr < tail_ptr) {
            seek(addr);
            if (coalesce_blocks) {
                length = combine_blocks(addr);
            } else {
                length = readInt();
            }
            if (length > 0) {
                if ((length + addr >= tail_ptr) && (!readOnly)) {
                    // add last block to tail
                    new_tail = addr;
                } else {
                    add_to_freelist(addr, length);
                }
            } else {
                length = - length;
                allocated_blocks++;
                allocated_words += length;
            }
            addr = addr + length;
        }
        if ((new_tail != tail_ptr) && (!readOnly)) {
            tail_ptr = new_tail;
            seek(TAIL_DPTR);
            writeLong(tail_ptr);
        }

    }
934426
int getLongestChainLength() {
		int maxLen = 0;

		for (Entry<?, ?> entry : table) {
			int thisLen = 0;
			while (entry != null) {
				thisLen++;
				entry = entry.next;
			}
			maxLen = Math.max(maxLen, thisLen);
		}

		return maxLen;
	}
1192592
def ks_distance(a, b):
    ''''''
    if len(a.shape) == 1:
        return np.max(np.abs(a.cumsum() - b.cumsum()))
    return np.max(np.abs(a.cumsum(axis=1) - b.cumsum(axis=1)), axis=1)
724013
def distance(self, other):
        
        return distance((self.separation, self.pa), (other.separation, other.pa))
389567
public static int distanceP(int index0, int index1, int size) {
		int difference = index1-index0;
		if( difference < 0 ) {
			difference = size+difference;
		}
		return difference;
	}