tupperware: list: add 'empty' predicate

This commit is contained in:
Bruno BELANYI 2020-11-22 19:06:42 +01:00
parent 5dd1f5b739
commit ad1f130deb
2 changed files with 7 additions and 0 deletions

View file

@ -64,6 +64,7 @@ struct list_node *list_node_safe_detach(struct list_node **at);
struct list_node *list_pop_front(struct list *list); struct list_node *list_pop_front(struct list *list);
struct list_node *list_pop_back(struct list *list); struct list_node *list_pop_back(struct list *list);
bool list_empty(const struct list *list);
size_t list_length(const struct list *list); size_t list_length(const struct list *list);
void list_node_concat(struct list_node *begin, struct list_node *end); void list_node_concat(struct list_node *begin, struct list_node *end);

View file

@ -108,6 +108,12 @@ struct list_node *list_pop_back(struct list *list) {
return list_pop_front(list); return list_pop_front(list);
} }
bool list_empty(const struct list *list) {
if (!list)
return true;
return list->head == NULL;
}
size_t list_length(const struct list *list) { size_t list_length(const struct list *list) {
if (!list || !list->head) if (!list || !list->head)
return 0; return 0;