<commit_before>#include "dynar.h"

/**
 * @brief The function reallocates the dynamic array to increase the space.
 *
 * The array remains unchanged in the event of an error.
 *
 * @param[in]  da The array that should be destroyed.
 * @param[out] err Indicates what went wrong in the event of an error.
 *
 * @returns Returns 0 on success.
 * @returns Otherwise, -1 is returned and @p err is set appropriately.
 *
 * @b Errors @n
 * ::DA_OK on success. @n
 * ::DA_PARAM_ERR | ::DA_PARAM_NULL if @p da is a NULL-pointer. @n
 */
/*static int daRealloc(DaStruct *da, int *err) {
    return 0;
}*/

DaStruct *daCreate(DaDesc *desc, int *err)
{
    DaStruct *da;
    da = NULL;

    if (!err)
    {
        return NULL;
    }
    else if (!desc)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return NULL;
    }

    if (desc->elements == 0 || desc->bytesPerElement == 0)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return NULL;
    }

    da = calloc(1, sizeof(DaStruct) + (desc->elements * desc->bytesPerElement));

    if (!da)
    {
        goto err;
    }

    da->magic = DA_MAGIC;
    da->firstAddr = da + sizeof(DaStruct);
    da->lastAddr = da + sizeof(DaStruct) + (desc->elements * desc->bytesPerElement) - 1;
    da->freeAddr = da->firstAddr;
    da->used = 0;
    da->max = desc->elements;
    da->bytesPerElement = desc->bytesPerElement;

    *err = DA_OK;
    return da;

err:

    if (da)
    {
        da->magic = 0;
        free(da);
    }

    *err = DA_FATAL | DA_ENOMEM;
    return NULL;
}


int daDestroy(DaStruct *da, int *err)
{
    if (!err)
    {
        return -1;
    }
    else if (!da || da->magic != DA_MAGIC)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return -1;
    }

    memset(da, '0', sizeof(DaStruct) + (da->max * da->bytesPerElement));
    free(da);

    *err = DA_OK;
    return 0;
}


int daSize(DaStruct *da, int *err, size_t *size)
{
    if (!err)
    {
        return -1;
    }
    else if (!da || da->magic != DA_MAGIC || !size)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return -1;
    }

    *size = da->used;

    *err = DA_OK;
    return 0;
}


int daIsEmpty(DaStruct *da, int *err)
{
    if (!err)
    {
        return -1;
    }
    else if (!da || da->magic != DA_MAGIC)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return -1;
    }

    *err = DA_OK;
    return (da->used > 0) ? 0 : 1;
}

/**
 * @brief The function returns the element at @p pos.
 *
 * @param[in]  da      Get the element from this array.
 * @param[out] err     Indicates what went wrong in the event of an error.
 * @param[in]  pos     Get the @p element at this position from the array.
 *
 * @returns The function returns a pointer to the element on success.
 * @returns Otherwise, the function returns a NULL pointer and @p err is set appropriately.
 *
 * @b Errors @n
 * ::DA_OK on success. @n
 * ::DA_PARAM_ERR | ::DA_PARAM_NULL if @p da is a NULL-pointer. @n
 * ::DA_PARAM_ERR | ::DA_OUT_OF_BOUNDS if @p pos is out of the array bounds (@p pos >= DaSize()).
 */
void *daGet(DaStruct *da, int *err, size_t pos)
{
    if (!err)
    {
        return NULL;
    }
    else if (!da || da->magic != DA_MAGIC)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return NULL;
    }

    if (pos >= da->used)
    {
        *err = DA_PARAM_ERR | DA_OUT_OF_BOUNDS;
        return NULL;
    }<commit_msg>Removed daGet description in source file.<commit_after>#include "dynar.h"

/**
 * @brief The function reallocates the dynamic array to increase the space.
 *
 * The array remains unchanged in the event of an error.
 *
 * @param[in]  da The array that should be destroyed.
 * @param[out] err Indicates what went wrong in the event of an error.
 *
 * @returns Returns 0 on success.
 * @returns Otherwise, -1 is returned and @p err is set appropriately.
 *
 * @b Errors @n
 * ::DA_OK on success. @n
 * ::DA_PARAM_ERR | ::DA_PARAM_NULL if @p da is a NULL-pointer. @n
 */
/*static int daRealloc(DaStruct *da, int *err) {
    return 0;
}*/

DaStruct *daCreate(DaDesc *desc, int *err)
{
    DaStruct *da;
    da = NULL;

    if (!err)
    {
        return NULL;
    }
    else if (!desc)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return NULL;
    }

    if (desc->elements == 0 || desc->bytesPerElement == 0)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return NULL;
    }

    da = calloc(1, sizeof(DaStruct) + (desc->elements * desc->bytesPerElement));

    if (!da)
    {
        goto err;
    }

    da->magic = DA_MAGIC;
    da->firstAddr = da + sizeof(DaStruct);
    da->lastAddr = da + sizeof(DaStruct) + (desc->elements * desc->bytesPerElement) - 1;
    da->freeAddr = da->firstAddr;
    da->used = 0;
    da->max = desc->elements;
    da->bytesPerElement = desc->bytesPerElement;

    *err = DA_OK;
    return da;

err:

    if (da)
    {
        da->magic = 0;
        free(da);
    }

    *err = DA_FATAL | DA_ENOMEM;
    return NULL;
}


int daDestroy(DaStruct *da, int *err)
{
    if (!err)
    {
        return -1;
    }
    else if (!da || da->magic != DA_MAGIC)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return -1;
    }

    memset(da, '0', sizeof(DaStruct) + (da->max * da->bytesPerElement));
    free(da);

    *err = DA_OK;
    return 0;
}


int daSize(DaStruct *da, int *err, size_t *size)
{
    if (!err)
    {
        return -1;
    }
    else if (!da || da->magic != DA_MAGIC || !size)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return -1;
    }

    *size = da->used;

    *err = DA_OK;
    return 0;
}


int daIsEmpty(DaStruct *da, int *err)
{
    if (!err)
    {
        return -1;
    }
    else if (!da || da->magic != DA_MAGIC)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return -1;
    }

    *err = DA_OK;
    return (da->used > 0) ? 0 : 1;
}

void *daGet(DaStruct *da, int *err, size_t pos)
{
    if (!err)
    {
        return NULL;
    }
    else if (!da || da->magic != DA_MAGIC)
    {
        *err = DA_PARAM_ERR | DA_PARAM_NULL;
        return NULL;
    }

    if (pos >= da->used)
    {
        *err = DA_PARAM_ERR | DA_OUT_OF_BOUNDS;
        return NULL;
    }
{'fraction_non_alphanumeric': 0.1389159363842908, 'fraction_numerical': 0.006815968841285297, 'mean_word_length': 2.1220871327254307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5223868', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2223, 'n_words': 639}