added new float array function and function definition to the header
This commit is contained in:
12
src/arrays.c
12
src/arrays.c
@@ -1,5 +1,6 @@
|
|||||||
#include "arrays.h"
|
#include "arrays.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
bool bool_array_get(const bool_array *array, int32_t index) {
|
bool bool_array_get(const bool_array *array, int32_t index) {
|
||||||
if (index >= 0 && index < array->length) {
|
if (index >= 0 && index < array->length) {
|
||||||
@@ -280,12 +281,23 @@ void float_array_set(float_array *array, const float value, int32_t index) {
|
|||||||
|
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
array->items[array->length - 1] = value;
|
array->items[array->length - 1] = value;
|
||||||
|
array->length++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
array->items[index] = value;
|
array->items[index] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void float_array_allocate(float_array *array, int32_t capacity) {
|
||||||
|
array->items = calloc(capacity, sizeof(float));
|
||||||
|
array->capacity = capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void float_array_init(float_array *array) {
|
||||||
|
array->capacity = 0;
|
||||||
|
array->length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
double double_array_get(const double_array *array, int32_t index) {
|
double double_array_get(const double_array *array, int32_t index) {
|
||||||
if (index >= 0 && index < array->length) {
|
if (index >= 0 && index < array->length) {
|
||||||
return array->items[index];
|
return array->items[index];
|
||||||
|
|||||||
14
src/arrays.h
14
src/arrays.h
@@ -12,6 +12,7 @@ typedef struct {
|
|||||||
} bool_array;
|
} bool_array;
|
||||||
|
|
||||||
bool bool_array_get(const bool_array *array, int32_t index);
|
bool bool_array_get(const bool_array *array, int32_t index);
|
||||||
|
void bool_array_set(bool_array *array, const bool value, int32_t index);
|
||||||
|
|
||||||
// --- Char (Strings/Bytes) ---
|
// --- Char (Strings/Bytes) ---
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -21,6 +22,7 @@ typedef struct {
|
|||||||
} char_array;
|
} char_array;
|
||||||
|
|
||||||
char char_array_get(const char_array *array, int32_t index);
|
char char_array_get(const char_array *array, int32_t index);
|
||||||
|
void char_array_set(char_array *array, const char value, int32_t index);
|
||||||
|
|
||||||
// --- Signed Integers ---
|
// --- Signed Integers ---
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -30,6 +32,7 @@ typedef struct {
|
|||||||
} int8_array;
|
} int8_array;
|
||||||
|
|
||||||
int8_t int8_array_get(const int8_array *array, int32_t index);
|
int8_t int8_array_get(const int8_array *array, int32_t index);
|
||||||
|
void int8_array_set(int8_array *array, const int8_t value, int32_t index);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int16_t *items;
|
int16_t *items;
|
||||||
@@ -38,6 +41,7 @@ typedef struct {
|
|||||||
} int16_array;
|
} int16_array;
|
||||||
|
|
||||||
int16_t int16_array_get(const int16_array *array, int32_t index);
|
int16_t int16_array_get(const int16_array *array, int32_t index);
|
||||||
|
void int16_array_set(int16_array *array, const int16_t value, int32_t index);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t *items;
|
int32_t *items;
|
||||||
@@ -46,6 +50,7 @@ typedef struct {
|
|||||||
} int32_array;
|
} int32_array;
|
||||||
|
|
||||||
int32_t int32_array_get(const int32_array *array, int32_t index);
|
int32_t int32_array_get(const int32_array *array, int32_t index);
|
||||||
|
void int32_array_set(int32_array *array, const int32_t value, int32_t index);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t *items;
|
int64_t *items;
|
||||||
@@ -54,6 +59,7 @@ typedef struct {
|
|||||||
} int64_array;
|
} int64_array;
|
||||||
|
|
||||||
int64_t int64_array_get(const int64_array *array, int32_t index);
|
int64_t int64_array_get(const int64_array *array, int32_t index);
|
||||||
|
void int64_array_set(int64_array *array, const int64_t value, int32_t index);
|
||||||
|
|
||||||
// --- Unsigned Integers ---
|
// --- Unsigned Integers ---
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -63,6 +69,7 @@ typedef struct {
|
|||||||
} uint8_array;
|
} uint8_array;
|
||||||
|
|
||||||
uint8_t uint8_array_get(const uint8_array *array, int32_t index);
|
uint8_t uint8_array_get(const uint8_array *array, int32_t index);
|
||||||
|
void uint8_array_set(uint8_array *array, const uint8_t value, int32_t index);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t *items;
|
uint16_t *items;
|
||||||
@@ -71,6 +78,7 @@ typedef struct {
|
|||||||
} uint16_array;
|
} uint16_array;
|
||||||
|
|
||||||
uint16_t uint16_array_get(const uint16_array *array, int32_t index);
|
uint16_t uint16_array_get(const uint16_array *array, int32_t index);
|
||||||
|
void uint16_array_set(uint16_array *array, const uint16_t value, int32_t index);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t *items;
|
uint32_t *items;
|
||||||
@@ -79,6 +87,7 @@ typedef struct {
|
|||||||
} uint32_array;
|
} uint32_array;
|
||||||
|
|
||||||
uint32_t uint32_array_get(const uint32_array *array, int32_t index);
|
uint32_t uint32_array_get(const uint32_array *array, int32_t index);
|
||||||
|
void uint32_array_set(uint32_array *array, const uint32_t value, int32_t index);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t *items;
|
uint64_t *items;
|
||||||
@@ -87,6 +96,7 @@ typedef struct {
|
|||||||
} uint64_array;
|
} uint64_array;
|
||||||
|
|
||||||
uint64_t uint64_array_get(const uint64_array *array, int32_t index);
|
uint64_t uint64_array_get(const uint64_array *array, int32_t index);
|
||||||
|
void uint64_array_set(uint64_array *array, const uint64_t value, int32_t index);
|
||||||
|
|
||||||
// --- Floating Point ---
|
// --- Floating Point ---
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -96,6 +106,9 @@ typedef struct {
|
|||||||
} float_array;
|
} float_array;
|
||||||
|
|
||||||
float float_array_get(const float_array *array, int32_t index);
|
float float_array_get(const float_array *array, int32_t index);
|
||||||
|
void float_array_set(float_array *array, const float value, int32_t index);
|
||||||
|
void float_array_allocate(float_array *array, int32_t capacity);
|
||||||
|
void float_array_init(float_array *array);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
double *items;
|
double *items;
|
||||||
@@ -104,5 +117,6 @@ typedef struct {
|
|||||||
} double_array;
|
} double_array;
|
||||||
|
|
||||||
double double_array_get(const double_array *array, int32_t index);
|
double double_array_get(const double_array *array, int32_t index);
|
||||||
|
void double_array_set(double_array *array, const double value, int32_t index);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user