Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,102 @@
|
|||
We create a binary tree from a random array, then we walk the canopy.
|
||||
|
||||
1) three functions for readability:
|
||||
|
||||
{def BT.data {lambda {:t} {A.get 0 :t}}} -> BT.data
|
||||
{def BT.left {lambda {:t} {A.get 1 :t}}} -> BT.left
|
||||
{def BT.right {lambda {:t} {A.get 2 :t}}} -> BT.right
|
||||
|
||||
2) adding a leaf to the tree:
|
||||
|
||||
{def BT.add {lambda {:x :t}
|
||||
{if {A.empty? :t}
|
||||
then {A.new :x {A.new} {A.new}}
|
||||
else {if {= :x {BT.data :t}}
|
||||
then :t
|
||||
else {if {< :x {BT.data :t}}
|
||||
then {A.new {BT.data :t}
|
||||
{BT.add :x {BT.left :t}}
|
||||
{BT.right :t}}
|
||||
else {A.new {BT.data :t}
|
||||
{BT.left :t}
|
||||
{BT.add :x {BT.right :t}} }}}}}}
|
||||
-> BT.add
|
||||
|
||||
3) creating the tree from an array of numbers:
|
||||
|
||||
{def BT.create
|
||||
{def BT.create.rec
|
||||
{lambda {:l :t}
|
||||
{if {A.empty? :l}
|
||||
then :t
|
||||
else {BT.create.rec {A.rest :l}
|
||||
{BT.add {A.first :l} :t}} }}}
|
||||
{lambda {:l}
|
||||
{BT.create.rec :l {A.new}} }}
|
||||
-> BT.create
|
||||
|
||||
4) walking the canopy -> sorting in increasing order:
|
||||
|
||||
{def BT.sort
|
||||
{lambda {:t}
|
||||
{if {A.empty? :t}
|
||||
then else {BT.sort {BT.left :t}}
|
||||
{BT.data :t}
|
||||
{BT.sort {BT.right :t}} }}}
|
||||
-> BT.sort
|
||||
|
||||
Testing
|
||||
|
||||
1) generating random numbers:
|
||||
|
||||
{def L {A.new
|
||||
{S.map {lambda {:n} {floor {* {random} 100000}}} {S.serie 1 100}}}}
|
||||
-> L = [1850,7963,50540,92667,72892,47361,19018,40640,10126,80235,48407,51623,63597,71675,27814,63478,18985,88032,46585,85209,
|
||||
74053,95005,27592,9575,22162,35904,70467,38527,89715,36594,54309,39950,89345,72224,7772,65756,68766,43942,52422,85144,
|
||||
66010,38961,21647,53194,72166,33545,49037,23218,27969,83566,19382,53120,55291,77374,27502,66648,99637,37322,9815,432,90565,
|
||||
37831,26503,99232,87024,65625,75155,55382,30120,58117,70031,13011,81375,10490,39786,1926,71311,4213,55183,2583,22075,90411,
|
||||
92928,61120,94259,433,93332,88423,64119,40850,94318,27816,84818,90632,5094,36696,94705,50602,45818,61365]
|
||||
|
||||
2) creating the tree is the main work:
|
||||
|
||||
{def T {BT.create {L}}}
|
||||
-> T = [1850,[432,],[433,],]]],[7963,[7772,[1926,],[4213,[2583,],]],[5094,],]]]],]],[50540,[47361,[19018,[10126,[9575,],
|
||||
[9815,],]]],[18985,[13011,[10490,],]],]],]]],[40640,[27814,[27592,[22162,[21647,[19382,],]],[22075,],]]],[23218,],
|
||||
[27502,[26503,],]],]]]],]],[35904,[33545,[27969,[27816,],]],[30120,],]]],]],[38527,[36594,],[37322,[36696,],]],[37831,],]]]],
|
||||
[39950,[38961,],[39786,],]]],]]]]],[46585,[43942,[40850,],]],[45818,],]]],]]]],[48407,],[49037,],]]]],[92667,[72892,
|
||||
[51623,[50602,],]],[63597,[63478,[54309,[52422,],[53194,[53120,],]],]]],[55291,[55183,],]],[55382,],[58117,],[61120,],[61365,],]]]]]]],]],[71675,[70467,[65756,[65625,[64119,],]],]],[68766,[66010,],[66648,],]]],[70031,],]]]],[71311,],]]],
|
||||
[72224,[72166,],]],]]]]],[80235,[74053,],[77374,[75155,],]],]]],[88032,[85209,[85144,[83566,[81375,],]],[84818,],]]],]],
|
||||
[87024,],]]],[89715,[89345,[88423,],]],]],[90565,[90411,],]],[90632,],]]]]]]],[95005,[92928,],[94259,[93332,],]],[94318,],
|
||||
[94705,],]]]]],[99637,[99232,],]],]]]]]]]
|
||||
|
||||
3) walking the canopy is fast:
|
||||
|
||||
{BT.sort {T}}
|
||||
-> 432 433 1850 1926 2583 4213 5094 7772 7963 9575 9815 10126 10490 13011 18985 19018 19382 21647 22075 22162 23218 26503
|
||||
27502 27592 27814 27816 27969 30120 33545 35904 36594 36696 37322 37831 38527 38961 39786 39950 40640 40850 43942 45818
|
||||
46585 47361 48407 49037 50540 50602 51623 52422 53120 53194 54309 55183 55291 55382 58117 61120 61365 63478 63597 64119
|
||||
65625 65756 66010 66648 68766 70031 70467 71311 71675 72166 72224 72892 74053 75155 77374 80235 81375 83566 84818 85144
|
||||
85209 87024 88032 88423 89345 89715 90411 90565 90632 92667 92928 93332 94259 94318 94705 95005 99232 99637
|
||||
|
||||
4) walking with new leaves is fast:
|
||||
|
||||
{BT.sort {BT.add -1 {T}}}
|
||||
-> -1 432 433 1850 1926 2583 4213 5094 7772 7963 9575 9815 10126 10490 13011 18985 19018 19382 21647 22075 22162 23218 26503
|
||||
27502 27592 27814 27816 27969 30120 33545 35904 36594 36696 37322 37831 38527 38961 39786 39950 40640 40850 43942 45818 46585
|
||||
47361 48407 49037 50540 50602 51623 52422 53120 53194 54309 55183 55291 55382 58117 61120 61365 63478 63597 64119 65625 65756
|
||||
66010 66648 68766 70031 70467 71311 71675 72166 72224 72892 74053 75155 77374 80235 81375 83566 84818 85144 85209 87024 88032
|
||||
88423 89345 89715 90411 90565 90632 92667 92928 93332 94259 94318 94705 95005 99232 99637
|
||||
|
||||
{BT.sort {BT.add 50000 {T}}}
|
||||
-> 432 433 1850 1926 2583 4213 5094 7772 7963 9575 9815 10126 10490 13011 18985 19018 19382 21647 22075 22162 23218 26503
|
||||
27502 27592 27814 27816 27969 30120 33545 35904 36594 36696 37322 37831 38527 38961 39786 39950 40640 40850 43942 45818 46585
|
||||
47361 48407 49037 50000 50540 50602 51623 52422 53120 53194 54309 55183 55291 55382 58117 61120 61365 63478 63597 64119 65625
|
||||
65756 66010 66648 68766 70031 70467 71311 71675 72166 72224 72892 74053 75155 77374 80235 81375 83566 84818 85144 85209 87024
|
||||
88032 88423 89345 89715 90411 90565 90632 92667 92928 93332 94259 94318 94705 95005 99232 99637
|
||||
|
||||
{BT.sort {BT.add 100000 {T}}}
|
||||
-> 432 433 1850 1926 2583 4213 5094 7772 7963 9575 9815 10126 10490 13011 18985 19018 19382 21647 22075 22162 23218 26503
|
||||
27502 27592 27814 27816 27969 30120 33545 35904 36594 36696 37322 37831 38527 38961 39786 39950 40640 40850 43942 45818 46585
|
||||
47361 48407 49037 50540 50602 51623 52422 53120 53194 54309 55183 55291 55382 58117 61120 61365 63478 63597 64119 65625 65756
|
||||
66010 66648 68766 70031 70467 71311 71675 72166 72224 72892 74053 75155 77374 80235 81375 83566 84818 85144 85209 87024 88032
|
||||
88423 89345 89715 90411 90565 90632 92667 92928 93332 94259 94318 94705 95005 99232 99637 100000
|
||||
Loading…
Add table
Add a link
Reference in a new issue