2024-08-23 11:53:40 +02:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* Copyright (C) 2024 Thomas Kolb
|
|
|
|
*/
|
|
|
|
|
2024-05-30 11:00:34 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "logger.h"
|
2024-05-07 21:40:29 +02:00
|
|
|
|
|
|
|
#include "var_array.h"
|
|
|
|
|
|
|
|
bool var_array_cf_init(var_array_cf_t *array)
|
|
|
|
{
|
|
|
|
array->used = 0;
|
|
|
|
array->allocated = 64;
|
|
|
|
array->symbols = reallocarray(NULL, array->allocated, sizeof(float complex));
|
|
|
|
|
|
|
|
return (array->symbols != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void var_array_cf_free(var_array_cf_t *array)
|
|
|
|
{
|
|
|
|
if(array->symbols) {
|
|
|
|
free(array->symbols);
|
|
|
|
array->symbols = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
array->used = 0;
|
|
|
|
array->allocated = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void var_array_cf_clear(var_array_cf_t *array)
|
|
|
|
{
|
|
|
|
array->used = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool var_array_cf_append(var_array_cf_t *array, float complex symbol)
|
|
|
|
{
|
|
|
|
if(array->used == array->allocated) {
|
|
|
|
size_t new_size = 2 * array->allocated;
|
|
|
|
float complex *new_symbols = reallocarray(array->symbols, new_size, sizeof(float complex));
|
|
|
|
|
|
|
|
if(!new_symbols) {
|
2024-05-30 11:00:34 +02:00
|
|
|
LOG(LVL_ERR, "reallocarray: %s", strerror(errno));
|
2024-05-07 21:40:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
array->allocated = new_size;
|
|
|
|
array->symbols = new_symbols;
|
|
|
|
}
|
|
|
|
|
|
|
|
array->symbols[array->used++] = symbol;
|
|
|
|
return true;
|
|
|
|
}
|