开始设计
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#include <c_Vector.h>
|
||||
#include <c_Memory.h>
|
||||
|
||||
/**
|
||||
* Initialize an N-dimensional Euclidean Vector.
|
||||
*/
|
||||
c_err_t c_Vector_Init(c_Vector_t* vec, c_size_t dimensions) {
|
||||
if (vec == NULL || dimensions == 0) return C_ERR_PARAM;
|
||||
|
||||
vec->dimensions = dimensions;
|
||||
vec->components = (double*)C_ALLOC(dimensions * sizeof(double));
|
||||
if (vec->components == NULL) return C_ERR_NOMEM;
|
||||
|
||||
memset(vec->components, 0, dimensions * sizeof(double));
|
||||
return C_ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up allocations within the vector wrapper safely.
|
||||
*/
|
||||
void c_Vector_Destroy(c_Vector_t* vec) {
|
||||
if (vec) {
|
||||
if (vec->components) {
|
||||
C_FREE(vec->components);
|
||||
vec->components = NULL;
|
||||
}
|
||||
vec->dimensions = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user