shithub: libds

ref: cfd7660a044c8bd3ad0c33a237155b05248c0b0b
dir: libds/list.h

View raw version
// Defines a node in a list
typedef struct ListNode ListNode;
struct ListNode {
	void *datum;			// Data stored in node
	ListNode *next;			// Next node in the list

	// Doubly-linked things
	union {
		ListNode *prev;		// Previous node in the list
		char empty;			// Stub for space savings in single
	};
};

// Defines a list from the head;
typedef struct List List;
struct List {
	ListNode	*head;
	usize		size;
};

// Return an allocated, empty, list. 
List*	mklist(void);

// Prepend to the front of the list. 
List*	listprepend(List*, void*);

// Append to the end of the list. 
List*	listappend(List*, void*);