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(dataPtr_, dataPtr_ + size_, value);
78 dataPtr_ = smallBuf_.data();
87 dataPtr_ = smallBuf_.data();
89 (*this) = std::move(other);
103 smallBuf_ = std::move(other.smallBuf_);
104 dataPtr_ = smallBuf_.data();
107 data_ = std::move(other.data_);
108 dataPtr_ = data_.data();
111 other.dataPtr_ =
nullptr;
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 size_ <= N ? N : data_.capacity(); }
181 void push_back(
const ValueType& value)
185 smallBuf_[size_++] = value;
186 }
else if (size_ == N) {
188 data_.reserve(N + 1);
189 data_.assign(smallBuf_.begin(), smallBuf_.end());
190 data_.push_back(value);
192 dataPtr_ = data_.data();
195 data_.push_back(value);
197 dataPtr_ = data_.data();
202 void init_(
size_t numElem)
208 dataPtr_ = data_.data();
210 dataPtr_ = smallBuf_.data();
213 std::array<ValueType, N> smallBuf_{};
214 std::vector<ValueType> data_;
An implementation of vector/array based on small object optimization.
Definition FastSmallVector.hpp:50
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