Blender V4.3
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
11namespace blender {
12
28template<typename T, int64_t CapacityStart = 32, int64_t CapacitySoftLimit = 4096>
30 public:
32
33 private:
37 Vector<UsedVector> vectors_;
38
39 public:
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
62 {
63 return vectors_.begin();
64 }
65
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
#define LIKELY(x)
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a vector
Vector< T, 0 > UsedVector
int64_t size() const
void append(T &&value)
const UsedVector * begin() const
void append(const T &value)
void append_as(ForwardT &&value)
const UsedVector * end() const
void append(const T &value)
const T & last(const int64_t n=0) const
bool is_empty() const
__int64 int64_t
Definition stdint.h:89