MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / SetOrAdd

Method SetOrAdd

oneflow/core/common/steady_vector.h:55–70  ·  view source on GitHub ↗

`index` should be <= size()

Source from the content-addressed store, hash-verified

53
54 // `index` should be <= size()
55 void SetOrAdd(size_t index, T value) {
56 std::unique_lock<std::mutex> lock(mutex_);
57 size_t size = size_.load(std::memory_order_relaxed);
58 CHECK_LE(index, size) << "index out of range";
59 if (index == size) {
60 int granularity = GetGranularity(size);
61 if (size + 1 == (1 << granularity)) {
62 CHECK_LT(granularity, N);
63 granularity2data_[granularity].reset(new T[1 << granularity]);
64 }
65 *Mutable(index) = std::move(value);
66 size_.fetch_add(1, std::memory_order_release);
67 } else {
68 *Mutable(index) = std::move(value);
69 }
70 }
71
72 void push_back(const T& elem) { SetOrAdd(size_, elem); }
73

Callers 1

GetVmStreamMethod · 0.80

Calls 2

loadMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected