<commit_before>#ifndef COMMON_H
#define COMMON_H

#include <stdlib.h>
#include "defs.h"

__BEGIN_DECLS

#define DEGREE(d) ((d) * M_PI / 180.0)
#define SQR(x) ((x) * (x))

#ifdef DEBUG_MEM
#define emalloc(n) malloc((size_t) (n))
#define erealloc(x,n) realloc(x,(size_t) (n))
#else
extern void *   emalloc(int n);
extern void *   erealloc(void *p, int n);
#endif

#ifdef WIN32
#define DIR_SEPARATOR '\\'
#else
#define DIR_SEPARATOR '/'
#endif

struct generic_array {
    size_t number;
    size_t alloc;
    void *heap;
};

extern void   generic_array_check_alloc(struct generic_array *s, int index,
                                        size_t data_size);
extern void * generic_array_new(size_t data_size, size_t nb);
extern void   generic_array_free(struct generic_array *r);

#define ARRAY_CHECK_ALLOC(s,dtype,idx) generic_array_check_alloc((struct generic_array *) (s),idx,sizeof(dtype))
#define ARRAY_NEW(dtype) generic_array_new(sizeof(dtype), 8)
#define ARRAY_FREE(s) generic_array_free(s)

__END_DECLS
<commit_msg>Add macro to access generic array elements<commit_after>#ifndef COMMON_H
#define COMMON_H

#include <stdlib.h>
#include "defs.h"

__BEGIN_DECLS

#define DEGREE(d) ((d) * M_PI / 180.0)
#define SQR(x) ((x) * (x))

#ifdef DEBUG_MEM
#define emalloc(n) malloc((size_t) (n))
#define erealloc(x,n) realloc(x,(size_t) (n))
#else
extern void *   emalloc(int n);
extern void *   erealloc(void *p, int n);
#endif

#ifdef WIN32
#define DIR_SEPARATOR '\\'
#else
#define DIR_SEPARATOR '/'
#endif

struct generic_array {
    size_t number;
    size_t alloc;
    void *heap;
};

extern void   generic_array_check_alloc(struct generic_array *s, int index,
                                        size_t data_size);
extern void * generic_array_new(size_t data_size, size_t nb);
extern void   generic_array_free(struct generic_array *r);

#define ARRAY_CHECK_ALLOC(s,dtype,idx) generic_array_check_alloc((struct generic_array *) (s),idx,sizeof(dtype))
#define ARRAY_NEW(dtype) generic_array_new(sizeof(dtype), 8)
#define ARRAY_FREE(s) generic_array_free(s)
#define ARRAY_GET(arr, dtype, i) ((dtype *) (arr)->heap)[i]
#define ARRAY_SET(arr, dtype, i, v) ((dtype *) (arr)->heap)[i] = (v)
#define ARRAY_GET_PTR(arr, dtype, i) (((dtype *) (arr)->heap) + (i))

__END_DECLS

{'fraction_non_alphanumeric': 0.13782474680757376, 'fraction_numerical': 0.006164685160722149, 'mean_word_length': 4.855670103092783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6995176', 'n_tokens_mistral': 883, 'n_tokens_neox': 867, 'n_words': 205}