comparison list.rhope @ 70:1bfcf5f8fa69

Beginning of List implementation
author Mike Pavone <pavone@retrodev.com>
date Wed, 16 Jun 2010 04:36:53 +0000
parents
children 0083b2f7b3c7
comparison
equal deleted inserted replaced
69:d0ce696786cc 70:1bfcf5f8fa69
1
2 Blueprint List Leaf
3 {
4 Buffer
5 }
6
7 Index@List Leaf[list,index:out,not found]
8 {
9 out, not found <- [[list]Buffer >>]Index[index]
10 }
11
12 Set@List Leaf[list,index,value:out]
13 {
14 If[[index] < [0]]
15 {
16 }{
17 If[[index] > [[[list]Buffer >>]Length >>]]
18 {
19 makeleft <- Yes
20 }{
21 If[[index] > [7]]
22 {
23 makeleft <- Yes
24 }{
25 out <- [list]Buffer <<[ [[list]Buffer >>]Set[index, value] ]
26 }
27 }
28 }
29
30 Val[makeleft]
31 {
32 out <- [[[[[[Build[List()]
33 ]Buffer << [[Array[]]Append[value]]
34 ]Left << [list]
35 ]Right << [List[]]
36 ]Offset << [index]
37 ]Right Offset <<[[index]+[8i32]]
38 ]Length << [ [[list]Length]+[1] ]
39 }
40 }
41
42 Blueprint List
43 {
44 Buffer
45 Left
46 Right
47 Offset(Int32,Naked)
48 Right Offset(Int32,Naked)
49 Length(Int32,Naked)
50 }
51
52 List[:out(List)]
53 {
54 out <- [Build[List Leaf()]]Buffer <<[Array[]]
55 }
56
57 Index@List[list,index:out,not found]
58 {
59 If[[index]<[[list]Offset >>]]
60 {
61 out, not found <- [[list]Left >>]Index[index]
62 }{
63 If[[index] < [[list]Right Offset >>]]
64 {
65 out, not found <- [[list]Buffer >>]Index[[index]-[[list]Offset >>]]
66 }{
67 out, not found <- [[list]Right >>]Index[[index]-[[list]Right Offset >>]]
68 }
69 }
70 }
71
72 Set@List[list,index,val:out,not found]
73 {
74
75 }
76
77
78