Arrays

For working with arrays (currently mainly supports 1D vectors) (Git Repo with Notes)


Types and Macros

struct Vector = {DataType dtype, int size, Data values}


percentile_method

This is an enum used by percentile_vector function to label the various methods of finding the percentile. (Currently, the function only supports INVERTED_CDF, LINEAR)

#define LENGTH_ARR(arr) sizeof(arr) / sizeof(*arr)

This gives the size of a 1-D array.

To view arrays and vectors

void view_array(int size, precision_t arr[])

void view_vector(Vector *A)

Initialising arrays and vectors

Vector *zero_vector(DataType dtype, int size)

Returns a vector of the given type and size with all elements as zero.

                                        Vector *A_int = zero_vector(INT, 5);
                                        Vector *A_prec = zero_vector(PREC, 5);
                                        Vector *A_str = zero_vector(STRING, 5);

                                        view_vector(A_int);
                                        view_vector(A_prec);
                                        view_vector(A_str);

                                        ```OUTPUT```

                                        5-element Vector {int}
                                        [ 0 , 0 , 0 , 0 , 0 ]

                                        5-element Vector {precision_t}

                                        [ 0.000000 , 0.000000 , 0.000000 , 0.000000 , 0.000000 ]
                                        
                                        5-element Vector {string}
                                        [ 0 , 0 , 0 , 0 , 0 ]


                           

void free_vector(Vector *V)

Function to free memory assigned to vector V.

Vector *ones_vector(DataType dtype, int size)

Returns a vector of the given type and size with all elements as ones.

                                        Vector *A_int = zero_vector(INT, 5);
                                        Vector *A_prec = zero_vector(PREC, 5);
                                        Vector *A_str = zero_vector(STRING, 5);

                                        view_vector(A_int);
                                        view_vector(A_prec);
                                        view_vector(A_str);

                                        ```OUTPUT```

                                        5-element Vector {int}
                                        [ 1 , 1 , 1 , 1 , 1 ]

                                        5-element Vector {precision_t}

                                        [ 1.000000 , 1.000000 , 1.000000 , 1.000000 , 1.000000 ]
                                        
                                        5-element Vector {string}
                                        [ 1 , 1 , 1 , 1 , 1 ]