Blender
V4.3
source
blender
blenlib
BLI_vector_list.hh
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#pragma once
6
7
#include <algorithm>
8
9
#include "
BLI_vector.hh
"
10
11
namespace
blender
{
12
28
template
<
typename
T,
int
64_t CapacityStart = 32,
int
64_t CapacitySoftLimit = 4096>
29
class
VectorList
{
30
public
:
31
using
UsedVector
=
Vector<T, 0>
;
32
33
private
:
37
Vector<UsedVector>
vectors_;
38
39
public
:
40
VectorList
()
41
{
42
this->append_vector();
43
}
44
45
void
append
(
const
T
&value)
46
{
47
this->
append_as
(value);
48
}
49
50
void
append
(
T
&&value)
51
{
52
this->
append_as
(std::move(value));
53
}
54
55
template
<
typename
ForwardT>
void
append_as
(ForwardT &&value)
56
{
57
UsedVector
&
vector
= this->ensure_space_for_one();
58
vector
.append_unchecked_as(std::forward<ForwardT>(value));
59
}
60
61
UsedVector
*
begin
()
62
{
63
return
vectors_.
begin
();
64
}
65
66
UsedVector
*
end
()
67
{
68
return
vectors_.
end
();
69
}
70
71
const
UsedVector
*
begin
()
const
72
{
73
return
vectors_.
begin
();
74
}
75
76
const
UsedVector
*
end
()
const
77
{
78
return
vectors_.
end
();
79
}
80
81
T
&
last
()
82
{
83
return
vectors_.last().last();
84
}
85
86
int64_t
size
()
const
87
{
88
int64_t
result
= 0;
89
for
(
const
UsedVector
&
vector
: *
this
) {
90
result
+=
vector
.size();
91
}
92
return
result
;
93
}
94
95
private
:
96
UsedVector
&ensure_space_for_one()
97
{
98
UsedVector
&
vector
= vectors_.
last
();
99
if
(
LIKELY
(!
vector
.is_at_capacity())) {
100
return
vector
;
101
}
102
this->append_vector();
103
return
vectors_.
last
();
104
}
105
106
void
append_vector()
107
{
108
const
int64_t
new_vector_capacity = this->get_next_vector_capacity();
109
vectors_.append({});
110
vectors_.last().reserve(new_vector_capacity);
111
}
112
113
int64_t
get_next_vector_capacity()
114
{
115
if
(vectors_.is_empty()) {
116
return
CapacityStart;
117
}
118
return
std::min(vectors_.last().capacity() * 2, CapacitySoftLimit);
119
}
120
};
121
122
}
// namespace blender
result
double result
Definition
BLI_expr_pylike_eval_test.cc:351
LIKELY
#define LIKELY(x)
Definition
BLI_utildefines.h:553
BLI_vector.hh
blender::VectorList::end
UsedVector * end()
Definition
BLI_vector_list.hh:66
blender::VectorList::UsedVector
Vector< T, 0 > UsedVector
Definition
BLI_vector_list.hh:31
blender::VectorList::begin
UsedVector * begin()
Definition
BLI_vector_list.hh:61
blender::VectorList::size
int64_t size() const
Definition
BLI_vector_list.hh:86
blender::VectorList::last
T & last()
Definition
BLI_vector_list.hh:81
blender::VectorList::append
void append(T &&value)
Definition
BLI_vector_list.hh:50
blender::VectorList::begin
const UsedVector * begin() const
Definition
BLI_vector_list.hh:71
blender::VectorList::append
void append(const T &value)
Definition
BLI_vector_list.hh:45
blender::VectorList::append_as
void append_as(ForwardT &&value)
Definition
BLI_vector_list.hh:55
blender::VectorList::end
const UsedVector * end() const
Definition
BLI_vector_list.hh:76
blender::VectorList::VectorList
VectorList()
Definition
BLI_vector_list.hh:40
blender::Vector
Definition
BLI_vector.hh:65
blender::Vector::last
const T & last(const int64_t n=0) const
Definition
BLI_vector.hh:660
blender::Vector::end
T * end()
Definition
BLI_vector.hh:882
blender::Vector::begin
T * begin()
Definition
BLI_vector.hh:878
vector
Definition
cycles/util/vector.h:22
T
#define T
Definition
mball_tessellate.cc:273
blender
Definition
ANIM_action.hh:36
int64_t
__int64 int64_t
Definition
stdint.h:89
Generated on Sat Oct 4 2025 05:32:23 for Blender by
doxygen
1.14.0