Lely core libraries  2.2.5
dllist.h File Reference
#include <lely/features.h>
#include <stddef.h>
Include dependency graph for dllist.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dlnode
 A node in a doubly-linked list. More...
 
struct  dllist
 A doubly-linked list. More...
 

Macros

#define DLNODE_INIT
 The static initializer for dlnode.
 
#define DLLIST_INIT
 The static initializer for dllist.
 
#define dlnode_foreach(first, node)   dlnode_foreach_(__LINE__, first, node)
 Iterates in order over each node in a doubly-linked list. More...
 
#define dllist_foreach(list, node)   dlnode_foreach (dllist_first(list), node)
 Iterates in order over each node in a doubly-linked list. More...
 

Functions

void dlnode_init (struct dlnode *node)
 Initializes a node in a doubly-linked list.
 
int dlnode_insert_after (struct dlnode *prev, struct dlnode *node)
 Inserts node after prev. More...
 
int dlnode_insert_before (struct dlnode *next, struct dlnode *node)
 Inserts node before next. More...
 
void dlnode_remove (struct dlnode *node)
 Removes node from a doubly-list. More...
 
void dllist_init (struct dllist *list)
 Initializes a doubly-linked list.
 
int dllist_empty (const struct dllist *list)
 Returns 1 if the doubly-linked list is empty, and 0 if not. More...
 
size_t dllist_size (const struct dllist *list)
 Returns the size (in number of nodes) of a doubly-linked list. More...
 
void dllist_push_front (struct dllist *list, struct dlnode *node)
 Pushes a node to the front of a doubly-linked list. More...
 
void dllist_push_back (struct dllist *list, struct dlnode *node)
 Pushes a node to the back of a doubly-linked list. More...
 
struct dlnodedllist_pop_front (struct dllist *list)
 Pops a node from the front of a doubly-linked list. More...
 
struct dlnodedllist_pop_back (struct dllist *list)
 Pops a node from the back of a doubly-linked list. More...
 
void dllist_insert_after (struct dllist *list, struct dlnode *prev, struct dlnode *node)
 Inserts a node into a doubly-linked list. More...
 
void dllist_insert_before (struct dllist *list, struct dlnode *next, struct dlnode *node)
 Inserts a node into a doubly-linked list. More...
 
void dllist_remove (struct dllist *list, struct dlnode *node)
 Removes a node from a doubly-linked list. More...
 
struct dllistdllist_append (struct dllist *dst, struct dllist *src)
 Appends the doubly-linked list at src to the one at dst. More...
 
struct dlnodedllist_first (const struct dllist *list)
 Returns a pointer to the first node in a doubly-linked list. More...
 
struct dlnodedllist_last (const struct dllist *list)
 Returns a pointer to the last node in a doubly-linked list. More...
 

Detailed Description

This header file is part of the utilities library; it contains the doubly-linked list declarations.

Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file dllist.h.

Macro Definition Documentation

◆ dlnode_foreach

#define dlnode_foreach (   first,
  node 
)    dlnode_foreach_(__LINE__, first, node)

Iterates in order over each node in a doubly-linked list.

It is safe to remove the current node during the iteration.

Parameters
firsta pointer to the first node in the list.
nodethe name of the pointer to the nodes. This variable is declared in the scope of the loop.

Definition at line 106 of file dllist.h.

◆ dllist_foreach

#define dllist_foreach (   list,
  node 
)    dlnode_foreach (dllist_first(list), node)

Iterates in order over each node in a doubly-linked list.

It is safe to remove the current node during the iteration.

Parameters
lista pointer to a doubly-linked list.
nodethe name of the pointer to the nodes. This variable is declared in the scope of the loop.

Definition at line 224 of file dllist.h.

Function Documentation

◆ dlnode_insert_after()

int dlnode_insert_after ( struct dlnode prev,
struct dlnode node 
)
inline

Inserts node after prev.

Returns
1 if prev was the last node in the list and 0 if not.

Definition at line 234 of file dllist.h.

◆ dlnode_insert_before()

int dlnode_insert_before ( struct dlnode next,
struct dlnode node 
)
inline

Inserts node before next.

Returns
1 if next was the first node in the list and 0 if not.

Definition at line 244 of file dllist.h.

◆ dlnode_remove()

void dlnode_remove ( struct dlnode node)
inline

Removes node from a doubly-list.

Note that this function does not reset the prev and next fields of the node.

Definition at line 254 of file dllist.h.

◆ dllist_empty()

int dllist_empty ( const struct dllist list)
inline

Returns 1 if the doubly-linked list is empty, and 0 if not.

This is an O(1) operation.

Definition at line 270 of file dllist.h.

◆ dllist_size()

size_t dllist_size ( const struct dllist list)
inline

Returns the size (in number of nodes) of a doubly-linked list.

This is an O(n) operation.

Definition at line 276 of file dllist.h.

◆ dllist_push_front()

void dllist_push_front ( struct dllist list,
struct dlnode node 
)
inline

Pushes a node to the front of a doubly-linked list.

This is an O(1) operation.

See also
dllist_pop_front()

Definition at line 285 of file dllist.h.

◆ dllist_push_back()

void dllist_push_back ( struct dllist list,
struct dlnode node 
)
inline

Pushes a node to the back of a doubly-linked list.

This is an O(1) operation.

See also
dllist_pop_back()

Definition at line 296 of file dllist.h.

◆ dllist_pop_front()

struct dlnode * dllist_pop_front ( struct dllist list)
inline

Pops a node from the front of a doubly-linked list.

This is an O(1) operation.

See also
dllist_push_front()

Definition at line 307 of file dllist.h.

◆ dllist_pop_back()

struct dlnode * dllist_pop_back ( struct dllist list)
inline

Pops a node from the back of a doubly-linked list.

This is an O(1) operation.

See also
dllist_push_back()

Definition at line 320 of file dllist.h.

◆ dllist_insert_after()

void dllist_insert_after ( struct dllist list,
struct dlnode prev,
struct dlnode node 
)
inline

Inserts a node into a doubly-linked list.

prev MUST be part of list. This is an O(1) operation.

See also
dlnode_insert_after()

Definition at line 333 of file dllist.h.

◆ dllist_insert_before()

void dllist_insert_before ( struct dllist list,
struct dlnode next,
struct dlnode node 
)
inline

Inserts a node into a doubly-linked list.

next MUST be part of list. This is an O(1) operation.

See also
dlnode_insert_before()

Definition at line 341 of file dllist.h.

◆ dllist_remove()

void dllist_remove ( struct dllist list,
struct dlnode node 
)
inline

Removes a node from a doubly-linked list.

node MUST be part of list. This is an O(1) operation.

See also
dlnode_remove()

Definition at line 349 of file dllist.h.

◆ dllist_append()

struct dllist * dllist_append ( struct dllist dst,
struct dllist src 
)
inline

Appends the doubly-linked list at src to the one at dst.

After the operation, the list at src is empty.

Returns
dst.

Definition at line 359 of file dllist.h.

◆ dllist_first()

struct dlnode * dllist_first ( const struct dllist list)
inline

Returns a pointer to the first node in a doubly-linked list.

This is an O(1) operation.

See also
dllist_last()

Definition at line 376 of file dllist.h.

◆ dllist_last()

struct dlnode * dllist_last ( const struct dllist list)
inline

Returns a pointer to the last node in a doubly-linked list.

This is an O(1) operation.

See also
dllist_first()

Definition at line 382 of file dllist.h.