Thomas Kolb
2e91fd7c42
All code is now licensed under GPLv3+. The documentation is licensed under CC BY-SA 4.0. This is now officially free software! \o/
58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
/*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* Copyright (C) 2024 Thomas Kolb
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
|
|
#include "logger.h"
|
|
|
|
#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) {
|
|
LOG(LVL_ERR, "reallocarray: %s", strerror(errno));
|
|
return false;
|
|
}
|
|
|
|
array->allocated = new_size;
|
|
array->symbols = new_symbols;
|
|
}
|
|
|
|
array->symbols[array->used++] = symbol;
|
|
return true;
|
|
}
|