瀏覽代碼

Docsify Auto Published

willin 8 年之前
父節點
當前提交
e5761bf253

+ 1 - 0
_sidebar.md

@@ -52,6 +52,7 @@
     - [奇数求和](basic/algorithm/sum-of-odd-numbers.md)
     - [查找单数](basic/algorithm/find-the-odd-int.md)
     - [查找杂散数](basic/algorithm/find-the-stray-number.md)
+    - [无限层级目录算法](basic/algorithm/categories.md)
 - 经验篇
   - [设计](experience/design/README.md)
     - [需求分析](experience/design/requirements.md)

+ 806 - 0
basic/algorithm/_categories/test1.json

@@ -0,0 +1,806 @@
+[
+  {
+    "oid": 26,
+    "name": "test3.2.2.2",
+    "parentoid": 1162,
+    "rootoid": 47378
+  },
+  {
+    "oid": 117,
+    "name": "test3.1.1.2",
+    "parentoid": 22063,
+    "rootoid": 47378
+  },
+  {
+    "oid": 831,
+    "name": "test2.1.1.1",
+    "parentoid": 68329,
+    "rootoid": 47378
+  },
+  {
+    "oid": 948,
+    "name": "test1.1.2.2",
+    "parentoid": 62557,
+    "rootoid": 47378
+  },
+  {
+    "oid": 1162,
+    "name": "test3.2.2",
+    "parentoid": 42095,
+    "rootoid": 47378
+  },
+  {
+    "oid": 1202,
+    "name": "test1.1.1.2",
+    "parentoid": 60835,
+    "rootoid": 47378
+  },
+  {
+    "oid": 1522,
+    "name": "test3.1.2.1.1",
+    "parentoid": 4952,
+    "rootoid": 47378
+  },
+  {
+    "oid": 1608,
+    "name": "test5.1.1.1",
+    "parentoid": 40298,
+    "rootoid": 47378
+  },
+  {
+    "oid": 1775,
+    "name": "test3",
+    "parentoid": 89732,
+    "rootoid": 47378
+  },
+  {
+    "oid": 1949,
+    "name": "test4.2.2.2",
+    "parentoid": 64948,
+    "rootoid": 47378
+  },
+  {
+    "oid": 1966,
+    "name": "test1.2.2.1",
+    "parentoid": 11142,
+    "rootoid": 47378
+  },
+  {
+    "oid": 2158,
+    "name": "test1.1.1.1",
+    "parentoid": 60835,
+    "rootoid": 47378
+  },
+  {
+    "oid": 2484,
+    "name": "test3.1.2.2",
+    "parentoid": 3824,
+    "rootoid": 47378
+  },
+  {
+    "oid": 2657,
+    "name": "test3.2.1",
+    "parentoid": 42095,
+    "rootoid": 47378
+  },
+  {
+    "oid": 2939,
+    "name": "test5.1.1.2",
+    "parentoid": 40298,
+    "rootoid": 47378
+  },
+  {
+    "oid": 2956,
+    "name": "test2.2.2.1",
+    "parentoid": 75323,
+    "rootoid": 47378
+  },
+  {
+    "oid": 2972,
+    "name": "test4.1.2.1",
+    "parentoid": 65776,
+    "rootoid": 47378
+  },
+  {
+    "oid": 3355,
+    "name": "test3.2.1.1",
+    "parentoid": 2657,
+    "rootoid": 47378
+  },
+  {
+    "oid": 3490,
+    "name": "test1.2.2.2",
+    "parentoid": 11142,
+    "rootoid": 47378
+  },
+  {
+    "oid": 3602,
+    "name": "test3.2.2.1.1",
+    "parentoid": 5719,
+    "rootoid": 47378
+  },
+  {
+    "oid": 3682,
+    "name": "test3.2.1.2",
+    "parentoid": 2657,
+    "rootoid": 47378
+  },
+  {
+    "oid": 3722,
+    "name": "test4.1.2.2",
+    "parentoid": 65776,
+    "rootoid": 47378
+  },
+  {
+    "oid": 3815,
+    "name": "test2.1.2.1.1",
+    "parentoid": 9722,
+    "rootoid": 47378
+  },
+  {
+    "oid": 3824,
+    "name": "test3.1.2",
+    "parentoid": 30122,
+    "rootoid": 47378
+  },
+  {
+    "oid": 4391,
+    "name": "test4.2.2.1",
+    "parentoid": 64948,
+    "rootoid": 47378
+  },
+  {
+    "oid": 4483,
+    "name": "test3.2.2.2.1",
+    "parentoid": 26,
+    "rootoid": 47378
+  },
+  {
+    "oid": 4782,
+    "name": "test5",
+    "parentoid": 33440,
+    "rootoid": 47378
+  },
+  {
+    "oid": 4952,
+    "name": "test3.1.2.1",
+    "parentoid": 3824,
+    "rootoid": 47378
+  },
+  {
+    "oid": 4988,
+    "name": "test1.2.1.1",
+    "parentoid": 75440,
+    "rootoid": 47378
+  },
+  {
+    "oid": 5037,
+    "name": "test3.1.1.2.1",
+    "parentoid": 117,
+    "rootoid": 47378
+  },
+  {
+    "oid": 5161,
+    "name": "test2.1",
+    "parentoid": 89732,
+    "rootoid": 47378
+  },
+  {
+    "oid": 5526,
+    "name": "test1.2.2.2.1",
+    "parentoid": 3490,
+    "rootoid": 47378
+  },
+  {
+    "oid": 5719,
+    "name": "test3.2.2.1",
+    "parentoid": 1162,
+    "rootoid": 47378
+  },
+  {
+    "oid": 5732,
+    "name": "test4.2.1.1",
+    "parentoid": 7085,
+    "rootoid": 47378
+  },
+  {
+    "oid": 5892,
+    "name": "test4.2.1.2",
+    "parentoid": 7085,
+    "rootoid": 47378
+  },
+  {
+    "oid": 7085,
+    "name": "test4.2.1",
+    "parentoid": 39883,
+    "rootoid": 47378
+  },
+  {
+    "oid": 7204,
+    "name": "test1.2.1.2",
+    "parentoid": 75440,
+    "rootoid": 47378
+  },
+  {
+    "oid": 7395,
+    "name": "test2.1.1.2",
+    "parentoid": 68329,
+    "rootoid": 47378
+  },
+  {
+    "oid": 7783,
+    "name": "test4.2.1.1.2",
+    "parentoid": 5732,
+    "rootoid": 47378
+  },
+  {
+    "oid": 8460,
+    "name": "test1.1.2.1",
+    "parentoid": 62557,
+    "rootoid": 47378
+  },
+  {
+    "oid": 8486,
+    "name": "test2.1.2.2.1",
+    "parentoid": 9090,
+    "rootoid": 47378
+  },
+  {
+    "oid": 8856,
+    "name": "test2.2.1.2",
+    "parentoid": 34758,
+    "rootoid": 47378
+  },
+  {
+    "oid": 9090,
+    "name": "test2.1.2.2",
+    "parentoid": 31335,
+    "rootoid": 47378
+  },
+  {
+    "oid": 9247,
+    "name": "test2.2.2.2",
+    "parentoid": 75323,
+    "rootoid": 47378
+  },
+  {
+    "oid": 9486,
+    "name": "test3.1.1.1",
+    "parentoid": 22063,
+    "rootoid": 47378
+  },
+  {
+    "oid": 9544,
+    "name": "test4.1.1.1",
+    "parentoid": 65918,
+    "rootoid": 47378
+  },
+  {
+    "oid": 9602,
+    "name": "test4.1.1.2",
+    "parentoid": 65918,
+    "rootoid": 47378
+  },
+  {
+    "oid": 9722,
+    "name": "test2.1.2.1",
+    "parentoid": 31335,
+    "rootoid": 47378
+  },
+  {
+    "oid": 9807,
+    "name": "test2.2.1.1",
+    "parentoid": 34758,
+    "rootoid": 47378
+  },
+  {
+    "oid": 10439,
+    "name": "test2.2.2.1.2",
+    "parentoid": 2956,
+    "rootoid": 47378
+  },
+  {
+    "oid": 11085,
+    "name": "test2.1.2.1.2",
+    "parentoid": 9722,
+    "rootoid": 47378
+  },
+  {
+    "oid": 11142,
+    "name": "test1.2.2",
+    "parentoid": 77786,
+    "rootoid": 47378
+  },
+  {
+    "oid": 11846,
+    "name": "test3.2.1.1.2",
+    "parentoid": 3355,
+    "rootoid": 47378
+  },
+  {
+    "oid": 12139,
+    "name": "test1.1.1.1.1",
+    "parentoid": 2158,
+    "rootoid": 47378
+  },
+  {
+    "oid": 12877,
+    "name": "test1.1",
+    "parentoid": 47378,
+    "rootoid": 47378
+  },
+  {
+    "oid": 13228,
+    "name": "test3.2.1.1.1",
+    "parentoid": 3355,
+    "rootoid": 47378
+  },
+  {
+    "oid": 15495,
+    "name": "test4.1.2.1.2",
+    "parentoid": 2972,
+    "rootoid": 47378
+  },
+  {
+    "oid": 17793,
+    "name": "test5.1.1.1.1",
+    "parentoid": 1608,
+    "rootoid": 47378
+  },
+  {
+    "oid": 18362,
+    "name": "test4.2.2.2.1",
+    "parentoid": 1949,
+    "rootoid": 47378
+  },
+  {
+    "oid": 19056,
+    "name": "test3.1.2.1.2",
+    "parentoid": 4952,
+    "rootoid": 47378
+  },
+  {
+    "oid": 19318,
+    "name": "test2.2.1.1.1",
+    "parentoid": 9807,
+    "rootoid": 47378
+  },
+  {
+    "oid": 21963,
+    "name": "test3.1.1.1.2",
+    "parentoid": 9486,
+    "rootoid": 47378
+  },
+  {
+    "oid": 22063,
+    "name": "test3.1.1",
+    "parentoid": 30122,
+    "rootoid": 47378
+  },
+  {
+    "oid": 22075,
+    "name": "test1.2.1.1.2",
+    "parentoid": 4988,
+    "rootoid": 47378
+  },
+  {
+    "oid": 25921,
+    "name": "test2.1.1.2.1",
+    "parentoid": 7395,
+    "rootoid": 47378
+  },
+  {
+    "oid": 27828,
+    "name": "test2.2.2.1.1",
+    "parentoid": 2956,
+    "rootoid": 47378
+  },
+  {
+    "oid": 28909,
+    "name": "test4.1.2.2.2",
+    "parentoid": 3722,
+    "rootoid": 47378
+  },
+  {
+    "oid": 29812,
+    "name": "test2.1.1.1.1",
+    "parentoid": 831,
+    "rootoid": 47378
+  },
+  {
+    "oid": 30122,
+    "name": "test3.1",
+    "parentoid": 1775,
+    "rootoid": 47378
+  },
+  {
+    "oid": 31335,
+    "name": "test2.1.2",
+    "parentoid": 5161,
+    "rootoid": 47378
+  },
+  {
+    "oid": 31798,
+    "name": "test4.1.1.2.1",
+    "parentoid": 9602,
+    "rootoid": 47378
+  },
+  {
+    "oid": 32310,
+    "name": "test2.1.1.1.2",
+    "parentoid": 831,
+    "rootoid": 47378
+  },
+  {
+    "oid": 32986,
+    "name": "test3.2.2.1.2",
+    "parentoid": 5719,
+    "rootoid": 47378
+  },
+  {
+    "oid": 33008,
+    "name": "test1.2.1.2.2",
+    "parentoid": 7204,
+    "rootoid": 47378
+  },
+  {
+    "oid": 33440,
+    "name": "test4",
+    "parentoid": 1775,
+    "rootoid": 47378
+  },
+  {
+    "oid": 34758,
+    "name": "test2.2.1",
+    "parentoid": 66942,
+    "rootoid": 47378
+  },
+  {
+    "oid": 34848,
+    "name": "test1.1.2.2.1",
+    "parentoid": 948,
+    "rootoid": 47378
+  },
+  {
+    "oid": 35648,
+    "name": "test1.1.1.2.2",
+    "parentoid": 1202,
+    "rootoid": 47378
+  },
+  {
+    "oid": 36588,
+    "name": "test4.1.2.1.1",
+    "parentoid": 2972,
+    "rootoid": 47378
+  },
+  {
+    "oid": 36679,
+    "name": "test1.1.1.2.1",
+    "parentoid": 1202,
+    "rootoid": 47378
+  },
+  {
+    "oid": 39883,
+    "name": "test4.2",
+    "parentoid": 33440,
+    "rootoid": 47378
+  },
+  {
+    "oid": 40298,
+    "name": "test5.1.1",
+    "parentoid": 57008,
+    "rootoid": 47378
+  },
+  {
+    "oid": 40495,
+    "name": "test1.2.2.2.2",
+    "parentoid": 3490,
+    "rootoid": 47378
+  },
+  {
+    "oid": 42095,
+    "name": "test3.2",
+    "parentoid": 1775,
+    "rootoid": 47378
+  },
+  {
+    "oid": 44801,
+    "name": "test1.1.1.1.2",
+    "parentoid": 2158,
+    "rootoid": 47378
+  },
+  {
+    "oid": 46059,
+    "name": "test5.1.2",
+    "parentoid": 57008,
+    "rootoid": 47378
+  },
+  {
+    "oid": 46603,
+    "name": "test1.2.2.1.2",
+    "parentoid": 1966,
+    "rootoid": 47378
+  },
+  {
+    "oid": 47378,
+    "name": "test1",
+    "parentoid": 0,
+    "rootoid": 47378
+  },
+  {
+    "oid": 47964,
+    "name": "test2.2.1.2.1",
+    "parentoid": 8856,
+    "rootoid": 47378
+  },
+  {
+    "oid": 48359,
+    "name": "test2.1.1.2.2",
+    "parentoid": 7395,
+    "rootoid": 47378
+  },
+  {
+    "oid": 50390,
+    "name": "test1.2.1.1.1",
+    "parentoid": 4988,
+    "rootoid": 47378
+  },
+  {
+    "oid": 51403,
+    "name": "test4.2.1.2.1",
+    "parentoid": 5892,
+    "rootoid": 47378
+  },
+  {
+    "oid": 53136,
+    "name": "test5.1.1.1.2",
+    "parentoid": 1608,
+    "rootoid": 47378
+  },
+  {
+    "oid": 53571,
+    "name": "test4.2.1.2.2",
+    "parentoid": 5892,
+    "rootoid": 47378
+  },
+  {
+    "oid": 53750,
+    "name": "test3.2.1.2.2",
+    "parentoid": 3682,
+    "rootoid": 47378
+  },
+  {
+    "oid": 57008,
+    "name": "test5.1",
+    "parentoid": 4782,
+    "rootoid": 47378
+  },
+  {
+    "oid": 60835,
+    "name": "test1.1.1",
+    "parentoid": 12877,
+    "rootoid": 47378
+  },
+  {
+    "oid": 61491,
+    "name": "test3.1.1.2.2",
+    "parentoid": 117,
+    "rootoid": 47378
+  },
+  {
+    "oid": 62557,
+    "name": "test1.1.2",
+    "parentoid": 12877,
+    "rootoid": 47378
+  },
+  {
+    "oid": 63524,
+    "name": "test3.2.2.2.2",
+    "parentoid": 26,
+    "rootoid": 47378
+  },
+  {
+    "oid": 64144,
+    "name": "test4.1.1.2.2",
+    "parentoid": 9602,
+    "rootoid": 47378
+  },
+  {
+    "oid": 64630,
+    "name": "test2.2.2.2.1",
+    "parentoid": 9247,
+    "rootoid": 47378
+  },
+  {
+    "oid": 64727,
+    "name": "test2.2.1.2.2",
+    "parentoid": 8856,
+    "rootoid": 47378
+  },
+  {
+    "oid": 64948,
+    "name": "test4.2.2",
+    "parentoid": 39883,
+    "rootoid": 47378
+  },
+  {
+    "oid": 65416,
+    "name": "test2.2.2.2.2",
+    "parentoid": 9247,
+    "rootoid": 47378
+  },
+  {
+    "oid": 65776,
+    "name": "test4.1.2",
+    "parentoid": 83727,
+    "rootoid": 47378
+  },
+  {
+    "oid": 65918,
+    "name": "test4.1.1",
+    "parentoid": 83727,
+    "rootoid": 47378
+  },
+  {
+    "oid": 66942,
+    "name": "test2.2",
+    "parentoid": 89732,
+    "rootoid": 47378
+  },
+  {
+    "oid": 68180,
+    "name": "test4.2.2.2.2",
+    "parentoid": 1949,
+    "rootoid": 47378
+  },
+  {
+    "oid": 68239,
+    "name": "test3.1.2.2.1",
+    "parentoid": 2484,
+    "rootoid": 47378
+  },
+  {
+    "oid": 68311,
+    "name": "test4.2.2.1.1",
+    "parentoid": 4391,
+    "rootoid": 47378
+  },
+  {
+    "oid": 68329,
+    "name": "test2.1.1",
+    "parentoid": 5161,
+    "rootoid": 47378
+  },
+  {
+    "oid": 72234,
+    "name": "test3.1.2.2.2",
+    "parentoid": 2484,
+    "rootoid": 47378
+  },
+  {
+    "oid": 73691,
+    "name": "test4.1.1.1.1",
+    "parentoid": 9544,
+    "rootoid": 47378
+  },
+  {
+    "oid": 75323,
+    "name": "test2.2.2",
+    "parentoid": 66942,
+    "rootoid": 47378
+  },
+  {
+    "oid": 75440,
+    "name": "test1.2.1",
+    "parentoid": 77786,
+    "rootoid": 47378
+  },
+  {
+    "oid": 76686,
+    "name": "test3.1.1.1.1",
+    "parentoid": 9486,
+    "rootoid": 47378
+  },
+  {
+    "oid": 77786,
+    "name": "test1.2",
+    "parentoid": 47378,
+    "rootoid": 47378
+  },
+  {
+    "oid": 80170,
+    "name": "test1.2.2.1.1",
+    "parentoid": 1966,
+    "rootoid": 47378
+  },
+  {
+    "oid": 81846,
+    "name": "test1.1.2.1.1",
+    "parentoid": 8460,
+    "rootoid": 47378
+  },
+  {
+    "oid": 83212,
+    "name": "test5.1.1.2.2",
+    "parentoid": 2939,
+    "rootoid": 47378
+  },
+  {
+    "oid": 83319,
+    "name": "test1.2.1.2.1",
+    "parentoid": 7204,
+    "rootoid": 47378
+  },
+  {
+    "oid": 83727,
+    "name": "test4.1",
+    "parentoid": 33440,
+    "rootoid": 47378
+  },
+  {
+    "oid": 85731,
+    "name": "test4.2.1.1.1",
+    "parentoid": 5732,
+    "rootoid": 47378
+  },
+  {
+    "oid": 86107,
+    "name": "test2.1.2.2.2",
+    "parentoid": 9090,
+    "rootoid": 47378
+  },
+  {
+    "oid": 86207,
+    "name": "test3.2.1.2.1",
+    "parentoid": 3682,
+    "rootoid": 47378
+  },
+  {
+    "oid": 86743,
+    "name": "test2.2.1.1.2",
+    "parentoid": 9807,
+    "rootoid": 47378
+  },
+  {
+    "oid": 87048,
+    "name": "test4.1.2.2.1",
+    "parentoid": 3722,
+    "rootoid": 47378
+  },
+  {
+    "oid": 89021,
+    "name": "test4.1.1.1.2",
+    "parentoid": 9544,
+    "rootoid": 47378
+  },
+  {
+    "oid": 89732,
+    "name": "test2",
+    "parentoid": 47378,
+    "rootoid": 47378
+  },
+  {
+    "oid": 90291,
+    "name": "test1.1.2.1.2",
+    "parentoid": 8460,
+    "rootoid": 47378
+  },
+  {
+    "oid": 93713,
+    "name": "test4.2.2.1.2",
+    "parentoid": 4391,
+    "rootoid": 47378
+  },
+  {
+    "oid": 93800,
+    "name": "test1.1.2.2.2",
+    "parentoid": 948,
+    "rootoid": 47378
+  },
+  {
+    "oid": 94546,
+    "name": "test5.1.1.2.1",
+    "parentoid": 2939,
+    "rootoid": 47378
+  }
+]

+ 940 - 0
basic/algorithm/_categories/test2.json

@@ -0,0 +1,940 @@
+[
+  {
+    "oid": 35648,
+    "name": "test1.1.1.2.2",
+    "parentoid": 1202,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 36679,
+    "name": "test1.1.1.2.1",
+    "parentoid": 1202,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 1202,
+    "name": "test1.1.1.2",
+    "parentoid": 60835,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 12139,
+    "name": "test1.1.1.1.1",
+    "parentoid": 2158,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 44801,
+    "name": "test1.1.1.1.2",
+    "parentoid": 2158,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 2158,
+    "name": "test1.1.1.1",
+    "parentoid": 60835,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 60835,
+    "name": "test1.1.1",
+    "parentoid": 12877,
+    "rootoid": 47378,
+    "depth": 3
+  },
+  {
+    "oid": 34848,
+    "name": "test1.1.2.2.1",
+    "parentoid": 948,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 93800,
+    "name": "test1.1.2.2.2",
+    "parentoid": 948,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 948,
+    "name": "test1.1.2.2",
+    "parentoid": 62557,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 81846,
+    "name": "test1.1.2.1.1",
+    "parentoid": 8460,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 90291,
+    "name": "test1.1.2.1.2",
+    "parentoid": 8460,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 8460,
+    "name": "test1.1.2.1",
+    "parentoid": 62557,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 62557,
+    "name": "test1.1.2",
+    "parentoid": 12877,
+    "rootoid": 47378,
+    "depth": 3
+  },
+  {
+    "oid": 12877,
+    "name": "test1.1",
+    "parentoid": 47378,
+    "rootoid": 47378,
+    "depth": 2
+  },
+  {
+    "oid": 46603,
+    "name": "test1.2.2.1.2",
+    "parentoid": 1966,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 80170,
+    "name": "test1.2.2.1.1",
+    "parentoid": 1966,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 1966,
+    "name": "test1.2.2.1",
+    "parentoid": 11142,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 5526,
+    "name": "test1.2.2.2.1",
+    "parentoid": 3490,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 40495,
+    "name": "test1.2.2.2.2",
+    "parentoid": 3490,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 3490,
+    "name": "test1.2.2.2",
+    "parentoid": 11142,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 11142,
+    "name": "test1.2.2",
+    "parentoid": 77786,
+    "rootoid": 47378,
+    "depth": 3
+  },
+  {
+    "oid": 22075,
+    "name": "test1.2.1.1.2",
+    "parentoid": 4988,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 50390,
+    "name": "test1.2.1.1.1",
+    "parentoid": 4988,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 4988,
+    "name": "test1.2.1.1",
+    "parentoid": 75440,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 33008,
+    "name": "test1.2.1.2.2",
+    "parentoid": 7204,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 83319,
+    "name": "test1.2.1.2.1",
+    "parentoid": 7204,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 7204,
+    "name": "test1.2.1.2",
+    "parentoid": 75440,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 75440,
+    "name": "test1.2.1",
+    "parentoid": 77786,
+    "rootoid": 47378,
+    "depth": 3
+  },
+  {
+    "oid": 77786,
+    "name": "test1.2",
+    "parentoid": 47378,
+    "rootoid": 47378,
+    "depth": 2
+  },
+  {
+    "oid": 68239,
+    "name": "test3.1.2.2.1",
+    "parentoid": 2484,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 72234,
+    "name": "test3.1.2.2.2",
+    "parentoid": 2484,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 2484,
+    "name": "test3.1.2.2",
+    "parentoid": 3824,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 1522,
+    "name": "test3.1.2.1.1",
+    "parentoid": 4952,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 19056,
+    "name": "test3.1.2.1.2",
+    "parentoid": 4952,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 4952,
+    "name": "test3.1.2.1",
+    "parentoid": 3824,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 3824,
+    "name": "test3.1.2",
+    "parentoid": 30122,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 5037,
+    "name": "test3.1.1.2.1",
+    "parentoid": 117,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 61491,
+    "name": "test3.1.1.2.2",
+    "parentoid": 117,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 117,
+    "name": "test3.1.1.2",
+    "parentoid": 22063,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 21963,
+    "name": "test3.1.1.1.2",
+    "parentoid": 9486,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 76686,
+    "name": "test3.1.1.1.1",
+    "parentoid": 9486,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 9486,
+    "name": "test3.1.1.1",
+    "parentoid": 22063,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 22063,
+    "name": "test3.1.1",
+    "parentoid": 30122,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 30122,
+    "name": "test3.1",
+    "parentoid": 1775,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 17793,
+    "name": "test5.1.1.1.1",
+    "parentoid": 1608,
+    "rootoid": 47378,
+    "depth": 9
+  },
+  {
+    "oid": 53136,
+    "name": "test5.1.1.1.2",
+    "parentoid": 1608,
+    "rootoid": 47378,
+    "depth": 9
+  },
+  {
+    "oid": 1608,
+    "name": "test5.1.1.1",
+    "parentoid": 40298,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 83212,
+    "name": "test5.1.1.2.2",
+    "parentoid": 2939,
+    "rootoid": 47378,
+    "depth": 9
+  },
+  {
+    "oid": 94546,
+    "name": "test5.1.1.2.1",
+    "parentoid": 2939,
+    "rootoid": 47378,
+    "depth": 9
+  },
+  {
+    "oid": 2939,
+    "name": "test5.1.1.2",
+    "parentoid": 40298,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 40298,
+    "name": "test5.1.1",
+    "parentoid": 57008,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 46059,
+    "name": "test5.1.2",
+    "parentoid": 57008,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 57008,
+    "name": "test5.1",
+    "parentoid": 4782,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 4782,
+    "name": "test5",
+    "parentoid": 33440,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 7783,
+    "name": "test4.2.1.1.2",
+    "parentoid": 5732,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 85731,
+    "name": "test4.2.1.1.1",
+    "parentoid": 5732,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 5732,
+    "name": "test4.2.1.1",
+    "parentoid": 7085,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 51403,
+    "name": "test4.2.1.2.1",
+    "parentoid": 5892,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 53571,
+    "name": "test4.2.1.2.2",
+    "parentoid": 5892,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 5892,
+    "name": "test4.2.1.2",
+    "parentoid": 7085,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 7085,
+    "name": "test4.2.1",
+    "parentoid": 39883,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 18362,
+    "name": "test4.2.2.2.1",
+    "parentoid": 1949,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 68180,
+    "name": "test4.2.2.2.2",
+    "parentoid": 1949,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 1949,
+    "name": "test4.2.2.2",
+    "parentoid": 64948,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 68311,
+    "name": "test4.2.2.1.1",
+    "parentoid": 4391,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 93713,
+    "name": "test4.2.2.1.2",
+    "parentoid": 4391,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 4391,
+    "name": "test4.2.2.1",
+    "parentoid": 64948,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 64948,
+    "name": "test4.2.2",
+    "parentoid": 39883,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 39883,
+    "name": "test4.2",
+    "parentoid": 33440,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 15495,
+    "name": "test4.1.2.1.2",
+    "parentoid": 2972,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 36588,
+    "name": "test4.1.2.1.1",
+    "parentoid": 2972,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 2972,
+    "name": "test4.1.2.1",
+    "parentoid": 65776,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 28909,
+    "name": "test4.1.2.2.2",
+    "parentoid": 3722,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 87048,
+    "name": "test4.1.2.2.1",
+    "parentoid": 3722,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 3722,
+    "name": "test4.1.2.2",
+    "parentoid": 65776,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 65776,
+    "name": "test4.1.2",
+    "parentoid": 83727,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 73691,
+    "name": "test4.1.1.1.1",
+    "parentoid": 9544,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 89021,
+    "name": "test4.1.1.1.2",
+    "parentoid": 9544,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 9544,
+    "name": "test4.1.1.1",
+    "parentoid": 65918,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 31798,
+    "name": "test4.1.1.2.1",
+    "parentoid": 9602,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 64144,
+    "name": "test4.1.1.2.2",
+    "parentoid": 9602,
+    "rootoid": 47378,
+    "depth": 8
+  },
+  {
+    "oid": 9602,
+    "name": "test4.1.1.2",
+    "parentoid": 65918,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 65918,
+    "name": "test4.1.1",
+    "parentoid": 83727,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 83727,
+    "name": "test4.1",
+    "parentoid": 33440,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 33440,
+    "name": "test4",
+    "parentoid": 1775,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 4483,
+    "name": "test3.2.2.2.1",
+    "parentoid": 26,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 63524,
+    "name": "test3.2.2.2.2",
+    "parentoid": 26,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 26,
+    "name": "test3.2.2.2",
+    "parentoid": 1162,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 3602,
+    "name": "test3.2.2.1.1",
+    "parentoid": 5719,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 32986,
+    "name": "test3.2.2.1.2",
+    "parentoid": 5719,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 5719,
+    "name": "test3.2.2.1",
+    "parentoid": 1162,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 1162,
+    "name": "test3.2.2",
+    "parentoid": 42095,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 11846,
+    "name": "test3.2.1.1.2",
+    "parentoid": 3355,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 13228,
+    "name": "test3.2.1.1.1",
+    "parentoid": 3355,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 3355,
+    "name": "test3.2.1.1",
+    "parentoid": 2657,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 53750,
+    "name": "test3.2.1.2.2",
+    "parentoid": 3682,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 86207,
+    "name": "test3.2.1.2.1",
+    "parentoid": 3682,
+    "rootoid": 47378,
+    "depth": 7
+  },
+  {
+    "oid": 3682,
+    "name": "test3.2.1.2",
+    "parentoid": 2657,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 2657,
+    "name": "test3.2.1",
+    "parentoid": 42095,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 42095,
+    "name": "test3.2",
+    "parentoid": 1775,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 1775,
+    "name": "test3",
+    "parentoid": 89732,
+    "rootoid": 47378,
+    "depth": 3
+  },
+  {
+    "oid": 8486,
+    "name": "test2.1.2.2.1",
+    "parentoid": 9090,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 86107,
+    "name": "test2.1.2.2.2",
+    "parentoid": 9090,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 9090,
+    "name": "test2.1.2.2",
+    "parentoid": 31335,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 3815,
+    "name": "test2.1.2.1.1",
+    "parentoid": 9722,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 11085,
+    "name": "test2.1.2.1.2",
+    "parentoid": 9722,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 9722,
+    "name": "test2.1.2.1",
+    "parentoid": 31335,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 31335,
+    "name": "test2.1.2",
+    "parentoid": 5161,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 29812,
+    "name": "test2.1.1.1.1",
+    "parentoid": 831,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 32310,
+    "name": "test2.1.1.1.2",
+    "parentoid": 831,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 831,
+    "name": "test2.1.1.1",
+    "parentoid": 68329,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 25921,
+    "name": "test2.1.1.2.1",
+    "parentoid": 7395,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 48359,
+    "name": "test2.1.1.2.2",
+    "parentoid": 7395,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 7395,
+    "name": "test2.1.1.2",
+    "parentoid": 68329,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 68329,
+    "name": "test2.1.1",
+    "parentoid": 5161,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 5161,
+    "name": "test2.1",
+    "parentoid": 89732,
+    "rootoid": 47378,
+    "depth": 3
+  },
+  {
+    "oid": 47964,
+    "name": "test2.2.1.2.1",
+    "parentoid": 8856,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 64727,
+    "name": "test2.2.1.2.2",
+    "parentoid": 8856,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 8856,
+    "name": "test2.2.1.2",
+    "parentoid": 34758,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 19318,
+    "name": "test2.2.1.1.1",
+    "parentoid": 9807,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 86743,
+    "name": "test2.2.1.1.2",
+    "parentoid": 9807,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 9807,
+    "name": "test2.2.1.1",
+    "parentoid": 34758,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 34758,
+    "name": "test2.2.1",
+    "parentoid": 66942,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 10439,
+    "name": "test2.2.2.1.2",
+    "parentoid": 2956,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 27828,
+    "name": "test2.2.2.1.1",
+    "parentoid": 2956,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 2956,
+    "name": "test2.2.2.1",
+    "parentoid": 75323,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 64630,
+    "name": "test2.2.2.2.1",
+    "parentoid": 9247,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 65416,
+    "name": "test2.2.2.2.2",
+    "parentoid": 9247,
+    "rootoid": 47378,
+    "depth": 6
+  },
+  {
+    "oid": 9247,
+    "name": "test2.2.2.2",
+    "parentoid": 75323,
+    "rootoid": 47378,
+    "depth": 5
+  },
+  {
+    "oid": 75323,
+    "name": "test2.2.2",
+    "parentoid": 66942,
+    "rootoid": 47378,
+    "depth": 4
+  },
+  {
+    "oid": 66942,
+    "name": "test2.2",
+    "parentoid": 89732,
+    "rootoid": 47378,
+    "depth": 3
+  },
+  {
+    "oid": 89732,
+    "name": "test2",
+    "parentoid": 47378,
+    "rootoid": 47378,
+    "depth": 2
+  },
+  {
+    "oid": 47378,
+    "name": "test1",
+    "parentoid": 0,
+    "rootoid": 47378,
+    "depth": 1
+  }
+]

File diff suppressed because it is too large
+ 1005 - 0
basic/algorithm/_categories/tree1.json


File diff suppressed because it is too large
+ 1139 - 0
basic/algorithm/_categories/tree2.json


+ 114 - 0
basic/algorithm/categories.md

@@ -0,0 +1,114 @@
+# 无限层级目录算法
+
+# 设计1
+
+核心字段
+
+Column | Desc
+--- | ---
+oid | 组织id
+name | 组织名称
+parentoid | 上级组织id
+rootoid | 根组织id
+
+测试数据, 一个复杂组织目录(根据 `oid = 47378` 查出):
+
+<a href="/basic/algorithm/_categories/test1.json" target="_blank">test1.json</a>
+
+## 树形结构生成
+
+期望结果:
+
+<a href="/basic/algorithm/_categories/tree1.json" target="_blank">tree1.json</a>
+
+递归方法:
+
+```js
+// 将测试数据保存
+const orgs = require('./test1.json');
+
+// 递归
+const loop = (list, oid, isRoot = true) => {
+  const c = list.filter(x => oid === (isRoot ? x.oid : x.parentoid)).map((x) => {
+    // 问题1: 每次都将数组完整传入遍历
+    x.children = loop(list, x.oid, false);
+    return x;
+  });
+  // 问题2: 循环次数最多 n^n 次
+  return c;
+};
+
+console.log(JSON.stringify(loop(orgs, 47378), null, 2));
+```
+
+# 设计2
+
+核心字段
+
+Column | Desc
+--- | ---
+oid | 组织id
+name | 组织名称
+parentoid | 上级组织id
+rootoid | 根组织id
+depth | 层级深度
+
+测试数据, 一个复杂组织目录(根据 `oid = 47378` 查出):
+
+<a href="/basic/algorithm/categories/test2.json" target="_blank">test2.json</a>
+
+## 树形结构生成
+
+期望结果:
+
+<a href="/basic/algorithm/categories/tree2.json" target="_blank">tree2.json</a>
+
+循环算法:
+
+```js
+// 将测试数据保存
+const orgs = require('./test2.json');
+
+const loop = (list) => {
+  const sorted = list.sort((x, y) => x.depth < y.depth ? 1 : -1);
+  // 计算深度
+  const depth = sorted[0].depth;
+  const items = {};
+  // 分级遍历, 问题1: 空间复杂度
+  for (let i = 1; i <= depth; i += 1) {
+    items[i] = list.filter(x => x.depth === i);  
+  }
+  // 循环自下而上遍历
+  for (let i = depth; i > 1; i -= 1) {
+    items[i] = items[i].forEach(x => {
+      const parentNode = items[i - 1].findIndex(y => y.oid === x.parentoid);
+      items[i - 1][parentNode].children = (items[i - 1][parentNode].children || [] ).concat(x);
+    });
+  }
+  // 循环次数: CN(Depth)
+  return items[1];
+};
+
+console.log(JSON.stringify(loop(orgs), null, 2));
+```
+
+# BenchMark
+
+使用`matcha`进行性能测试
+
+```js
+suite('Categories', function () {
+  bench('test 1', function() {
+    loop1(orgs1, 47378);
+  });
+  bench('test 2', function() {
+    loop2(orgs2);
+  });
+});
+```
+
+```
+                     Categories
+           2,620 op/s » test 1
+             531 op/s » test 2
+```