Skip to content

Commit

Permalink
Updates compressed_vector class.
Browse files Browse the repository at this point in the history
* Adds new constructor for dense intialization
* Fixes bug in resize when extending vector size with non-zero value
* Fixes bug in stride_reduce when vector has no non-zero values
  • Loading branch information
jonathonl committed Feb 3, 2021
1 parent 71e8918 commit 6c8cf49
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions include/savvy/compressed_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ namespace savvy
resize(sz);
}

/**
* Constructs compressed_vector class and initializes with dense data.
* @param val_it Begin iterator
* @param val_end End iterator
*/
template <typename ValT>
compressed_vector(ValT val_it, ValT val_end)
{
assign(val_it, val_end);
}

/**
* Constructs compressed_vector class and initializes with sparse data.
* @param val_it Begin iterator of non-zero values
Expand Down Expand Up @@ -358,10 +369,13 @@ namespace savvy
}
else if (val != value_type())
{
values_.resize(sz, val);
values_.reserve(values_.size() + (sz - size_));
offsets_.reserve(offsets_.size() + (sz - size_));
for (std::size_t i = size_; i < sz; ++i)
{
offsets_.emplace_back(i);
values_.emplace_back(val);
}
}

size_ = sz;
Expand Down Expand Up @@ -521,8 +535,8 @@ namespace savvy

vec.offsets_.resize(dest_idx + 1);
vec.values_.resize(dest_idx + 1);
vec.size_ = vec.size_ / stride;
}
vec.size_ = vec.size_ / stride;
}
private:
std::vector<value_type> values_;
Expand Down

0 comments on commit 6c8cf49

Please sign in to comment.