Skip to content

Instantly share code, notes, and snippets.

@jmaciasluque
Created August 15, 2015 12:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jmaciasluque/d352853e3f682c8b3b3b 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];
Supplier<Stream<String>> streamSupplier = parallel ? wordList::parallelStream : wordList::stream;
streamSupplier.get()
.map(a -> streamSupplier.get()
.mapToInt(b -> Levenshtein.lev(a, b))
.toArray())
.collect(Collectors.toList()).toArray(distances);
return distances;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment