I think I explained this incorrectly. Sorry, I’m kind of tired.
In my actual code, I’m doing this:
Note : arr_cap > num_cart_points
pa.reserve(arr_cap);
ta.reserve(arr_cap);
fs.reserve(arr_cap);
la.reserve(arr_cap);
pa.assign(arr_cap, -1);
ta.assign(arr_cap, -1);
fs.assign(arr_cap, -1);
la.assign(arr_cap, -1);
pa.resize(num_cart_points);
ta.resize(num_cart_points);
fs.resize(num_cart_points);
la.resize(num_cart_points);
For example, num_cart_points is initially 64.
I then write to these arrays. This is safe because the capacity is there. I’m not writing out of bounds.
I use the first 64 elements of data to calculate a bunch of info which I write to the back of the array. For example, I’ll write a bunch of stuff after the 64th element of the array.
The initial 64 elements are then reset back to -1 and I sort the array so that all the -1’s are behind anything positive. So it goes { 0, 1, 2, 3, -1, …, -1 }.
I then calculate the new_size to be 87 as that’s the first occurrence of -1 so the new “size” should be 87.
Before, I resize() the vectors, the data is as it should be. The only issue is that the size of each vector is still 64 and not 87.
So when I resize() the vectors, the last 23 elements get reset to 0.
This is the data before the resize (old size = 64, this is visually confirmed) :
4, 2, 1, 1
7, 2, 2, 3
8, 2, 3, 7
9, 2, 2, 9
11, 2, 2, 5
12, 2, 2, 5
13, 2, 2, 5
16, 2, 3, 13
17, 2, 3, 13
18, 2, 3, 7
19, 2, 3, 7
20, 2, 3, 7
21, 2, 3, 7
22, 2, 4, 15
23, 2, 4, 15
24, 2, 4, 15
25, 2, 4, 15
26, 2, 3, 7
27, 2, 3, 7
28, 2, 3, 7
29, 2, 2, 3
30, 2, 2, 3
31, 2, 3, 7
32, 2, 3, 11
35, 2, 3, 11
46, 2, 4, 15
47, 2, 3, 11
48, 2, 2, 9
49, 2, 3, 13
4, 1, 1, 1
5, 1, 2, 3
6, 1, 3, 7
7, 1, 2, 5
9, 1, 2, 9
29, 1, 2, 5
30, 1, 2, 5
32, 1, 3, 13
33, 1, 3, 7
34, 1, 3, 7
35, 1, 3, 13
36, 1, 4, 15
37, 1, 3, 7
38, 1, 3, 7
39, 1, 4, 15
40, 1, 4, 15
41, 1, 3, 7
42, 1, 3, 7
43, 1, 4, 15
44, 1, 4, 15
47, 1, 3, 13
48, 1, 2, 9
51, 1, 3, 11
62, 1, 3, 11
63, 1, 3, 11
64, 1, 3, 7
65, 1, 3, 7
66, 1, 2, 3
67, 1, 2, 3
4, 0, 1, 1
5, 0, 2, 5
9, 0, 2, 9
10, 0, 3, 7
11, 0, 2, 3
12, 0, 2, 3
13, 0, 2, 3
14, 0, 3, 7
15, 0, 3, 7
16, 0, 3, 11
17, 0, 3, 11
48, 0, 2, 9
49, 0, 3, 11
50, 0, 4, 15
51, 0, 3, 13
52, 0, 4, 15
53, 0, 4, 15
54, 0, 4, 15
55, 0, 4, 15
56, 0, 3, 7
57, 0, 3, 7
58, 0, 3, 7
59, 0, 3, 7
60, 0, 3, 7
61, 0, 3, 7
62, 0, 3, 13
63, 0, 3, 13
66, 0, 2, 5
67, 0, 2, 5
And this is the data after the resize (note how the last 23 elements are now 0) :
0 : 4, 2, 1, 1
1 : 7, 2, 2, 3
2 : 8, 2, 3, 7
3 : 9, 2, 2, 9
4 : 11, 2, 2, 5
5 : 12, 2, 2, 5
6 : 13, 2, 2, 5
7 : 16, 2, 3, 13
8 : 17, 2, 3, 13
9 : 18, 2, 3, 7
10 : 19, 2, 3, 7
11 : 20, 2, 3, 7
12 : 21, 2, 3, 7
13 : 22, 2, 4, 15
14 : 23, 2, 4, 15
15 : 24, 2, 4, 15
16 : 25, 2, 4, 15
17 : 26, 2, 3, 7
18 : 27, 2, 3, 7
19 : 28, 2, 3, 7
20 : 29, 2, 2, 3
21 : 30, 2, 2, 3
22 : 31, 2, 3, 7
23 : 32, 2, 3, 11
24 : 35, 2, 3, 11
25 : 46, 2, 4, 15
26 : 47, 2, 3, 11
27 : 48, 2, 2, 9
28 : 49, 2, 3, 13
29 : 4, 1, 1, 1
30 : 5, 1, 2, 3
31 : 6, 1, 3, 7
32 : 7, 1, 2, 5
33 : 9, 1, 2, 9
34 : 29, 1, 2, 5
35 : 30, 1, 2, 5
36 : 32, 1, 3, 13
37 : 33, 1, 3, 7
38 : 34, 1, 3, 7
39 : 35, 1, 3, 13
40 : 36, 1, 4, 15
41 : 37, 1, 3, 7
42 : 38, 1, 3, 7
43 : 39, 1, 4, 15
44 : 40, 1, 4, 15
45 : 41, 1, 3, 7
46 : 42, 1, 3, 7
47 : 43, 1, 4, 15
48 : 44, 1, 4, 15
49 : 47, 1, 3, 13
50 : 48, 1, 2, 9
51 : 51, 1, 3, 11
52 : 62, 1, 3, 11
53 : 63, 1, 3, 11
54 : 64, 1, 3, 7
55 : 65, 1, 3, 7
56 : 66, 1, 2, 3
57 : 67, 1, 2, 3
58 : 4, 0, 1, 1
59 : 5, 0, 2, 5
60 : 9, 0, 2, 9
61 : 10, 0, 3, 7
62 : 11, 0, 2, 3
63 : 12, 0, 2, 3
64 : 0, 0, 0, 0
65 : 0, 0, 0, 0
66 : 0, 0, 0, 0
67 : 0, 0, 0, 0
68 : 0, 0, 0, 0
69 : 0, 0, 0, 0
70 : 0, 0, 0, 0
71 : 0, 0, 0, 0
72 : 0, 0, 0, 0
73 : 0, 0, 0, 0
74 : 0, 0, 0, 0
75 : 0, 0, 0, 0
76 : 0, 0, 0, 0
77 : 0, 0, 0, 0
78 : 0, 0, 0, 0
79 : 0, 0, 0, 0
80 : 0, 0, 0, 0
81 : 0, 0, 0, 0
82 : 0, 0, 0, 0
83 : 0, 0, 0, 0
84 : 0, 0, 0, 0
85 : 0, 0, 0, 0
86 : 0, 0, 0, 0
Sorry if I was vague earlier.