提交 95a8cdaf 编写于 作者: J Johannes Rieken

LCS match

上级 d58c8124
......@@ -574,3 +574,48 @@ function computeLandmarks(word: string, lowWord: string): [string, number[]] {
return [result, positions];
}
// function print(m: number[][]) {
// for (const n of m) {
// console.log(n.join('|'));
// }
// }
export function matchesFuzzy5(pattern: string, word: string) {
// create matrix
const matrix: number[][] = [[0]];
for (let i = 1; i <= pattern.length; i++) {
matrix.push([-i]);
}
for (let i = 1; i <= word.length; i++) {
matrix[0].push(-i);
}
for (let i = 0; i < pattern.length; i++) {
let match = false;
for (let j = 0; j < word.length; j++) {
let diagScore = 0;
if (pattern[i] === word[j]) {
diagScore = 1 + matrix[i][j];
match = true;
} else {
diagScore = -1 + matrix[i][j];
}
let upScore = -1 + matrix[i][j + 1];
let leftScore = -1 + matrix[i + 1][j];
matrix[i + 1][j + 1] = Math.max(diagScore, upScore, leftScore);
}
if (!match) {
return undefined;
}
}
// print(matrix);
return [];
}
......@@ -5,7 +5,7 @@
'use strict';
import * as assert from 'assert';
import { fuzzyContiguousFilter, matchesFuzzy2, matchesFuzzy3, matchesFuzzy4 } from 'vs/base/common/filters';
import { fuzzyContiguousFilter, matchesFuzzy2, matchesFuzzy3, matchesFuzzy4, matchesFuzzy5 } from 'vs/base/common/filters';
const fuzz = require.__$__nodeRequire('fuzzaldrin-plus');
const data = <{ label: string }[]>require.__$__nodeRequire(require.toUrl('./filters.perf.data.json'));
......@@ -91,6 +91,26 @@ perfSuite('Performance - fuzzyMatch', function () {
assert.ok(count > 0);
});
test('matchesFuzzy5', function () {
matchesFuzzy5('ACGTC', 'AGTC');
const t1 = Date.now();
let count = 0;
for (const pattern of patterns) {
for (const item of data) {
if (item.label) {
const matches = matchesFuzzy5(pattern, item.label);
if (matches) {
count += 1;
}
}
}
}
console.log('matchesFuzzy5', Date.now() - t1, count);
assert.ok(count > 0);
});
test('fuzzaldrin', function () {
const t1 = Date.now();
let count = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册