commit 2dedef6f6c1216985d73e00be1bc63758dac1bd3
parent ff57ed0d47a21614c0fd3f7f3be9d7a0233958e7
Author: Louis Burda <quent.burda@gmail.com>
Date: Sun, 2 Apr 2023 15:27:22 -0400
Rename _push_ api to _insert_
Diffstat:
2 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/include/list.h b/include/list.h
@@ -48,16 +48,16 @@ static inline bool list_empty(const struct list *list);
size_t list_len(const struct list *list);
ssize_t list_index(const struct list *list, const struct list_link *link);
-void list_insert_sorted(struct list *list, struct list_link *link, bool reverse,
- bool (*in_order)(struct list_link *a, struct list_link *b));
-void list_insertion_sort(struct list *list, bool reverse,
- bool (*in_order)(struct list_link *a, struct list_link *b));
-
struct list_link *list_at(struct list *list, size_t n);
struct list_link *list_at_back(struct list *list, size_t n);
-static inline void list_push_front(struct list *list, struct list_link *link);
-static inline void list_push_back(struct list *list, struct list_link *link);
+void list_insert_sorted(struct list *list, struct list_link *link, bool reverse,
+ bool (*in_order)(const struct list_link *a, const struct list_link *b));
+void list_insertion_sort(struct list *list, bool reverse,
+ bool (*in_order)(const struct list_link *a, const struct list_link *b));
+static inline void list_insert_front(struct list *list, struct list_link *link);
+static inline void list_insert_back(struct list *list, struct list_link *link);
+
struct list_link *list_pop_front(struct list *list);
struct list_link *list_pop_back(struct list *list);
@@ -111,7 +111,7 @@ list_link_inuse(const struct list_link *link)
}
static inline void
-list_push_front(struct list *list, struct list_link *link)
+list_insert_front(struct list *list, struct list_link *link)
{
LIST_ABORT_ON_ARGS(!list);
@@ -119,7 +119,7 @@ list_push_front(struct list *list, struct list_link *link)
}
static inline void
-list_push_back(struct list *list, struct list_link *link)
+list_insert_back(struct list *list, struct list_link *link)
{
LIST_ABORT_ON_ARGS(!list);
diff --git a/src/list.c b/src/list.c
@@ -67,9 +67,33 @@ list_index(const struct list *list, const struct list_link *target)
return -1;
}
+struct list_link *
+list_at(struct list *list, size_t n)
+{
+ struct list_link *link;
+
+ LIST_ABORT_ON_ARGS(!list);
+
+ link = list_iter_fwd(list->head.next, n);
+
+ return LIST_INNER(link) ? link : NULL;
+}
+
+struct list_link *
+list_at_back(struct list *list, size_t n)
+{
+ struct list_link *link;
+
+ LIST_ABORT_ON_ARGS(!list);
+
+ link = list_iter_bwd(&list->tail, n);
+
+ return LIST_INNER(link) ? link : NULL;
+}
+
void
list_insert_sorted(struct list *list, struct list_link *insert, bool reverse,
- bool (*in_order)(struct list_link *a, struct list_link *b))
+ bool (*in_order)(const struct list_link *a, const struct list_link *b))
{
struct list_link *link;
@@ -82,12 +106,12 @@ list_insert_sorted(struct list *list, struct list_link *insert, bool reverse,
}
}
- list_push_back(list, insert);
+ list_insert_back(list, insert);
}
void
list_insertion_sort(struct list *list, bool reverse,
- bool (*in_order)(struct list_link *a, struct list_link *b))
+ bool (*in_order)(const struct list_link *a, const struct list_link *b))
{
struct list_link *link, *cmp, *next;
@@ -109,30 +133,6 @@ list_insertion_sort(struct list *list, bool reverse,
}
struct list_link *
-list_at(struct list *list, size_t n)
-{
- struct list_link *link;
-
- LIST_ABORT_ON_ARGS(!list);
-
- link = list_iter_fwd(list->head.next, n);
-
- return LIST_INNER(link) ? link : NULL;
-}
-
-struct list_link *
-list_at_back(struct list *list, size_t n)
-{
- struct list_link *link;
-
- LIST_ABORT_ON_ARGS(!list);
-
- link = list_iter_bwd(&list->tail, n);
-
- return LIST_INNER(link) ? link : NULL;
-}
-
-struct list_link *
list_pop_front(struct list *list)
{
LIST_ABORT_ON_ARGS(!list);