Socket
Socket
Sign inDemoInstall

performant-array-to-tree

Package Overview
Dependencies
0
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

2

package.json
{
"name": "performant-array-to-tree",
"version": "1.0.2",
"version": "1.0.3",
"description": "Converts an array of items with ids and parent ids to a nested tree in a performant `O(n)` way. Runs in browsers and node.",

@@ -5,0 +5,0 @@ "main": "build/arrayToTree.min.js",

@@ -13,13 +13,12 @@ # Performant array to tree

Converts an array of items with ids and parent ids to a nested tree in a performant `O(n)` way. Runs in browsers and node.
Converts an array of items with ids and parent ids to a nested tree in a performant way (time complexity `O(n)`). Runs in browsers and node.
## Why another package
Other packages have stricter assumptions or are not as performant, as they often use multiple loops or recursion. For example:
Other packages have stricter assumptions or are not as performant, as they often use nested loops or recursion. For example:
[o-unflatten](https://www.npmjs.com/package/o-unflatten) requires the input to be ordered such that parent nodes always come before their children.
[array-to-tree](https://www.npmjs.com/package/array-to-tree) uses two loops (runs with `O(2n)`), one for grouping all items by their parents, and one for creating the tree.
[un-flatten-tree](https://www.npmjs.com/package/un-flatten-tree) uses 2 nested loops (runs even worse with `O(n^2)`).
[un-flatten-tree](https://www.npmjs.com/package/un-flatten-tree) uses 2 nested loops (time complexity `O(n^2)`).
This implementation does not require any order of items in the input array and focuses on runtime performance. By only using a single loop (runs with `O(n)`). It was inspired by [this discussion](http://stackoverflow.com/questions/444296/how-to-efficiently-build-a-tree-from-a-flat-structure) on StackOverflow.
This implementation does not require any order of items in the input array and focuses on runtime performance. It uses an index and a single loop (time complexity `O(n)`). It was inspired by [this discussion](http://stackoverflow.com/questions/444296/how-to-efficiently-build-a-tree-from-a-flat-structure) on StackOverflow.

@@ -26,0 +25,0 @@ ## Installation

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc