{"name":"short-tree","version":"2.0.0","description":"Keep a tree trimmed from longer-than-necessary branches","author":{"name":"Gustaf Räntilä"},"license":"MIT","bugs":{"url":"https://github.com/grantila/short-tree/issues"},"homepage":"https://github.com/grantila/short-tree#readme","exports":"./dist/index.js","main":"./dist/index.js","types":"./dist/index.d.ts","type":"module","sideEffects":false,"engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"build":"rimraf dist && tsc -p tsconfig.prod.json","test":"NODE_OPTIONS=--experimental-vm-modules jest --coverage","cz":"git-cz"},"repository":{"type":"git","url":"git+https://github.com/grantila/short-tree.git"},"keywords":["graph","tree","trim"],"devDependencies":{"@babel/preset-env":"^7.15.6","@babel/preset-typescript":"^7.15.0","@types/jest":"^27.0.1","@types/node":"^16.9.1","cz-conventional-changelog":"^3.1.0","jest":"^27.1.1","rimraf":"^3.0.1","typescript":"^4.4.3"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"dependencies":{"@types/bintrees":"^1.0.3","bintrees":"^1.0.2"},"jest":{"testEnvironment":"node","coverageReporters":["lcov","text","html"]},"gitHead":"16e81adb7c490eaa791cec87d5c2c62b61718f7b","_id":"short-tree@2.0.0","_nodeVersion":"14.17.6","_npmVersion":"6.14.15","dist":{"integrity":"sha512-iMtPBvS0uL9wShaRZgx59Yf59D7MezDQZnkwUofKPg1/zapO5v/qhTAa6t/oI+f/GACkWFJWZwfSjh7dMPdYww==","shasum":"f95821cd5c5a5e13991904ff3046bc57be355779","tarball":"http://registry-npm.ywwl.com/short-tree/download/short-tree-2.0.0.tgz","fileCount":5,"unpackedSize":8494,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhPvZBCRA9TVsSAnZWagAARMAP/2d9C8d5heEnAEG47IhI\npff1zNNBq7Ha/QNp9o6Zba2QJQXw+jTFBEzzVjJ7qUusW99u05e6V82DeS/C\nkNeTKReXVgYMhbK89Y27Y5KBlWN7jMpcfA3uFhT+TuiHIjVfmNqP6kY9lI2g\n0VJE9WzFanaqadip13ReQtjm7F3J6YkxFJGE8tyfyESd+l1rzKKDTUsyA/6X\nCarTKRdFj1TvMYqOLTq6tMCm67GHIWwkfEcb/fj4Zu2HUJjy0o8fy0DA4nY5\nNi4HoCzSThCDM3itZw9dCxberUgmHuDUgE4opSjgAz5VTcGeRi/epCNezGKE\nsGI0R7UhqpRylCY1m9PhjcPdu9vL0JvLzBgWaYOcv7oB16NXxG6hZnos7R07\n8Gq43yAus/jUS+U4FfmekDcCULgoXzxz+tNXveqfmdqCIiS9L7QD6BJ3YNDF\nD7WScUrJ0H0KLf4w0okDOT80lVhV12ys39x3RskE57+9i/B96/D0NKvdNkFe\nWB9nLmVz3f2Xncdq5j1voVAwkwAiQxfL+RH3T45sh/2nuUI3vaAWNekaJL0y\n1QdyI+gbgm0y2CsjG5gbpPtFwqg3jR2bNkKiXX/CCvtFuDE8BaOtXLYnh34N\npBG39C59DR6ojHVB3JYK3QKepmHKZc9LWOHEpFgAnxcn8tNvb+ISigMxjhpw\nDHBT\r\n=qE5y\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHtezvDkAUPTIhUDz7h7/WdctivSZLqnZ8PY6v8tdFgfAiEApgki2zyx/Mco4uENJKz++oalFzQBBPKFkZNvwvcJ2m8="}],"size":3639,"noattachment":false,"key":"/short-tree/-/short-tree-2.0.0.tgz"},"_npmUser":{"name":"grantila","email":"g.rantila@gmail.com"},"directories":{},"maintainers":[{"name":"grantila","email":"g.rantila@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/short-tree_2.0.0_1631516225357_0.841125974685611"},"_hasShrinkwrap":false,"readme":"[![npm version][npm-image]][npm-url]\n[![downloads][downloads-image]][npm-url]\n[![build status][build-image]][build-url]\n[![coverage status][coverage-image]][coverage-url]\n[![Node.JS version][node-version]][node-url]\n\n\n# short-tree\n\n`ShortTree` is a class extending `RBTree` from [bintrees][bintrees-npm-url], and **works explicitly on nodes of arrays**.\n\nThe `ShortTree< T >` class extends `RBTree< Array< T > >`.\n\n`insert` is overloaded and behaves differently. When adding a node, it will first check if there is another shorter node being the beginning of the to-be-inserted node, and if so, won't insert. It also checks if there are existing longer nodes which begin with the newly inserted node, and deletes them.\n\nA new function is added `values()` which returns `Array< Array< T > >`, i.e. an array of all nodes (and again, each node is an array of `T`).\n\n\n## Versions\n\n * Since v2 this is a [pure ESM][pure-esm] package, and requires Node.js >=12.20. It cannot be used from CommonJS.\n * Since v3 requires Node.js >= 14.13.1.\n\n\n# Algorithm\n\n\nWhen inserting `[ 'a', 'b', 'c', 'd' ]`, **one** node is inserted with this value.\n\nInserting  `[ 'x', 'y' ]`, will insert **one** new node.\n\nIf later, `[ 'a', 'b', 'c', 'd', 'e' ]` is inserted, it won't be - there's already a \"shorter\" version of this node (the first one inserted).\n\nIf later, `[ 'a', 'b' ]` is inserted, the first node `[ 'a', 'b', 'c', 'd' ]` will be removed (or \"chopped off\" after `b`).\n\n\n# API\n\nConstruct a `ShortTree` by giving the comparison function for `T`.\n\nIf `T` is `number` e.g., this could be `(a, b) => a - b`.\n\n\n## Order\n\nThe order when traversing the values is going to depend on the comparison function provided to the constructor.\n\nE.g. a traditional `(a: string, b: string) => a.localeCompare(b)` will ensure an order for your current locale. You can use `Intl` to define string comparison orders for other situations.\n\nIf the *human friendly* order isn't that important, but speed is critical, use [`fast-string-compare`][fast-string-compare-npm-url].\n\n\n## Example\n\n```ts\nimport { compare } from 'fast-string-compare'\nimport { ShortTree } from 'short-tree'\n\n// T is deduced to {string}\nconst tree = new ShortTree( compare );\n\ntree.insert( [ 'a', 'b', 'c', 'd' ] );\ntree.insert( [ 'x', 'y' ] );\n// This will \"chop off\" (i.e. remove) [ 'a', 'b', 'c', 'd' ]\ntree.insert( [ 'a', 'b' ] );\n\ntree.values( ); // [ [ 'a', 'b' ], [ 'x', 'y' ] ]\n```\n\n\n[npm-image]: https://img.shields.io/npm/v/short-tree.svg\n[npm-url]: https://npmjs.org/package/short-tree\n[downloads-image]: https://img.shields.io/npm/dm/short-tree.svg\n[build-image]: https://img.shields.io/github/actions/workflow/status/grantila/short-tree/master.yml?branch=master\n[build-url]: https://github.com/grantila/short-tree/actions?query=workflow%3AMaster\n[coverage-image]: https://coveralls.io/repos/github/grantila/short-tree/badge.svg?branch=master\n[coverage-url]: https://coveralls.io/github/grantila/short-tree?branch=master\n[node-version]: https://img.shields.io/node/v/short-tree\n[node-url]: https://nodejs.org/en/\n\n[bintrees-npm-url]: https://npmjs.org/package/bintrees\n[fast-string-compare-npm-url]: https://npmjs.org/package/fast-string-compare\n[pure-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n","publish_time":1631516225503,"_cnpm_publish_time":1631516225503,"dist-tags":{"latest":"3.0.0"}}