|
17 | 17 | // that the UnixFS node.
|
18 | 18 | //
|
19 | 19 | // Notes:
|
20 |
| -// 1. In the implementation. `FSNodeOverDag` structure is used for representing |
21 |
| -// the UnixFS node encoded inside the DAG node. |
22 |
| -// (see https://github.com/ipfs/go-ipfs/pull/5118.) |
23 |
| -// 2. `TFile` is used for backwards-compatibility. It was a bug causing the leaf |
24 |
| -// nodes to be generated with this type instead of `TRaw`. The former one |
25 |
| -// should be used (like the trickle builder does). |
26 |
| -// (See https://github.com/ipfs/go-ipfs/pull/5120.) |
27 | 20 | //
|
28 |
| -// +-------------+ |
29 |
| -// | Root 4 | |
30 |
| -// +-------------+ |
31 |
| -// | |
32 |
| -// +--------------------------+----------------------------+ |
33 |
| -// | | |
34 |
| -// +-------------+ +-------------+ |
35 |
| -// | Node 2 | | Node 5 | |
36 |
| -// +-------------+ +-------------+ |
37 |
| -// | | |
38 |
| -// +-------------+-------------+ +-------------+ |
39 |
| -// | | | |
40 |
| -// +-------------+ +-------------+ +-------------+ |
41 |
| -// | Node 1 | | Node 3 | | Node 6 | |
42 |
| -// +-------------+ +-------------+ +-------------+ |
43 |
| -// | | | |
44 |
| -// +------+------+ +------+------+ +------+ |
45 |
| -// | | | | | |
46 |
| -// +=========+ +=========+ +=========+ +=========+ +=========+ |
47 |
| -// | Chunk 1 | | Chunk 2 | | Chunk 3 | | Chunk 4 | | Chunk 5 | |
48 |
| -// +=========+ +=========+ +=========+ +=========+ +=========+ |
| 21 | +// 1. In the implementation. `FSNodeOverDag` structure is used for representing |
| 22 | +// the UnixFS node encoded inside the DAG node. |
| 23 | +// (see https://github.com/ipfs/go-ipfs/pull/5118.) |
49 | 24 | //
|
| 25 | +// 2. `TFile` is used for backwards-compatibility. It was a bug causing the leaf |
| 26 | +// nodes to be generated with this type instead of `TRaw`. The former one |
| 27 | +// should be used (like the trickle builder does). |
| 28 | +// (See https://github.com/ipfs/go-ipfs/pull/5120.) |
| 29 | +// |
| 30 | +// +-------------+ |
| 31 | +// | Root 4 | |
| 32 | +// +-------------+ |
| 33 | +// | |
| 34 | +// +--------------------------+----------------------------+ |
| 35 | +// | | |
| 36 | +// +-------------+ +-------------+ |
| 37 | +// | Node 2 | | Node 5 | |
| 38 | +// +-------------+ +-------------+ |
| 39 | +// | | |
| 40 | +// +-------------+-------------+ +-------------+ |
| 41 | +// | | | |
| 42 | +// +-------------+ +-------------+ +-------------+ |
| 43 | +// | Node 1 | | Node 3 | | Node 6 | |
| 44 | +// +-------------+ +-------------+ +-------------+ |
| 45 | +// | | | |
| 46 | +// +------+------+ +------+------+ +------+ |
| 47 | +// | | | | | |
| 48 | +// +=========+ +=========+ +=========+ +=========+ +=========+ |
| 49 | +// | Chunk 1 | | Chunk 2 | | Chunk 3 | | Chunk 4 | | Chunk 5 | |
| 50 | +// +=========+ +=========+ +=========+ +=========+ +=========+ |
50 | 51 | package balanced
|
51 | 52 |
|
52 | 53 | import (
|
@@ -80,55 +81,54 @@ import (
|
80 | 81 | // offset in the file the graph represents: each internal node uses the file size
|
81 | 82 | // of its children as an index when seeking.
|
82 | 83 | //
|
83 |
| -// `Layout` creates a root and hands it off to be filled: |
84 |
| -// |
85 |
| -// +-------------+ |
86 |
| -// | Root 1 | |
87 |
| -// +-------------+ |
88 |
| -// | |
89 |
| -// ( fillNodeRec fills in the ) |
90 |
| -// ( chunks on the root. ) |
91 |
| -// | |
92 |
| -// +------+------+ |
93 |
| -// | | |
94 |
| -// + - - - - + + - - - - + |
95 |
| -// | Chunk 1 | | Chunk 2 | |
96 |
| -// + - - - - + + - - - - + |
| 84 | +// `Layout` creates a root and hands it off to be filled: |
97 | 85 | //
|
98 |
| -// ↓ |
99 |
| -// When the root is full but there's more data... |
100 |
| -// ↓ |
| 86 | +// +-------------+ |
| 87 | +// | Root 1 | |
| 88 | +// +-------------+ |
| 89 | +// | |
| 90 | +// ( fillNodeRec fills in the ) |
| 91 | +// ( chunks on the root. ) |
| 92 | +// | |
| 93 | +// +------+------+ |
| 94 | +// | | |
| 95 | +// + - - - - + + - - - - + |
| 96 | +// | Chunk 1 | | Chunk 2 | |
| 97 | +// + - - - - + + - - - - + |
101 | 98 | //
|
102 |
| -// +-------------+ |
103 |
| -// | Root 1 | |
104 |
| -// +-------------+ |
105 |
| -// | |
106 |
| -// +------+------+ |
107 |
| -// | | |
108 |
| -// +=========+ +=========+ + - - - - + |
109 |
| -// | Chunk 1 | | Chunk 2 | | Chunk 3 | |
110 |
| -// +=========+ +=========+ + - - - - + |
| 99 | +// ↓ |
| 100 | +// When the root is full but there's more data... |
| 101 | +// ↓ |
111 | 102 | //
|
112 |
| -// ↓ |
113 |
| -// ...Layout's job is to create a new root. |
114 |
| -// ↓ |
| 103 | +// +-------------+ |
| 104 | +// | Root 1 | |
| 105 | +// +-------------+ |
| 106 | +// | |
| 107 | +// +------+------+ |
| 108 | +// | | |
| 109 | +// +=========+ +=========+ + - - - - + |
| 110 | +// | Chunk 1 | | Chunk 2 | | Chunk 3 | |
| 111 | +// +=========+ +=========+ + - - - - + |
115 | 112 | //
|
116 |
| -// +-------------+ |
117 |
| -// | Root 2 | |
118 |
| -// +-------------+ |
119 |
| -// | |
120 |
| -// +-------------+ - - - - - - - - + |
121 |
| -// | | |
122 |
| -// +-------------+ ( fillNodeRec creates the ) |
123 |
| -// | Node 1 | ( branch that connects ) |
124 |
| -// +-------------+ ( "Root 2" to "Chunk 3." ) |
125 |
| -// | | |
126 |
| -// +------+------+ + - - - - -+ |
127 |
| -// | | | |
128 |
| -// +=========+ +=========+ + - - - - + |
129 |
| -// | Chunk 1 | | Chunk 2 | | Chunk 3 | |
130 |
| -// +=========+ +=========+ + - - - - + |
| 113 | +// ↓ |
| 114 | +// ...Layout's job is to create a new root. |
| 115 | +// ↓ |
131 | 116 | //
|
| 117 | +// +-------------+ |
| 118 | +// | Root 2 | |
| 119 | +// +-------------+ |
| 120 | +// | |
| 121 | +// +-------------+ - - - - - - - - + |
| 122 | +// | | |
| 123 | +// +-------------+ ( fillNodeRec creates the ) |
| 124 | +// | Node 1 | ( branch that connects ) |
| 125 | +// +-------------+ ( "Root 2" to "Chunk 3." ) |
| 126 | +// | | |
| 127 | +// +------+------+ + - - - - -+ |
| 128 | +// | | | |
| 129 | +// +=========+ +=========+ + - - - - + |
| 130 | +// | Chunk 1 | | Chunk 2 | | Chunk 3 | |
| 131 | +// +=========+ +=========+ + - - - - + |
132 | 132 | func Layout(db *h.DagBuilderHelper) (ipld.Node, error) {
|
133 | 133 | if db.Done() {
|
134 | 134 | // No data, return just an empty node.
|
@@ -185,22 +185,22 @@ func Layout(db *h.DagBuilderHelper) (ipld.Node, error) {
|
185 | 185 | // root, and those children will in turn be filled (calling `fillNodeRec`
|
186 | 186 | // recursively).
|
187 | 187 | //
|
188 |
| -// +-------------+ |
189 |
| -// | `node` | |
190 |
| -// | (new root) | |
191 |
| -// +-------------+ |
192 |
| -// | |
193 |
| -// +-------------+ - - - - - - + - - - - - - - - - - - + |
194 |
| -// | | | |
195 |
| -// +--------------+ + - - - - - + + - - - - - + |
196 |
| -// | (old root) | | new child | | | |
197 |
| -// +--------------+ + - - - - - + + - - - - - + |
198 |
| -// | | | |
199 |
| -// +------+------+ + - - + - - - + |
200 |
| -// | | | | |
201 |
| -// +=========+ +=========+ + - - - - + + - - - - + |
202 |
| -// | Chunk 1 | | Chunk 2 | | Chunk 3 | | Chunk 4 | |
203 |
| -// +=========+ +=========+ + - - - - + + - - - - + |
| 188 | +// +-------------+ |
| 189 | +// | `node` | |
| 190 | +// | (new root) | |
| 191 | +// +-------------+ |
| 192 | +// | |
| 193 | +// +-------------+ - - - - - - + - - - - - - - - - - - + |
| 194 | +// | | | |
| 195 | +// +--------------+ + - - - - - + + - - - - - + |
| 196 | +// | (old root) | | new child | | | |
| 197 | +// +--------------+ + - - - - - + + - - - - - + |
| 198 | +// | | | |
| 199 | +// +------+------+ + - - + - - - + |
| 200 | +// | | | | |
| 201 | +// +=========+ +=========+ + - - - - + + - - - - + |
| 202 | +// | Chunk 1 | | Chunk 2 | | Chunk 3 | | Chunk 4 | |
| 203 | +// +=========+ +=========+ + - - - - + + - - - - + |
204 | 204 | //
|
205 | 205 | // The `node` to be filled uses the `FSNodeOverDag` abstraction that allows adding
|
206 | 206 | // child nodes without packing/unpacking the UnixFS layer node (having an internal
|
|
0 commit comments