0
|
1 /* user defined */
|
|
2 DataSegment tree {
|
|
3 DataSegment tree first;
|
|
4 DataSegment tree second;
|
|
5 int v;
|
|
6 };
|
|
7 /* replace above to below. */
|
|
8 typedef int32_t DS_offset;
|
|
9 struct tree {
|
|
10 /* system defined. */
|
|
11 struct {
|
|
12 int allocated_size;
|
|
13 int size;
|
|
14 DS_offset parent;
|
|
15 }
|
|
16 /* user defined. */
|
|
17 DS_offset first;
|
|
18 DS_offset second;
|
|
19 void *v;
|
|
20 }
|
|
21
|
|
22 tree a = new tree();
|
|
23 newDS(type) {
|
|
24 data = malloc(defaultsize);
|
|
25 data->allocated_size = defaultsize;
|
|
26 data->size = sizeof(type);
|
|
27 data->parent = 0;
|
|
28 return data;
|
|
29 }
|
|
30
|
|
31 a->first = othertree; // 完全にコピーされる
|
|
32 // 次のように扱われる
|
|
33 copyDS(DS a, field fld, DS othertree) {
|
|
34 DS top;
|
|
35 top = a;
|
|
36 while (top->parent!=0) {
|
|
37 top = top + top->parent;
|
|
38 }
|
|
39
|
|
40 DS newspace;
|
|
41 //if (top->allocated_size < top->size + othertree->size) realloc();
|
|
42 newspace = top + top->size;
|
|
43 top->size += othertree->size;
|
|
44
|
|
45 memcpy(newspace, othertree, othertree->size);
|
|
46 a->fld = newspace - a;
|
|
47 newspace->parent = a - newspace;
|
|
48 }
|
|
49
|
|
50 *(a->first);
|
|
51 *(a + a->first);
|
|
52
|
|
53 //deleteはできない
|
|
54
|
|
55
|
|
56
|
|
57
|
|
58 #if 0
|
|
59
|
|
60 class DS_offset {
|
|
61 uint32_t offset;
|
|
62 }
|
|
63 /* */
|
|
64 class DataSegmentBase {
|
|
65 int allocated_size;
|
|
66 int size;
|
|
67 DS_offset parent;
|
|
68 };
|
|
69
|
|
70 DataSegment tree {
|
|
71 DataSegment tree first;
|
|
72 DataSegment tree second;
|
|
73 int v;
|
|
74 };
|
|
75 class tree : DataSegmentBase {
|
|
76 DS_offset first;
|
|
77 DS_offset second;
|
|
78 int v;
|
|
79 };
|
|
80
|
|
81 DataSegmentBase::operator new() {
|
|
82 }
|
|
83 DS_offset::operator =(DataSegmentBase ) {
|
|
84 }
|
|
85 #endif
|
|
86
|
|
87 /*
|
|
88 * -------------------------------------
|
|
89 * | Sfsv|first|second| |
|
|
90 * -------------------------------------
|
|
91 *
|
|
92 */
|
|
93 void
|
|
94 main() {
|
|
95 DataSegment tree a = new DataSegment tree;
|
|
96 a->first = null;
|
|
97 a->second = null;
|
|
98 a->v = "aiueo";
|
|
99
|
|
100 DataSegment tree top = new DataSegment tree;
|
|
101 a->first = a;
|
|
102 //a->first = new DataSegment tree;
|
|
103
|
|
104 a->first->first = new DataSegment tree;
|
|
105 }
|
|
106
|
|
107
|
|
108
|
|
109
|