33#ifndef OPM_FAST_SMALL_VECTOR_HPP
34#define OPM_FAST_SMALL_VECTOR_HPP
48template <
typename ValueType,
unsigned N>
56 dataPtr_ = smallBuf_.data();
71 std::fill_n(dataPtr_, size_, value);
78 dataPtr_ = smallBuf_.data();
87 dataPtr_ = smallBuf_.data();
89 (*this) = std::move(other);
102 if (other.usingSmallBuf()) {
103 smallBuf_ = std::move(other.smallBuf_);
104 dataPtr_ = smallBuf_.data();
107 data_ = std::move(other.data_);
108 dataPtr_ = data_.data();
111 other.dataPtr_ =
nullptr;
122 if (other.usingSmallBuf()) {
123 smallBuf_ = other.smallBuf_;
124 dataPtr_ = smallBuf_.data();
126 else if (dataPtr_ != other.dataPtr_) {
128 dataPtr_ = data_.data();
136 {
return dataPtr_[idx]; }
140 {
return dataPtr_[idx]; }
142 using size_type =
typename std::vector<ValueType>::size_type;
160 {
return dataPtr_ + size_; }
168 {
return dataPtr_ + size_; }
176 {
return dataPtr_ + size_; }
179 {
return this->usingSmallBuf() ? N : data_.capacity(); }
181 void push_back(
const ValueType& value)
183 if (this->usingSmallBuf()) {
186 smallBuf_[size_++] = value;
187 }
else if (size_ == N) {
189 data_.reserve(N + 1);
191 std::move(smallBuf_.begin(), smallBuf_.end(), data_.begin());
192 data_.push_back(value);
194 dataPtr_ = data_.data();
198 data_.push_back(value);
200 dataPtr_ = data_.data();
204 void resize(
size_t numElem)
206 if (numElem == size_)
return;
208 if (this->usingSmallBuf()) {
210 data_.resize(numElem);
211 if (size_ > 0 && N > 0) {
212 std::copy_n(smallBuf_.begin(), size_, data_.begin());
214 dataPtr_ = data_.data();
215 }
else if (numElem < size_) {
218 for (
auto ii = numElem; ii < size_; ++ii) {
219 smallBuf_[ii].~ValueType();
224 data_.resize(numElem);
230 void init_(
size_t numElem)
236 dataPtr_ = data_.data();
238 dataPtr_ = smallBuf_.data();
241 bool usingSmallBuf()
const
243 return dataPtr_ == smallBuf_.data();
246 std::array<ValueType, N> smallBuf_{};
247 std::vector<ValueType> data_;
FastSmallVector()
default constructor
Definition FastSmallVector.hpp:53
Iterator end()
To support range-for etc.
Definition FastSmallVector.hpp:175
const ValueType * ConstIterator
ConstIterator type is a plain pointer, so be warned there is no validity checking.
Definition FastSmallVector.hpp:152
FastSmallVector & operator=(FastSmallVector &&other)
move assignment
Definition FastSmallVector.hpp:99
FastSmallVector(FastSmallVector &&other)
move constructor
Definition FastSmallVector.hpp:84
ConstIterator end() const
To support range-for etc.
Definition FastSmallVector.hpp:159
const ValueType & operator[](size_t idx) const
const access the idx th element
Definition FastSmallVector.hpp:139
ValueType * Iterator
Iterator type is a plain pointer, so be warned there is no validity checking.
Definition FastSmallVector.hpp:149
FastSmallVector(const 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:67
FastSmallVector & operator=(const FastSmallVector &other)
copy assignment
Definition FastSmallVector.hpp:118
~FastSmallVector()
destructor
Definition FastSmallVector.hpp:93
FastSmallVector(const size_t numElem)
constructor based on the number of the element
Definition FastSmallVector.hpp:60
FastSmallVector(const FastSmallVector &other)
copy constructor
Definition FastSmallVector.hpp:75
ConstIterator cbegin() const
To support range-for etc.
Definition FastSmallVector.hpp:163
ConstIterator begin() const
To support range-for etc.
Definition FastSmallVector.hpp:155
ConstIterator cend() const
To support range-for etc.
Definition FastSmallVector.hpp:167
ValueType & operator[](size_t idx)
access the idx th element
Definition FastSmallVector.hpp:135
size_type size() const
number of elements
Definition FastSmallVector.hpp:145
Iterator begin()
To support range-for etc.
Definition FastSmallVector.hpp:171
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30