Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 278 additions & 7 deletions bin/genEvalSpecializations.py

Large diffs are not rendered by default.

54 changes: 41 additions & 13 deletions opm/material/common/FastSmallVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class FastSmallVector
FastSmallVector& operator=(FastSmallVector&& other)
{
size_ = other.size_;
if (size_ <= N) {
if (other.usingSmallBuf()) {
smallBuf_ = std::move(other.smallBuf_);
dataPtr_ = smallBuf_.data();
}
Expand All @@ -119,7 +119,7 @@ class FastSmallVector
{
size_ = other.size_;

if (size_ <= N) {
if (other.usingSmallBuf()) {
smallBuf_ = other.smallBuf_;
dataPtr_ = smallBuf_.data();
}
Expand Down Expand Up @@ -176,20 +176,22 @@ class FastSmallVector
{ return dataPtr_ + size_; }

size_type capacity()
{ return size_ <= N ? N : data_.capacity(); }
{ return this->usingSmallBuf() ? N : data_.capacity(); }

void push_back(const ValueType& value)
{
if (size_ < N) {
// Data is contained in smallBuf_
smallBuf_[size_++] = value;
} else if (size_ == N) {
// Must switch from using smallBuf_ to using data_
data_.reserve(N + 1);
data_.assign(smallBuf_.begin(), smallBuf_.end());
data_.push_back(value);
++size_;
dataPtr_ = data_.data();
if (this->usingSmallBuf()) {
if (size_ < N) {
// Data is contained in smallBuf_
smallBuf_[size_++] = value;
} else if (size_ == N) {
// Must switch from using smallBuf_ to using data_
data_.reserve(N + 1);
data_.assign(smallBuf_.begin(), smallBuf_.end());
data_.push_back(value);
++size_;
dataPtr_ = data_.data();
}
} else {
// Data is contained in data_
data_.push_back(value);
Expand All @@ -198,6 +200,27 @@ class FastSmallVector
}
}

void resize(size_t numElem)
{
if (numElem == size_) return; // nothing to do

if (this->usingSmallBuf()) {
if (numElem > N) {
data_.resize(numElem);
std::copy(smallBuf_.begin(), smallBuf_.begin() + size_, data_.begin());
dataPtr_ = data_.data();
} else if (numElem < size_) {
// when shrinking, remove the values after numElem so that the space
// is ready to use in the potentional future resize
std::fill(smallBuf_.begin() + numElem, smallBuf_.begin() + size_, ValueType{});
}
} else {
// when shriking to numElem < N, we do not switch back to use smallBuf_
data_.resize(numElem);
}
size_ = numElem;
}

private:
void init_(size_t numElem)
{
Expand All @@ -210,6 +233,11 @@ class FastSmallVector
dataPtr_ = smallBuf_.data();
}

bool usingSmallBuf() const
{
return dataPtr_ == smallBuf_.data();
}

std::array<ValueType, N> smallBuf_{};
std::vector<ValueType> data_;
size_type size_;
Expand Down
Loading