Skip to content

Instantly share code, notes, and snippets.

@trishagee
Created August 13, 2015 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trishagee/953ce7315c05a07496e8 to your computer and use it in GitHub Desktop.
Save trishagee/953ce7315c05a07496e8 to your computer and use it in GitHub Desktop.
static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
IntStream stream = IntStream.range(0, LIST_SIZE);
if (parallel) {
stream = stream.parallel(); // Convert the stream to a parallel one
}
stream.forEach(i -> {
for (int j = 0; j < LIST_SIZE; j++) {
distances[i][j] = lev(wordList.get(i), wordList.get(j));
}
});
return distances;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment