Skip to content

Instantly share code, notes, and snippets.

@archie
Created February 27, 2012 09:38
Show Gist options
  • Save archie/1922816 to your computer and use it in GitHub Desktop.
Save archie/1922816 to your computer and use it in GitHub Desktop.
Signature Matrix Creation
def createSignatureMatrix(characterMatrix: Array[Array[Int]], hashFunctions: List[HashFunction]): Array[Array[Int]] = {
val signatureMatrix: Array[Array[Int]] = createEmptySignatureMatrix(hashFunctions.length, characterMatrix(0).length)
characterMatrix.zipWithIndex.foreach { case (row, i) =>
row.zipWithIndex.foreach { case (character, j) =>
/* only apply hash functions if character is not 0 */
if (character == 1) {
hashFunctions.zipWithIndex.foreach { case (hasher, k) =>
val hashedRowValue: Int = hasher.apply(i)
if (isReplaceable(signatureMatrix(k)(j), hashedRowValue)) {
signatureMatrix(k)(j) = hashedRowValue
}
}
}
}
}
signatureMatrix
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment