Skip to content

Instantly share code, notes, and snippets.

@trishagee
Last active August 29, 2015 14:27
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/78b9da561ec93cb0d083 to your computer and use it in GitHub Desktop.
Save trishagee/78b9da561ec93cb0d083 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 = () -> wordList.stream();
Stream<String> stream = streamSupplier.get();
if (true == parallel) {
stream = stream.parallel();
}
stream.map(a -> streamSupplier.get()
.mapToInt(b -> Levenshtein.lev((String) a, (String) b)).toArray())
.collect(Collectors.toList()).toArray(distances);
return distances;
}
static int[][] computeLevenshtein(List<String> wordList, boolean parallel) {
final int LIST_SIZE = wordList.size();
int[][] distances = new int[LIST_SIZE][LIST_SIZE];
Stream<String> stream = wordList.stream();
if (parallel) {
stream = stream.parallel();
}
stream.map(a -> wordList.stream()
.mapToInt(b -> Levenshtein.lev(a, b))
.toArray())
.collect(toList()).toArray(distances);
return distances;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment