fast-totree
Installation
$ npm install fast-totree --save
Usage
; let list = id:1name:'max1'parentId:0 id:2name:'max2'parentId:0 id:3name:'max3'parentId:1 id:4name:'max4'parentId:1 id:5name:'max5'parentId:2; //如果数据格式与上述一致,比较键为id、parentIdlet tree = list; //如果不一致,则重置配置文件,示例数据格式 {_id:1,name:'max',_pid:0}const config = key:'_id' pid:'_pid' chidren:'_chidren' value:'0' let tree2 = list; /* * Output: * * item 0 * item 2 * item 3 * item 1 * item 4 */
性能测试
name | 1千条 | 1万条 | 10万条 | 50万条 |
---|---|---|---|---|
fast-totree | 1ms | 15ms | 95ms | 450ms |
array-to-tree | 9ms | 溢出 | 溢出 | 溢出 |
totree | 2ms | 溢出 | 溢出 | 溢出 |
performant-array-to-tree | 1ms | 10ms | 103ms | 500ms |
list-to-tree | 26ms | 溢出 | 溢出 | 溢出 |