Skip to content

Commit

Permalink
AddAndReadVector::operator[]
Browse files Browse the repository at this point in the history
  • Loading branch information
lixinqi committed Jun 13, 2022
1 parent a061c50 commit 1b0df76
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions oneflow/core/common/add_and_read_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AddAndReadVector {
AddAndReadVector() : size_(0) {}
~AddAndReadVector() = default;

using value_type = T;
using value_type = const T;
using size_type = size_t;

// not thread safe.
Expand All @@ -46,10 +46,7 @@ class AddAndReadVector {
return granularity2vector_[gran].data()[index - start];
}

// lock free.
T& at(size_t index) {
CHECK_GE(index, 0);
CHECK_LT(index, size_);
const T& operator[](size_t index) const {
int gran = GetGranularity(index);
int start = (1 << gran) - 1;
return granularity2vector_[gran].data()[index - start];
Expand Down
2 changes: 1 addition & 1 deletion oneflow/core/common/container_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Maybe<typename VecT::value_type&> VectorAt(VecT& vec, typename VecT::size_type i
static_assert(!std::is_same<typename VecT::value_type, bool>::value,
"VectorAt(vector<bool>&, size_t) is not supported.");
CHECK_LT_OR_RETURN(index, vec.size());
return vec.at(index);
return vec[index];
}

template<>
Expand Down

0 comments on commit 1b0df76

Please sign in to comment.