Skip to content

Instantly share code, notes, and snippets.

%%% File : ahocorasik.erl
%%% Author : Fyodor Ustinov <ufm@ufm.su>
%%% Descrip.: Multiple search based on Aho-Corasick string matching algorithm
%%%
%%% License : GPL
%%%
%%% Usage:
%%% ahocorasik:match(["pat1", "pat2"], "pat1 pat2 pat1")
%%% or
%%% Tree = ahocorasik:tree(["pat1", "pat2"])
%%% File : ahocorasik.erl
%%% Author : Fyodor Ustinov <ufm@ufm.su>
%%% Descrip.: Multiple search based on Aho-Corasick string matching algorithm
%%%
%%% License : GPL
%%%
%%% Usage:
%%% ahocorasik:match(["pat1", "pat2"], "pat1 pat2 pat1")
%%% or
%%% Tree = ahocorasik:tree(["pat1", "pat2"])
-module(levenshtein).
-export([distance/2]).
distance(Source, Source) -> 0;
distance(Source, []) -> length(Source);
distance([], Source) -> length(Source);
distance(Source, Target) ->
D1 = lists:seq(0, length(Target)),
outer_loop([[]|Source], [[]|Target], {D1, D1}, 1).