diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2015-10-30 07:53:08 +0100 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2015-10-30 07:53:08 +0100 |
commit | e1a19fbda5bb54a1378620c8df9c2d42ed087fee (patch) | |
tree | 73257383b80e08e54298464bdf1af6bd1dd19e57 | |
parent | 32d25b33ee109f1979db85d7ddf563246d6bcb7f (diff) | |
download | luaotfload-e1a19fbda5bb54a1378620c8df9c2d42ed087fee.tar.gz |
[db] omit duplicate entries from fuzzed lookup results
-rw-r--r-- | src/luaotfload-database.lua | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index b84b48d..1bc2768 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -1171,6 +1171,25 @@ local iterative_levenshtein = function (s1, s2) return costs[len2]--- lower right has the distance end +--- string list -> string list +local delete_dupes = function (lst) + local n0 = #lst + if n0 == 0 then return lst end + tablesort (lst) + local ret = { } + local last + for i = 1, n0 do + local cur = lst[i] + if cur ~= last then + last = cur + ret[#ret + 1] = cur + end + end + logreport (false, 8, "query", + "Removed %d duplicate names.", n0 - #ret) + return ret +end + --- string -> int -> bool find_closest = function (name, limit) local name = sanitize_fontname (name) @@ -1216,6 +1235,7 @@ find_closest = function (name, limit) else --- append namelst[#namelst+1] = fullname end + by_distance[dist] = namelst end @@ -1229,11 +1249,11 @@ find_closest = function (name, limit) for i = 1, limit do local dist = distances[i] - local namelst = by_distance[dist] + local namelst = delete_dupes (by_distance[dist]) logreport (false, 0, "query", "Distance from \"%s\": %s\n " .. tableconcat (namelst, "\n "), - name, dist) + name, dist) end return true |