1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
//! Cutting a tree in two at a key: [`Tree::split_off_at`], for the map's
//! `split_off`.
//!
//! A search finds the leaf edge on the given side of the key ([`KeySide`]),
//! where the cut goes. For a key that is a separator, the edge before it is
//! the end of the rightmost leaf left of it. Up the node stack from there,
//! each node is cut at the node stack's edge (`Leaf::cut_off_at`,
//! `Internal::cut_off_at`). It keeps what lies left of the node stack; what
//! lies right goes into a new node, after the part cut off the node below,
//! as its first child. The new nodes make a tree as tall as the old one,
//! with the keys past the cut.
//!
//! The nodes on the node stack become the borders of the two trees, whose
//! prefix is what every key of the tree shares (D50). So before the cut,
//! their prefixes go back to the root's, from the root down, reading no key.
//! Both trees keep what the old tree's keys shared; their keys share at
//! least that.
//!
//! Along the cut, nodes on both sides may hold fewer keys than their
//! minimum, down to none. [`Tree::fix_border`] brings them back, from the
//! top down, along the left tree's right border and the right tree's left
//! border. A separator left at the start of the right tree, with nothing
//! left of it, comes down that border into the tree's first leaf, by a merge
//! or a move. It brings its value, which was its head (D17).
//!
//! The nodes beside the borders, which entries moved over from, then fit
//! their prefixes to their new fences, reading keys. They do so only once
//! both trees are counted and where a panic can't lose them. So the cut
//! hands out the right tree only through [`Cut::finish`], which puts it
//! there and fits both.
//!
//! The cut touches the nodes along the node stack and the two borders:
//! O(log n) of them. The two maps' lengths come from counting the entries of
//! the shorter tree, a node at a time, as std's do ([`Cut::lengths`]).
//!
//! # Borders
//!
//! [`Tree::fix_border`] brings the nodes along one edge of a tree up to
//! their minimum (D22), from the top down. A tree cut in two needs it along
//! both sides of the cut. A tree built from the left (`build.rs`) needs it
//! along its right edge. There, nodes may hold any number of keys, down to
//! none, while every other node holds its minimum.
//!
//! It reads no key. The nodes beside the border that give it entries keep
//! their prefixes, which still fit their narrower fences, until the
//! operation fits them once it is done ([`Tree::refit_border_siblings`]).
use Borrow;
use SearchKey;
use Internal;
use Leaf;
use FreshPage;
use Siblings;
use ;
use ;
use Tree;
use crateAllocator;
use crateInlineKeyStrategy;
/// The part after a cut ([`Tree::split_off_at`]). It comes out only once
/// the nodes beside both borders along the cut, which gave the borders
/// entries, fit their prefixes to their new fences. Until then those nodes
/// keep prefixes that still fit, which searches allow, but shorter than
/// what their fences share.
pub