10 #ifndef SMALLMATRIX_TYPE_HPP
11 #define SMALLMATRIX_TYPE_HPP
78 if (&other ==
this)
return;
80 this->height = other.Height();
81 this->width = other.Width();
82 uint num_items = this->width * this->
height;
83 if (num_items > this->capacity) {
84 this->capacity = num_items;
86 this->data = MallocT<T>(num_items);
87 MemCpyT(this->data, other[0], num_items);
88 }
else if (num_items > 0) {
89 MemCpyT(this->data, other[0], num_items);
113 this->data =
nullptr;
122 if (capacity >= this->capacity)
return;
124 this->data =
ReallocT(this->data, this->capacity);
133 if (x < --this->
width) {
134 MemCpyT<T>(this->data + x * this->height,
135 this->data + this->width * this->height,
147 if (count == 0)
return;
148 assert(x < this->
width);
149 assert(x + count <= this->
width);
150 this->width -= count;
151 uint to_move = (this->width - x) * this->height;
153 MemMoveT(this->data + x * this->height,
154 this->data + (x + count) * this->height, to_move);
164 if (y < this->
height - 1) {
165 for (uint x = 0; x < this->
width; ++x) {
166 this->data[x * this->height + y] =
167 this->data[(x + 1) * this->height - 1];
170 this->
Resize(this->width, this->height - 1);
180 if (this->height > count + y) {
181 for (uint x = 0; x < this->
width; ++x) {
182 MemMoveT(this->data + x * this->height + y,
183 this->data + x * this->height + y + count,
184 this->height - count - y);
187 this->
Resize(this->width, this->height - count);
196 this->
Resize(this->width, to_add + this->height);
205 this->
Resize(to_add + this->width, this->height);
214 inline void Resize(uint new_width, uint new_height)
216 uint new_capacity = new_width * new_height;
217 T *new_data =
nullptr;
218 void (*copy)(T *dest,
const T *src,
size_t count) =
nullptr;
219 if (new_capacity > this->capacity) {
221 new_data = MallocT<T>(new_capacity);
225 new_data = this->
data;
228 if (this->height != new_height || new_data != this->data) {
229 if (this->height > 0) {
230 if (new_height > this->height) {
233 for (uint x = this->width; x > 0; --x) {
234 if (x * new_height > new_capacity)
continue;
235 (*copy)(new_data + (x - 1) * new_height,
236 this->data + (x - 1) * this->
height,
237 std::min(this->height, new_height));
241 for (uint x = 0; x < this->
width; ++x) {
242 if ((x + 1) * new_height > new_capacity)
break;
243 (*copy)(new_data + x * new_height,
244 this->data + x * this->
height,
245 std::min(this->height, new_height));
249 this->height = new_height;
250 if (new_data != this->data) {
252 this->data = new_data;
253 this->capacity = new_capacity;
256 this->width = new_width;
259 inline uint Height()
const
264 inline uint Width()
const
276 inline const T &
Get(uint x, uint y)
const
279 return this->data[x * this->height + y];
289 inline T &
Get(uint x, uint y)
292 return this->data[x * this->height + y];
303 assert(x < this->
width);
304 return this->data + x * this->
height;
315 assert(x < this->
width);
316 return this->data + x * this->
height;