Skip to content

Instantly share code, notes, and snippets.

@trishagee
Last active August 29, 2015 14:26
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/0db464587c909006bcbd to your computer and use it in GitHub Desktop.
Save trishagee/0db464587c909006bcbd to your computer and use it in GitHub Desktop.
public static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
IntStream range = range(0, LIST_SIZE * LIST_SIZE);
if (parallel) {
range.parallel();
}
range.forEach(value -> {
int i = value % LIST_SIZE;
int j = value / LIST_SIZE;
distances[i][j] = lev(wordList.get(i), wordList.get(j));
});
return distances;
}
public static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
IntStream iRange = range(0, LIST_SIZE);
if (parallel) {
iRange.parallel();
}
iRange.forEach(i -> {
IntStream range = range(0, LIST_SIZE);
if (parallel) {
range.parallel();
}
range.forEach(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