cpython/Include/internal/pycore_llist.h

// A doubly-linked list that can be embedded in a struct.
//
// Usage:
//  struct llist_node head = LLIST_INIT(head);
//  typedef struct {
//      ...
//      struct llist_node node;
//      ...
//  } MyObj;
//
//  llist_insert_tail(&head, &obj->node);
//  llist_remove(&obj->node);
//
//  struct llist_node *node;
//  llist_for_each(node, &head) {
//      MyObj *obj = llist_data(node, MyObj, node);
//      ...
//  }
//

#ifndef Py_INTERNAL_LLIST_H
#define Py_INTERNAL_LLIST_H

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef Py_BUILD_CORE
#  error "Py_BUILD_CORE must be defined to include this header"
#endif

struct llist_node {};

// Get the struct containing a node.
#define llist_data(node, type, member)

// Iterate over a list.
#define llist_for_each(node, head)

// Iterate over a list, but allow removal of the current node.
#define llist_for_each_safe(node, head)

#define LLIST_INIT(head)

static inline void
llist_init(struct llist_node *head)
{}

// Returns 1 if the list is empty, 0 otherwise.
static inline int
llist_empty(struct llist_node *head)
{}

// Appends to the tail of the list.
static inline void
llist_insert_tail(struct llist_node *head, struct llist_node *node)
{}

// Remove a node from the list.
static inline void
llist_remove(struct llist_node *node)
{}

// Append all nodes from head2 onto head1. head2 is left empty.
static inline void
llist_concat(struct llist_node *head1, struct llist_node *head2)
{}

#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_LLIST_H */