bwp_list

Real-time safe doubly linked list.

API

Module type: Utility

bwp_list_elem

typedef struct bwp_list_elem {
	struct bwp_list_elem * prev;
	struct bwp_list_elem * next;
	void *                 data;
} bwp_list_elem;

List element.

bwp_list

typedef struct {
	bwp_list_elem * head;
	bwp_list_elem * tail;
} bwp_list;

List.

bwp_list_prepend()

static inline void bwp_list_prepend(
	bwp_list * BW_RESTRICT list,
	bwp_list_elem *        elem);

Prepends elem to list.

elem must not be already part of list.

bwp_list_append()

static inline void bwp_list_append(
	bwp_list * BW_RESTRICT list,
	bwp_list_elem *        elem);

Appends elem to list.

elem must not be already part of list.

bwp_list_insert_before()

static inline void bwp_list_insert_before(
	bwp_list * BW_RESTRICT list,
	bwp_list_elem *        elem,
	bwp_list_elem *        before);

Inserts elem into list right before the before element.

elem must not be already part of list, while before must be part of list.

bwp_list_insert_after()

static inline void bwp_list_insert_after(
	bwp_list * BW_RESTRICT list,
	bwp_list_elem *        elem,
	bwp_list_elem *        after);

Inserts elem into list right after the after element.

elem must not be already part of list, while after must be part of list.

bwp_list_move_before()

static inline void bwp_list_move_before(
	bwp_list * BW_RESTRICT list,
	bwp_list_elem *        elem,
	bwp_list_elem *        before);

Moves elem right before the before element.

elem and before must be part of list.

bwp_list_move_after()

static inline void bwp_list_move_after(
	bwp_list * BW_RESTRICT list,
	bwp_list_elem *        elem,
	bwp_list_elem *        after);

Moves elem right after the after element.

elem and after must be part of list.

bwp_list_pop()

static inline void bwp_list_pop(
	bwp_list * BW_RESTRICT list,
	bwp_list_elem *        elem);

Removes elem from list.

elem must be part of list.

bwp_list_contains()

static inline char bwp_list_contains(
	const bwp_list * BW_RESTRICT list,
	const bwp_list_elem *        elem);

Returns non-0 if elem is part of list, 0 otherwise.

bwp_list_count()

static inline size_t bwp_list_count(
	const bwp_list * BW_RESTRICT list);

Returns the number of elements in list.

bwp_list_is_valid()

static inline char bwp_list_is_valid(
	const bwp_list * BW_RESTRICT list);

Tries to determine whether list is valid and returns non-0 if it seems to be the case and 0 if it is certainly not. False positives are possible, false negatives are not.

C++ wrapper

BrickworksPro::List
class List {
public:
	List();

	void prepend(
		bwp_list_elem * elem);

	void append(
		bwp_list_elem * elem);

	void insertBefore(
		bwp_list_elem * elem,
		bwp_list_elem * before);

	void insertAfter(
		bwp_list_elem * elem,
		bwp_list_elem * after);

	void moveBefore(
		bwp_list_elem * elem,
		bwp_list_elem * before);

	void moveAfter(
		bwp_list_elem * elem,
		bwp_list_elem * after);

	void pop(
		bwp_list_elem * elem);

	bool contains(
		bwp_list_elem * elem);

	size_t count();
	
	bwp_list list;
};

Changelog

  • Version 1.0.0:
    • First release.