Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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