18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include "xyarray.h" 38c2ecf20Sopenharmony_ci#include <stdlib.h> 48c2ecf20Sopenharmony_ci#include <string.h> 58c2ecf20Sopenharmony_ci#include <linux/zalloc.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_cistruct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) 88c2ecf20Sopenharmony_ci{ 98c2ecf20Sopenharmony_ci size_t row_size = ylen * entry_size; 108c2ecf20Sopenharmony_ci struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size); 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci if (xy != NULL) { 138c2ecf20Sopenharmony_ci xy->entry_size = entry_size; 148c2ecf20Sopenharmony_ci xy->row_size = row_size; 158c2ecf20Sopenharmony_ci xy->entries = xlen * ylen; 168c2ecf20Sopenharmony_ci xy->max_x = xlen; 178c2ecf20Sopenharmony_ci xy->max_y = ylen; 188c2ecf20Sopenharmony_ci } 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci return xy; 218c2ecf20Sopenharmony_ci} 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_civoid xyarray__reset(struct xyarray *xy) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci size_t n = xy->entries * xy->entry_size; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci memset(xy->contents, 0, n); 288c2ecf20Sopenharmony_ci} 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_civoid xyarray__delete(struct xyarray *xy) 318c2ecf20Sopenharmony_ci{ 328c2ecf20Sopenharmony_ci free(xy); 338c2ecf20Sopenharmony_ci} 34