33 #ifndef OPM_FAST_SMALL_VECTOR_HPP 34 #define OPM_FAST_SMALL_VECTOR_HPP 47 template <
typename ValueType,
unsigned N>
57 dataPtr_ = smallBuf_.data();
72 std::fill_n(dataPtr_, size_,
value);
79 dataPtr_ = smallBuf_.data();
88 dataPtr_ = smallBuf_.data();
90 (*this) = std::move(other);
103 if (other.usingSmallBuf()) {
104 smallBuf_ = std::move(other.smallBuf_);
105 dataPtr_ = smallBuf_.data();
108 data_ = std::move(other.data_);
109 dataPtr_ = data_.data();
112 other.dataPtr_ =
nullptr;
123 if (other.usingSmallBuf()) {
124 smallBuf_ = other.smallBuf_;
125 dataPtr_ = smallBuf_.data();
127 else if (dataPtr_ != other.dataPtr_) {
129 dataPtr_ = data_.data();
137 {
return dataPtr_[idx]; }
141 {
return dataPtr_[idx]; }
143 using size_type =
typename std::vector<ValueType>::size_type;
161 {
return dataPtr_ + size_; }
169 {
return dataPtr_ + size_; }
177 {
return dataPtr_ + size_; }
180 {
return this->usingSmallBuf() ? N : data_.capacity(); }
182 void push_back(
const ValueType&
value)
184 if (this->usingSmallBuf()) {
187 smallBuf_[size_++] =
value;
188 }
else if (size_ == N) {
190 data_.reserve(N + 1);
192 std::move(smallBuf_.begin(), smallBuf_.end(), data_.begin());
193 data_.push_back(
value);
195 dataPtr_ = data_.data();
199 data_.push_back(
value);
201 dataPtr_ = data_.data();
205 void resize(std::size_t numElem)
207 if (numElem == size_)
return;
209 if (this->usingSmallBuf()) {
211 data_.resize(numElem);
212 if (size_ > 0 && N > 0) {
213 std::copy_n(smallBuf_.begin(), size_, data_.begin());
215 dataPtr_ = data_.data();
216 }
else if (numElem < size_) {
219 for (
auto ii = numElem; ii < size_; ++ii) {
220 smallBuf_[ii].~ValueType();
225 data_.resize(numElem);
231 void init_(std::size_t numElem)
237 dataPtr_ = data_.data();
239 dataPtr_ = smallBuf_.data();
242 bool usingSmallBuf()
const 244 return dataPtr_ == smallBuf_.data();
247 std::array<ValueType, N> smallBuf_{};
248 std::vector<ValueType> data_;
255 #endif // OPM_FAST_SMALL_VECTOR_HPP size_type size() const
number of elements
Definition: FastSmallVector.hpp:146
ConstIterator cend() const
To support range-for etc.
Definition: FastSmallVector.hpp:168
FastSmallVector(const FastSmallVector &other)
copy constructor
Definition: FastSmallVector.hpp:76
An implementation of vector/array based on small object optimization.
Definition: FastSmallVector.hpp:50
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
FastSmallVector(const std::size_t numElem)
constructor based on the number of the element
Definition: FastSmallVector.hpp:61
~FastSmallVector()
destructor
Definition: FastSmallVector.hpp:94
FastSmallVector(const std::size_t numElem, const ValueType value)
constructor based on the number of the element, and all the elements will have the same value ...
Definition: FastSmallVector.hpp:68
ValueType & operator[](std::size_t idx)
access the idx th element
Definition: FastSmallVector.hpp:136
const ValueType & operator[](std::size_t idx) const
const access the idx th element
Definition: FastSmallVector.hpp:140
FastSmallVector(FastSmallVector &&other)
move constructor
Definition: FastSmallVector.hpp:85
Iterator begin()
To support range-for etc.
Definition: FastSmallVector.hpp:172
Iterator end()
To support range-for etc.
Definition: FastSmallVector.hpp:176
ConstIterator cbegin() const
To support range-for etc.
Definition: FastSmallVector.hpp:164
ConstIterator begin() const
To support range-for etc.
Definition: FastSmallVector.hpp:156
FastSmallVector & operator=(const FastSmallVector &other)
copy assignment
Definition: FastSmallVector.hpp:119
ConstIterator end() const
To support range-for etc.
Definition: FastSmallVector.hpp:160
FastSmallVector()
default constructor
Definition: FastSmallVector.hpp:54
ValueT * Iterator
Iterator type is a plain pointer, so be warned there is no validity checking.
Definition: FastSmallVector.hpp:150
const ValueT * ConstIterator
ConstIterator type is a plain pointer, so be warned there is no validity checking.
Definition: FastSmallVector.hpp:153
FastSmallVector & operator=(FastSmallVector &&other)
move assignment
Definition: FastSmallVector.hpp:100