Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1 | #include "xyarray.h" |
| 2 | #include "util.h" |
Arnaldo Carvalho de Melo | 72f7c4d | 2017-04-19 19:06:30 -0300 | [diff] [blame] | 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 5 | |
| 6 | struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) |
| 7 | { |
| 8 | size_t row_size = ylen * entry_size; |
| 9 | struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size); |
| 10 | |
| 11 | if (xy != NULL) { |
| 12 | xy->entry_size = entry_size; |
| 13 | xy->row_size = row_size; |
Jiri Olsa | b45f65e | 2015-06-14 10:19:16 +0200 | [diff] [blame] | 14 | xy->entries = xlen * ylen; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | return xy; |
| 18 | } |
| 19 | |
Jiri Olsa | b45f65e | 2015-06-14 10:19:16 +0200 | [diff] [blame] | 20 | void xyarray__reset(struct xyarray *xy) |
| 21 | { |
| 22 | size_t n = xy->entries * xy->entry_size; |
| 23 | |
| 24 | memset(xy->contents, 0, n); |
| 25 | } |
| 26 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 27 | void xyarray__delete(struct xyarray *xy) |
| 28 | { |
| 29 | free(xy); |
| 30 | } |