RList
Typedefs
src/include/rlist/common.h File Reference
#include <stdbool.h>

Go to the source code of this file.

Typedefs

typedef void(* rl_free_fn )(void *payload)
typedef bool(* rl_match_fn )(void *const payload, void *const context)

Detailed Description

Public declarations common to multiple RList data structures.

Definition in file common.h.


Typedef Documentation

typedef void(* rl_free_fn)(void *payload)

A function type for deleting the payload of a list node. A function of this type can be associated with a list to automatically delete the payload of a node whenever a node is deleted.

This helps in avoiding memory leaks: When deleting a list node, it is easy to forget to de-allocate its payload. When a list is associated with a rl_free_fn() call-back function, the call-back is invoked whenever a node is deleted from the list. This is primarily useful when the list payload is allocated dynamically and the list serves as the primary container for the payload (i.e., there is no other data structure that points to the same payload data).

See also:
srl_init(), drl_init()

Definition at line 37 of file common.h.

typedef bool(* rl_match_fn)(void *const payload, void *const context)

A type for call-back functions used to match list nodes against custom criteria, e.g., for finding list nodes with specific payload.

Typically, call-backs of this type are used to linearly iterate over a list and either stop at the first match or to apply some function to all matching nodes. It it is recommended to make such call-back functions efficient because they are applied to potentially large numbers of list nodes.

Using call-back functions for these operations gives the user of drl_list full customizability on the matching criteria while the generic iteration code is provided as an RList function and does not need to be re-implemented and customized over and over.

Parameters:
payloadpoints to the payload of a list node that is to be classified as a match or not.
contextpoints to a custom memory location that the call-back function requires as input or for storing data across calls. context may be used, e.g., for storing known payload data at the beginning of a search so the call-back only needs to compare context and payload to determine a match. Another use is to read and update changing information with every call, such as a position counter.
Returns:
The call-back function is expected to return true if the list node with payload is to be considered a match. It is expected to return false if the list node is not to be considered a match.

Definition at line 54 of file common.h.