npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@edit-distance/myers-1986

v1.1.0

Published

Reasonably efficient and concise exact longest common subsequence and minimum edit-distance algorithm implementation for JavaScript

Downloads

24

Readme

:abacus: @edit-distance/myers-1986

Reasonably efficient implementation of Eugene W. Myers's exact longest common subsequence and minimum edit-distance algorithm for JavaScript. See docs.

:building_construction: Caveat emptor! This is work in progress. Code may be working. Documentation may be present. Coherence may be. Maybe.

:warning: Only signed 32-bit integers are supported for MAX, xi, xj, yi, yj. This is also true for the values xj - xi and yj - yi but is not enforced. You should be fine if the elements of each pair have the same sign. This means you cannot diff things with more than 2,147,483,647 parts (array elements, string characters, text words or lines).

// Example 1: compute Edit Distance.

import {makeScan, twoWay} from '@edit-distance/myers-1986';

const scan = makeScan(twoWay);

const ed = (x, y) => {
	const eq = (xi, yi) => x[xi] === y[yi];
	const xi = 0;
	const xj = x.length;
	const yi = 0;
	const yj = y.length;
	const MAX = xj - xi + (yj - yi);
	return scan(MAX, eq, xi, xj, yi, yj);
};

ed('BANANA', 'ATANA'); // 3

// Example 2: compute LCS.

import {diff} from '@edit-distance/myers-1986';

const rectangles = (x, y) => {
	const eq = (xi, yi) => x[xi] === y[yi];
	const xi = 0;
	const xj = x.length;
	const yi = 0;
	const yj = y.length;
	const MAX = xj - xi + (yj - yi);
	return diff(MAX, eq, xi, xj, yi, yj);
};

const lcs = (x, y) => {
	let result = x.slice(0, 0);
	let xp = 0;
	for (const [x0, x1] of rectangles(x, y)) {
		result = result.concat(x.slice(xp, x0));
		xp = x1;
	}

	return result.concat(x.slice(xp, x.length));
};

lcs('BANANA', 'ATANA'); // AANA

License Version Tests Dependencies Dev dependencies GitHub issues Downloads

Code issues Code maintainability Code coverage (cov) Code technical debt Documentation Package size

:bicyclist: Benchmark

| input | fast-myers-diff v3.0.1 | modern.js v0.0.1 | module.js v0.0.1 | cjs v0.0.1 | | --------------------------------------------------- | ---------------------: | ----------------: | ----------------: | -----------------: | | N+M=220 N=100 M=120 LCS=100 DEL=0 INS=20 | 77,170 ops/sec | 99,952 ops/sec | 97,806 ops/sec | 100,333 ops/sec | | N+M=220 N=120 M=100 LCS=100 DEL=20 INS=0 | 68,575 ops/sec | 90,582 ops/sec | 89,178 ops/sec | 90,030 ops/sec | | N+M=220 N=110 M=110 LCS=100 DEL=10 INS=10 | 63,494 ops/sec | 83,439 ops/sec | 81,201 ops/sec | 82,661 ops/sec | | N+M=224 N=14 M=210 LCS=10 DEL=4 INS=200 | 7,112 ops/sec | 10,346 ops/sec | 10,406 ops/sec | 10,898 ops/sec | | N+M=20020 N=10000 M=10020 LCS=10000 DEL=0 INS=20 | 3,282 ops/sec | 4,313 ops/sec | 4,174 ops/sec | 4,415 ops/sec | | N+M=20020 N=10020 M=10000 LCS=10000 DEL=20 INS=0 | 3,317 ops/sec | 4,040 ops/sec | 4,035 ops/sec | 4,947 ops/sec | | N+M=20020 N=10010 M=10010 LCS=10000 DEL=10 INS=10 | 2,414 ops/sec | 2,939 ops/sec | 2,843 ops/sec | 3,009 ops/sec | | N+M=220 N=110 M=110 LCS=10 DEL=100 INS=100 | 1,607 ops/sec | 2,737 ops/sec | 2,720 ops/sec | 2,887 ops/sec | | N+M=20200 N=10000 M=10200 LCS=10000 DEL=0 INS=200 | 871 ops/sec | 1,258 ops/sec | 1,254 ops/sec | 1,293 ops/sec | | N+M=20200 N=10200 M=10000 LCS=10000 DEL=200 INS=0 | 844 ops/sec | 1,240 ops/sec | 1,258 ops/sec | 1,309 ops/sec | | N+M=20200 N=10100 M=10100 LCS=10000 DEL=100 INS=100 | 703 ops/sec | 978 ops/sec | 976 ops/sec | 978 ops/sec | | N+M=2020 N=1010 M=1010 LCS=10 DEL=1000 INS=1000 | 19.10 ops/sec | 36.35 ops/sec | 36.45 ops/sec | 38.16 ops/sec |