Ruby: prism/util/pm_list.c Source File

Ruby 3.3.7p123 (2025-01-15 revision be31f993d7fa0219d85f7b3c694d454da4ecc10b)

pm_list.c
1#include "prism/util/pm_list.h"
2
6 PRISM_EXPORTED_FUNCTION bool
7pm_list_empty_p(pm_list_t *list) {
8 return list->head == NULL;
9}
10
14 PRISM_EXPORTED_FUNCTION size_t
15pm_list_size(pm_list_t *list) {
16 return list->size;
17}
18
22void
23pm_list_append(pm_list_t *list, pm_list_node_t *node) {
24 if (list->head == NULL) {
25 list->head = node;
26 } else {
27 list->tail->next = node;
28 }
29
30 list->tail = node;
31 list->size++;
32}
33
37 PRISM_EXPORTED_FUNCTION void
38pm_list_free(pm_list_t *list) {
39 pm_list_node_t *node = list->head;
40 pm_list_node_t *next;
41
42 while (node != NULL) {
43 next = node->next;
44 free(node);
45 node = next;
46 }
47
48 list->size = 0;
49}
pm_list.h
An abstract linked list.
pm_list_node_t
struct pm_list_node pm_list_node_t
This struct represents an abstract linked list that provides common functionality.
PRISM_EXPORTED_FUNCTION
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition defines.h:32
pm_list_node::next
struct pm_list_node * next
A pointer to the next node in the list.
Definition pm_list.h:48
pm_list_t
This represents the overall linked list.
Definition pm_list.h:55
pm_list_t::tail
pm_list_node_t * tail
A pointer to the tail of the list.
Definition pm_list.h:63
pm_list_t::head
pm_list_node_t * head
A pointer to the head of the list.
Definition pm_list.h:60
pm_list_t::size
size_t size
The size of the list.
Definition pm_list.h:57