39 unsigned int num()
const
52 T*
at(
unsigned int pos)
const;
58 unsigned int _capacity;
60 unsigned int _BLOCKSIZE;
62 std::vector<T*> _block;
64 std::vector<unsigned int> _deleted;
76 template <
typename T>
using object_reset_t =
decltype(std::declval<T&>().reset());
88 const unsigned int iBS = init / _BLOCKSIZE + 1;
90 for (
unsigned int i = 0;
i <
iBS;
i++) {
91 _block[
i] =
new T[_BLOCKSIZE];
93 _capacity =
iBS * _BLOCKSIZE;
106 *
this = std::move(
other);
111 _length =
other._length;
113 _capacity =
other._capacity;
115 _BLOCKSIZE =
other._BLOCKSIZE;
116 other._BLOCKSIZE = 0;
117 _block = std::move(
other._block);
118 _deleted = std::move(
other._deleted);
127 for (
size_t i = 0;
i < _block.size();
i++) {
134 _length = _capacity = 0;
145 _capacity += _BLOCKSIZE;
154 if (!_deleted.empty()) {
155 *pos = _deleted.back();
157 elem = &(_block[*pos / _BLOCKSIZE][*pos % _BLOCKSIZE]);
162 static_assert(WEMInternal::has_reset_v<T>,
163 "Type T must implement ::reset() to reset the object back to the default constructed state.");
169 if (_length == _capacity) {
173 elem = &(_block[_length / _BLOCKSIZE][_length % _BLOCKSIZE]);
184 _deleted.push_back(pos);
203 return &(_block[pos / _BLOCKSIZE][pos % _BLOCKSIZE]);
unsigned int num() const
Returns the number of elements in this vector.
WEMObjectVector(unsigned int init=0, unsigned int bs=8192)
Standard constructor.
void createNumObjects(unsigned int numObjects)
Creates the given number of objects.
WEMObjectVector & operator=(WEMObjectVector &&other) noexcept
Move assignment operator.
T * at(unsigned int pos) const
Returns the element at the given position.
void destroy()
Deletes all elements in this vector.
T * append(unsigned int *pos)
Appends an element to this vector and returns a pointer to it.
~WEMObjectVector()
Standard destructor.
void deleteAt(unsigned int pos)
Deletes an element at the given position.
WEMObjectVector(WEMObjectVector &&other) noexcept
Move c'tor.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
constexpr bool has_reset_v
decltype(std::declval< T & >().reset()) object_reset_t