/* Dynamic 2D Array Library; version 1.0 */ /* (c) copyright Ian Hickson 2000, distributed under the GNU GPL */ /* MANUAL: defining your array: array2d* array; defining a variable of the relevant type: type value; ...where type is "int", "float", "array2d", or whatever. allocate the array: array = allocArray2D(width, height, sizeof(type)); set a place in the array to a particular value: value = (something); setArray2D(array, x, y, &value); get a particular value: value = *(type*)getArray2D(array, x, y); make a copy of an array: array2d* newarray; newarray = cloneArray2D(array) swap rows 2 and 3: permuteRowsArray2D(array, 2, 3); free the array: freeArray2D(array); freeArray2D(newarray); that's it. */ /* WARNING! In the interests of speed, this library does no serious error checking! (Note: You can disable error checking altogether by disabling asserts when compiling.) */ typedef char byte; /* SizeOf(byte) MUST equal 1! */ /* internal representation of the array */ typedef struct ARRAY2D { int elementSize; int width, height; byte* array; } array2d; /* interface functions */ extern array2d* allocArray2D(int width, int height, int elementSize); extern array2d* cloneArray2D(array2d* source); extern void* getPointerArray2D(array2d* array, int x, int y); extern void freeArray2D(array2d* array); extern void setArray2D(array2d* array, int x, int y, void* value); extern void* getArray2D(array2d* array, int x, int y); extern void permuteRowsArray2D(array2d* array, int y1, int y2); /* end */