2021-01-07 13:07:16 -06:00
|
|
|
#ifndef STRING_ARRAY_H
|
|
|
|
#define STRING_ARRAY_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
struct str_array {
|
2021-01-07 14:34:44 -06:00
|
|
|
/* strings in the array */
|
2021-01-07 15:17:20 -06:00
|
|
|
char **v;
|
2021-01-07 14:34:44 -06:00
|
|
|
/* flag to say if they fit a certain condition or not */
|
2021-01-07 13:07:16 -06:00
|
|
|
bool *m;
|
2021-01-07 14:34:44 -06:00
|
|
|
/* total number of true in m */
|
|
|
|
size_t ms;
|
|
|
|
/* number of elements, maximum number of elements */
|
2021-01-07 13:07:16 -06:00
|
|
|
size_t n, c;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-07 15:17:20 -06:00
|
|
|
static inline char *get_entry(const struct str_array *a, size_t i)
|
2021-01-07 13:07:16 -06:00
|
|
|
{
|
|
|
|
return a->v[i];
|
|
|
|
}
|
|
|
|
|
2021-01-07 14:34:44 -06:00
|
|
|
static inline bool get_entry_match(const struct str_array *a, size_t i)
|
2021-01-07 13:07:16 -06:00
|
|
|
{
|
2021-01-07 14:34:44 -06:00
|
|
|
return a->m[i];
|
|
|
|
}
|
|
|
|
|
2021-01-07 15:17:20 -06:00
|
|
|
static inline char *get_entry_if_match(const struct str_array *a, size_t i)
|
2021-01-07 14:34:44 -06:00
|
|
|
{
|
|
|
|
return get_entry_match(a, i) ? a->v[i] : NULL;
|
2021-01-07 13:07:16 -06:00
|
|
|
}
|
|
|
|
|
2021-01-07 15:17:20 -06:00
|
|
|
void add_entry(struct str_array *, char *);
|
|
|
|
char *pop_entry(struct str_array *);
|
|
|
|
void filter_entries(struct str_array *, const struct str_array *);
|
2021-01-07 17:57:22 -06:00
|
|
|
void sort_entries(struct str_array *);
|
2021-01-07 13:07:16 -06:00
|
|
|
void print_entries(const struct str_array *);
|
|
|
|
|
|
|
|
#endif
|