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
//! Regression test for `capacity()` on structs that mix a plain (`Vec`)
//! column with a `Compact<T>` column.
//!
//! `Compact` columns have word-granular capacity (e.g. 256 for a 1-bit
//! column) while plain `Vec` columns have a smaller, element-granular
//! capacity. The old `capacity()` body debug-asserted that every column's
//! capacity was equal, which panicked for any mixed struct. The new body
//! returns the minimum capacity across all columns.
use layout::{Compact, CompactBool, SOA};
#[derive(SOA)]
struct C {
id: u32,
flag: CompactBool,
}
#[test]
fn capacity_does_not_panic_for_mixed_struct() {
let mut v = CVec::new();
v.push(C {
id: 1,
flag: Compact(true),
});
v.push(C {
id: 2,
flag: Compact(false),
});
// This alone is the regression: under the old `debug_assert_eq!` body this
// debug-panicked because the compact column's word-granular capacity (256
// for a 1-bit column) differs from the plain `Vec<u32>` capacity (4).
let _ = v.capacity();
}
#[test]
fn capacity_is_min_after_reserve() {
let mut v = CVec::new();
v.push(C {
id: 1,
flag: Compact(true),
});
v.push(C {
id: 2,
flag: Compact(false),
});
v.reserve(1000);
// The min capacity is a valid lower bound: after reserving 1000 additional
// slots on every column, the binding (minimum) column must still have at
// least len + 1000 free.
assert!(v.capacity() >= v.len() + 1000);
}
#[test]
fn capacity_equals_min_of_columns() {
let mut v = CVec::new();
v.push(C {
id: 1,
flag: Compact(true),
});
v.push(C {
id: 2,
flag: Compact(false),
});
// Lock in the documented semantics: the returned value is exactly the
// minimum across the columns.
assert_eq!(v.capacity(), v.id.capacity().min(v.flag.capacity()));
}