12 #ifndef SMALLMATRIX_TYPE_HPP
13 #define SMALLMATRIX_TYPE_HPP
80 if (&other ==
this)
return;
82 this->
height = other.Height();
83 this->
width = other.Width();
88 this->
data = MallocT<T>(num_items);
90 }
else if (num_items > 0) {
124 if (capacity >= this->capacity)
return;
135 if (x < --this->
width) {
149 if (count == 0)
return;
150 assert(x < this->
width);
151 assert(x + count <= this->width);
152 this->width -= count;
153 uint to_move = (this->width - x) * this->
height;
156 this->
data + (x + count) * this->height, to_move);
166 if (y < this->
height - 1) {
167 for (uint x = 0; x < this->
width; ++x) {
182 if (this->
height > count + y) {
183 for (uint x = 0; x < this->
width; ++x) {
186 this->
height - count - y);
216 inline void Resize(uint new_width, uint new_height)
218 uint new_capacity = new_width * new_height;
220 void (*copy)(T *dest,
const T *src,
size_t count) = NULL;
221 if (new_capacity > this->
capacity) {
223 new_data = MallocT<T>(new_capacity);
227 new_data = this->
data;
230 if (this->
height != new_height || new_data != this->
data) {
232 if (new_height > this->
height) {
235 for (uint x = this->
width; x > 0; --x) {
236 if (x * new_height > new_capacity)
continue;
237 (*copy)(new_data + (x - 1) * new_height,
239 min(this->height, new_height));
243 for (uint x = 0; x < this->
width; ++x) {
244 if ((x + 1) * new_height > new_capacity)
break;
245 (*copy)(new_data + x * new_height,
247 min(this->height, new_height));
251 this->
height = new_height;
252 if (new_data != this->
data) {
254 this->
data = new_data;
258 this->
width = new_width;
261 inline uint Height()
const
266 inline uint Width()
const
278 inline const T &
Get(uint x, uint y)
const
281 return this->
data[x * this->height + y];
291 inline T &
Get(uint x, uint y)
294 return this->
data[x * this->height + y];
305 assert(x < this->
width);
317 assert(x < this->
width);