@@ -20,6 +20,7 @@ pub use iterator::Iterator;
20
20
/// assert_eq!(flat_tree::index(3, 0), 7);
21
21
/// assert_eq!(flat_tree::index(3, 1), 23);
22
22
/// ```
23
+ #[ inline]
23
24
pub fn index ( depth : usize , offset : usize ) -> usize {
24
25
( offset << ( depth + 1 ) ) | ( ( 1 << depth) - 1 )
25
26
}
@@ -34,6 +35,7 @@ pub fn index(depth: usize, offset: usize) -> usize {
34
35
/// assert_eq!(flat_tree::depth(3), 2);
35
36
/// assert_eq!(flat_tree::depth(4), 0);
36
37
/// ```
38
+ #[ inline]
37
39
pub fn depth ( i : usize ) -> usize {
38
40
let mut depth = 0 ;
39
41
let mut i = i;
@@ -54,6 +56,7 @@ pub fn depth(i: usize) -> usize {
54
56
/// assert_eq!(flat_tree::offset_with_depth(3, 2), 0);
55
57
/// assert_eq!(flat_tree::offset_with_depth(4, 0), 2);
56
58
/// ```
59
+ #[ inline]
57
60
pub fn offset_with_depth ( i : usize , depth : usize ) -> usize {
58
61
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
59
62
if is_even ( i) {
@@ -73,6 +76,7 @@ pub fn offset_with_depth(i: usize, depth: usize) -> usize {
73
76
/// assert_eq!(flat_tree::offset(3), 0);
74
77
/// assert_eq!(flat_tree::offset(4), 2);
75
78
/// ```
79
+ #[ inline]
76
80
pub fn offset ( i : usize ) -> usize {
77
81
offset_with_depth ( i, depth ( i) )
78
82
}
@@ -87,6 +91,7 @@ pub fn offset(i: usize) -> usize {
87
91
/// assert_eq!(flat_tree::parent_with_depth(3, 2), 7);
88
92
/// assert_eq!(flat_tree::parent_with_depth(4, 0), 5);
89
93
/// ```
94
+ #[ inline]
90
95
pub fn parent_with_depth ( i : usize , depth : usize ) -> usize {
91
96
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
92
97
index ( depth + 1 , offset_with_depth ( i, depth) >> 1 )
@@ -104,6 +109,7 @@ pub fn parent_with_depth(i: usize, depth: usize) -> usize {
104
109
/// assert_eq!(flat_tree::parent(2), 1);
105
110
/// assert_eq!(flat_tree::parent(1), 3);
106
111
/// ```
112
+ #[ inline]
107
113
pub fn parent ( i : usize ) -> usize {
108
114
parent_with_depth ( i, depth ( i) )
109
115
}
@@ -118,6 +124,7 @@ pub fn parent(i: usize) -> usize {
118
124
/// assert_eq!(flat_tree::sibling_with_depth(3, 2), 11);
119
125
/// assert_eq!(flat_tree::sibling_with_depth(4, 0), 6);
120
126
/// ```
127
+ #[ inline]
121
128
pub fn sibling_with_depth ( i : usize , depth : usize ) -> usize {
122
129
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
123
130
index ( depth, offset ( i) ^ 1 )
@@ -132,6 +139,7 @@ pub fn sibling_with_depth(i: usize, depth: usize) -> usize {
132
139
/// assert_eq!(flat_tree::sibling(1), 5);
133
140
/// assert_eq!(flat_tree::sibling(5), 1);
134
141
/// ```
142
+ #[ inline]
135
143
pub fn sibling ( i : usize ) -> usize {
136
144
sibling_with_depth ( i, depth ( i) )
137
145
}
@@ -145,6 +153,7 @@ pub fn sibling(i: usize) -> usize {
145
153
/// assert_eq!(flat_tree::uncle_with_depth(2, 0), 5);
146
154
/// assert_eq!(flat_tree::uncle_with_depth(5, 1), 11);
147
155
/// ```
156
+ #[ inline]
148
157
pub fn uncle_with_depth ( i : usize , depth : usize ) -> usize {
149
158
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
150
159
sibling_with_depth ( parent_with_depth ( i, depth) , depth + 1 )
@@ -159,6 +168,7 @@ pub fn uncle_with_depth(i: usize, depth: usize) -> usize {
159
168
/// assert_eq!(flat_tree::uncle(1), 11);
160
169
/// assert_eq!(flat_tree::uncle(5), 11);
161
170
/// ```
171
+ #[ inline]
162
172
pub fn uncle ( i : usize ) -> usize {
163
173
uncle_with_depth ( i, depth ( i) )
164
174
}
@@ -172,6 +182,7 @@ pub fn uncle(i: usize) -> usize {
172
182
/// assert_eq!(flat_tree::children_with_depth(3, 2), Some((1, 5)));
173
183
/// assert_eq!(flat_tree::children_with_depth(9, 1), Some((8, 10)));
174
184
/// ```
185
+ #[ inline]
175
186
pub fn children_with_depth ( i : usize , depth : usize ) -> Option < ( usize , usize ) > {
176
187
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
177
188
if is_even ( i) {
@@ -193,6 +204,7 @@ pub fn children_with_depth(i: usize, depth: usize) -> Option<(usize, usize)> {
193
204
/// assert_eq!(flat_tree::children(3), Some((1, 5)));
194
205
/// assert_eq!(flat_tree::children(9), Some((8, 10)));
195
206
/// ```
207
+ #[ inline]
196
208
pub fn children ( i : usize ) -> Option < ( usize , usize ) > {
197
209
children_with_depth ( i, depth ( i) )
198
210
}
@@ -206,6 +218,7 @@ pub fn children(i: usize) -> Option<(usize, usize)> {
206
218
/// assert_eq!(flat_tree::left_child_with_depth(3, 2), Some(1));
207
219
/// ```
208
220
// TODO: handle errors
221
+ #[ inline]
209
222
pub fn left_child_with_depth ( i : usize , depth : usize ) -> Option < usize > {
210
223
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
211
224
if is_even ( i) {
@@ -225,6 +238,7 @@ pub fn left_child_with_depth(i: usize, depth: usize) -> Option<usize> {
225
238
/// assert_eq!(flat_tree::left_child(1), Some(0));
226
239
/// assert_eq!(flat_tree::left_child(3), Some(1));
227
240
/// ```
241
+ #[ inline]
228
242
pub fn left_child ( i : usize ) -> Option < usize > {
229
243
left_child_with_depth ( i, depth ( i) )
230
244
}
@@ -237,6 +251,7 @@ pub fn left_child(i: usize) -> Option<usize> {
237
251
/// assert_eq!(flat_tree::right_child_with_depth(1, 1), Some(2));
238
252
/// assert_eq!(flat_tree::right_child_with_depth(3, 2), Some(5));
239
253
/// ```
254
+ #[ inline]
240
255
pub fn right_child_with_depth ( i : usize , depth : usize ) -> Option < usize > {
241
256
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
242
257
if is_even ( i) {
@@ -257,6 +272,7 @@ pub fn right_child_with_depth(i: usize, depth: usize) -> Option<usize> {
257
272
/// assert_eq!(flat_tree::right_child(3), Some(5));
258
273
/// ```
259
274
// TODO: handle errors
275
+ #[ inline]
260
276
pub fn right_child ( i : usize ) -> Option < usize > {
261
277
right_child_with_depth ( i, depth ( i) )
262
278
}
@@ -271,6 +287,7 @@ pub fn right_child(i: usize) -> Option<usize> {
271
287
/// assert_eq!(flat_tree::right_span_with_depth(23, 3), 30);
272
288
/// assert_eq!(flat_tree::right_span_with_depth(27, 2), 30);
273
289
/// ```
290
+ #[ inline]
274
291
pub fn right_span_with_depth ( i : usize , depth : usize ) -> usize {
275
292
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
276
293
if depth == 0 {
@@ -290,6 +307,7 @@ pub fn right_span_with_depth(i: usize, depth: usize) -> usize {
290
307
/// assert_eq!(flat_tree::right_span(23), 30);
291
308
/// assert_eq!(flat_tree::right_span(27), 30);
292
309
/// ```
310
+ #[ inline]
293
311
pub fn right_span ( i : usize ) -> usize {
294
312
right_span_with_depth ( i, depth ( i) )
295
313
}
@@ -304,6 +322,7 @@ pub fn right_span(i: usize) -> usize {
304
322
/// assert_eq!(flat_tree::left_span_with_depth(23, 3), 16);
305
323
/// assert_eq!(flat_tree::left_span_with_depth(27, 2), 24);
306
324
/// ```
325
+ #[ inline]
307
326
pub fn left_span_with_depth ( i : usize , depth : usize ) -> usize {
308
327
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
309
328
if depth == 0 {
@@ -323,6 +342,7 @@ pub fn left_span_with_depth(i: usize, depth: usize) -> usize {
323
342
/// assert_eq!(flat_tree::left_span(23), 16);
324
343
/// assert_eq!(flat_tree::left_span(27), 24);
325
344
/// ```
345
+ #[ inline]
326
346
pub fn left_span ( i : usize ) -> usize {
327
347
left_span_with_depth ( i, depth ( i) )
328
348
}
@@ -338,6 +358,7 @@ pub fn left_span(i: usize) -> usize {
338
358
/// assert_eq!(flat_tree::spans_with_depth(23, 3), (16, 30));
339
359
/// assert_eq!(flat_tree::spans_with_depth(27, 2), (24, 30));
340
360
/// ```
361
+ #[ inline]
341
362
pub fn spans_with_depth ( i : usize , depth : usize ) -> ( usize , usize ) {
342
363
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
343
364
(
@@ -356,6 +377,7 @@ pub fn spans_with_depth(i: usize, depth: usize) -> (usize, usize) {
356
377
/// assert_eq!(flat_tree::spans(23), (16, 30));
357
378
/// assert_eq!(flat_tree::spans(27), (24, 30));
358
379
/// ```
380
+ #[ inline]
359
381
pub fn spans ( i : usize ) -> ( usize , usize ) {
360
382
spans_with_depth ( i, depth ( i) )
361
383
}
@@ -371,6 +393,7 @@ pub fn spans(i: usize) -> (usize, usize) {
371
393
/// assert_eq!(flat_tree::count_with_depth(23, 3), 15);
372
394
/// assert_eq!(flat_tree::count_with_depth(27, 2), 7);
373
395
/// ```
396
+ #[ inline]
374
397
pub fn count_with_depth ( i : usize , depth : usize ) -> usize {
375
398
debug_assert_eq ! ( depth, self :: depth( i) , "Invalid depth." ) ;
376
399
( 2 << depth) - 1
@@ -387,6 +410,7 @@ pub fn count_with_depth(i: usize, depth: usize) -> usize {
387
410
/// assert_eq!(flat_tree::count(23), 15);
388
411
/// assert_eq!(flat_tree::count(27), 7);
389
412
/// ```
413
+ #[ inline]
390
414
pub fn count ( i : usize ) -> usize {
391
415
count_with_depth ( i, depth ( i) )
392
416
}
@@ -426,6 +450,7 @@ pub fn count(i: usize) -> usize {
426
450
/// full_roots(16, &mut nodes);
427
451
/// assert_eq!(nodes, [7]);
428
452
/// ```
453
+ #[ inline]
429
454
pub fn full_roots ( i : usize , nodes : & mut Vec < usize > ) {
430
455
assert ! (
431
456
is_even( i) ,
0 commit comments