ref: 7d2f1a2d83df21f0520180537eba7f930bbdb7ee
dir: /array.c/
#include <u.h> #include <libc.h> #include <thread.h> #include "dat.h" #include "fns.h" /* This file is the only file that knows how arrays are stored. * In theory, that allows us to experiment with other representations later. */ struct Array { int rank; usize *shape; union { void *data; vlong *intdata; Rune *chardata; }; }; void initarrays(void) { dataspecs[DataArray].size = sizeof(Array); } Array * allocarray(int type, int rank, usize size) { Array *a = alloc(DataArray); a->rank = rank; switch(type){ case TypeNumber: size *= sizeof(vlong); break; case TypeChar: size *= sizeof(Rune); break; } a->shape = allocextra(a, (sizeof(usize) * rank) + size); a->data = (void*)(a->shape+rank); return a; } void setint(Array *a, usize offset, vlong v) { a->intdata[offset] = v; } void setshape(Array *a, int dim, usize size) { a->shape[dim] = size; }