MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / reset

Method reset

common/unordered_inline_set.h:45–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43public:
44 SparseArray(size_t capacity) { reset(capacity); }
45 void* reset(size_t new_capacity) {
46 if (_size > 0)
47 for (auto x: *this) ((T&)x).~T();
48 if (new_capacity == _capacity)
49 return buf();
50 auto s = get_s(new_capacity) * sizeof(T);
51 if (new_capacity > 0) {
52 auto ptr = realloc(buf(), s + new_capacity * sizeof(T));
53 memset(ptr, 0, s);
54 _ptr = (T*)((char*)ptr + s);
55 _capacity = new_capacity;
56 _size = 0;
57 return ptr;
58 } else {
59 free(buf());
60 _capacity = _size = 0;
61 return _ptr = nullptr;
62 }
63 }
64 SparseArray(SparseArray&& rhs) { *this = std::move(rhs); }
65 void operator=(SparseArray&& rhs) {
66 reset(0);

Callers 4

assignMethod · 0.45
_rehashMethod · 0.45
rehashMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected