Mstdlib-1.24.0
Linked List - Binary

Typedefs

typedef struct M_llist_bin M_llist_bin_t
 
typedef struct M_llist_bin_node M_llist_bin_node_t
 

Enumerations

enum  M_llist_bin_flags_t {
  M_LLIST_BIN_NONE = 0 ,
  M_LLIST_BIN_CIRCULAR = 1 << 0
}
 
enum  M_llist_bin_match_type_t {
  M_LLIST_BIN_MATCH_VAL = 0 ,
  M_LLIST_BIN_MATCH_ALL = 1 << 0
}
 

Functions

M_llist_bin_tM_llist_bin_create (M_uint32 flags) M_MALLOC
 
void M_llist_bin_destroy (M_llist_bin_t *d) M_FREE(1)
 
M_llist_bin_node_tM_llist_bin_insert (M_llist_bin_t *d, const M_uint8 *val, size_t len)
 
M_llist_bin_node_tM_llist_bin_insert_first (M_llist_bin_t *d, const M_uint8 *val, size_t len)
 
M_llist_bin_node_tM_llist_bin_insert_before (M_llist_bin_node_t *n, const M_uint8 *val, size_t len)
 
M_llist_bin_node_tM_llist_bin_insert_after (M_llist_bin_node_t *n, const M_uint8 *val, size_t len)
 
void M_llist_bin_set_first (M_llist_bin_node_t *n)
 
M_bool M_llist_bin_move_before (M_llist_bin_node_t *move, M_llist_bin_node_t *before)
 
M_bool M_llist_bin_move_after (M_llist_bin_node_t *move, M_llist_bin_node_t *after)
 
size_t M_llist_bin_len (const M_llist_bin_t *d)
 
size_t M_llist_bin_count (const M_llist_bin_t *d, const M_uint8 *val, size_t len)
 
M_llist_bin_node_tM_llist_bin_first (const M_llist_bin_t *d)
 
M_llist_bin_node_tM_llist_bin_last (const M_llist_bin_t *d)
 
M_llist_bin_node_tM_llist_bin_find (const M_llist_bin_t *d, const M_uint8 *val, size_t len)
 
M_uint8 * M_llist_bin_take_node (M_llist_bin_node_t *n, size_t *len)
 
M_bool M_llist_bin_remove_node (M_llist_bin_node_t *n)
 
size_t M_llist_bin_remove_val (M_llist_bin_t *d, const M_uint8 *val, size_t len, M_uint32 type)
 
void M_llist_bin_remove_duplicates (M_llist_bin_t *d)
 
M_llist_bin_node_tM_llist_bin_node_next (const M_llist_bin_node_t *n)
 
M_llist_bin_node_tM_llist_bin_node_prev (const M_llist_bin_node_t *n)
 
const M_uint8 * M_llist_bin_node_val (const M_llist_bin_node_t *n, size_t *len)
 
M_llist_bin_tM_llist_bin_duplicate (const M_llist_bin_t *d) M_MALLOC
 
void M_llist_bin_merge (M_llist_bin_t **dest, M_llist_bin_t *src, M_bool include_duplicates) M_FREE(2)
 

Detailed Description

Linked list for storing values.

The list can be used in multiple ways:

A linked list is not indexable. Iteration and find are supported.

Sorted notes:

Typedef Documentation

◆ M_llist_bin_t

typedef struct M_llist_bin M_llist_bin_t

◆ M_llist_bin_node_t

typedef struct M_llist_bin_node M_llist_bin_node_t

Enumeration Type Documentation

◆ M_llist_bin_flags_t

Flags for controlling the behavior of the list.

Enumerator
M_LLIST_BIN_NONE 

List mode.

M_LLIST_BIN_CIRCULAR 

Circular list.

◆ M_llist_bin_match_type_t

Type of matching that should be used when searching/modifying a value in the list.

Enumerator
M_LLIST_BIN_MATCH_VAL 

Match based on the value.

M_LLIST_BIN_MATCH_ALL 

Include all instances.

Function Documentation

◆ M_llist_bin_create()

M_llist_bin_t * M_llist_bin_create ( M_uint32  flags)

Create a new list.

A list is a linked list. The list can be, optionally, kept in sorted order. The sorted order is determined by the flags.

Parameters
[in]flagsM_llist_bin_flags_t flags controlling behavior.
Returns
Allocated linked list.
See also
M_llist_bin_destroy

◆ M_llist_bin_destroy()

void M_llist_bin_destroy ( M_llist_bin_t d)

Destroy the list.

Parameters
[in]dThe llist to destory.

◆ M_llist_bin_insert()

M_llist_bin_node_t * M_llist_bin_insert ( M_llist_bin_t d,
const M_uint8 *  val,
size_t  len 
)

Insert a value into the list.

If sorted the value will be inserted in sorted order. Otherwise it will be appended to the end of the list.

Parameters
[in,out]dThe list.
[in]valThe value to insert.
[in]lenThe length of val.
Returns
Pointer to M_llist_bin_node_t container object of new node on success, otherwise NULL.
See also
m_llist_bin_insert_first

◆ M_llist_bin_insert_first()

M_llist_bin_node_t * M_llist_bin_insert_first ( M_llist_bin_t d,
const M_uint8 *  val,
size_t  len 
)

Insert a value into the list as the first node.

Only applies to unsorted lists.

Parameters
[in,out]dThe list.
[in]valThe value to insert.
[in]lenThe length of val.
Returns
Pointer to M_llist_bin_node_t container object of new node on success, otherwise NULL.
See also
M_llist_bin_insert

◆ M_llist_bin_insert_before()

M_llist_bin_node_t * M_llist_bin_insert_before ( M_llist_bin_node_t n,
const M_uint8 *  val,
size_t  len 
)

Insert a value into the list before a given node.

Only applies to unsorted lists.

Parameters
[in,out]nThe node to insert before. Cannot be NULL.
[in]valThe value to insert.
[in]lenThe length of val.
Returns
Pointer to M_llist_bin_node_t container object of new node on success, otherwise NULL.
See also
M_llist_bin_insert_after

◆ M_llist_bin_insert_after()

M_llist_bin_node_t * M_llist_bin_insert_after ( M_llist_bin_node_t n,
const M_uint8 *  val,
size_t  len 
)

Insert a value into the list after a given node.

Only applies to unsorted lists.

Parameters
[in,out]nThe node to insert after. Cannot be NULL.
[in]valThe value to insert.
[in]lenThe length of val.
Returns
Pointer to M_llist_bin_node_t container object of new node on success, otherwise NULL.
See also
M_llist_bin_insert_before

◆ M_llist_bin_set_first()

void M_llist_bin_set_first ( M_llist_bin_node_t n)

Set the node as the first node in the circular list.

Only applies to circular lists.

Parameters
[in]nThe node that should be considered first.

◆ M_llist_bin_move_before()

M_bool M_llist_bin_move_before ( M_llist_bin_node_t move,
M_llist_bin_node_t before 
)

Move a node before another node in the list.

Parameters
[in]moveThe node to move.
[in]beforeThe node that move should be placed before.
Returns
M_TRUE on sucess, otherwise M_FALSE.

◆ M_llist_bin_move_after()

M_bool M_llist_bin_move_after ( M_llist_bin_node_t move,
M_llist_bin_node_t after 
)

Move a node after another node in the list.

Parameters
[in]moveThe node to move.
[in]afterThe node that move should be placed after.
Returns
M_TRUE on sucess, otherwise M_FALSE.

◆ M_llist_bin_len()

size_t M_llist_bin_len ( const M_llist_bin_t d)

The length of the list.

Parameters
[in]dThe list.
Returns
the length of the list.

◆ M_llist_bin_count()

size_t M_llist_bin_count ( const M_llist_bin_t d,
const M_uint8 *  val,
size_t  len 
)

Count the number of times a value occurs in the list.

Parameters
[in]dThe list.
[in]valThe value to search for.
[in]lenThe length of val.
Returns
The number of times val appears in the list.

◆ M_llist_bin_first()

M_llist_bin_node_t * M_llist_bin_first ( const M_llist_bin_t d)

Get the first node in the list.

Parameters
[in]dThe list.
Returns
Node or NULL.
See also
M_llist_bin_last
M_llist_bin_find

◆ M_llist_bin_last()

M_llist_bin_node_t * M_llist_bin_last ( const M_llist_bin_t d)

Get the last node in the list.

Parameters
[in]dThe list.
Returns
Node or NULL.
See also
M_llist_bin_first
M_llist_bin_find

◆ M_llist_bin_find()

M_llist_bin_node_t * M_llist_bin_find ( const M_llist_bin_t d,
const M_uint8 *  val,
size_t  len 
)

Find a node for the given value in the list.

Parameters
[in]dThe list.
[in]valThe value to search for.
[in]lenThe length of val.
Returns
Node or NULL.
See also
M_llist_bin_first
M_llist_bin_last

◆ M_llist_bin_take_node()

M_uint8 * M_llist_bin_take_node ( M_llist_bin_node_t n,
size_t *  len 
)

Take the node from the list and return its value.

The element will be removed from the list and its value returned. The caller is responsible for freeing the value.

Parameters
[in]nThe node.
[out]lenThe length of val.
Returns
The node's value.
See also
M_llist_bin_node_val

◆ M_llist_bin_remove_node()

M_bool M_llist_bin_remove_node ( M_llist_bin_node_t n)

Remove a node from the list.

The value will be free'd using the value_free callback.

Parameters
[in]nThe node.
Returns
M_TRUE on success otherwise M_FALSE.
See also
M_llist_bin_remove_val

◆ M_llist_bin_remove_val()

size_t M_llist_bin_remove_val ( M_llist_bin_t d,
const M_uint8 *  val,
size_t  len,
M_uint32  type 
)

Remove node(s) from the list matching a given value.

The value will be free'd using the value_free callback.

Parameters
[in,out]dThe list.
[in]valThe value to search for.
[in]lenThe length of val.
[in]typeM_llist_bin_match_type_t type of how the val should be matched. valid values are:
  • M_LLIST_BIN_MATCH_VAL (removes one/first)
  • M_LLIST_BIN_MATCH_ALL
Returns
M_TRUE on success otherwise M_FALSE.
See also
M_llist_bin_remove_node

◆ M_llist_bin_remove_duplicates()

void M_llist_bin_remove_duplicates ( M_llist_bin_t d)

Remove duplicate values from the list.

Parameters
[in]dThe list.

◆ M_llist_bin_node_next()

M_llist_bin_node_t * M_llist_bin_node_next ( const M_llist_bin_node_t n)

Get the next node, the one after a given node.

Parameters
[in]nThe node.
Returns
Node or NULL.
See also
M_llist_bin_node_prev

◆ M_llist_bin_node_prev()

M_llist_bin_node_t * M_llist_bin_node_prev ( const M_llist_bin_node_t n)

Get the previous node, the one before a given node.

Parameters
[in]nThe node.
Returns
Node or NULL.
See also
M_llist_bin_node_next

◆ M_llist_bin_node_val()

const M_uint8 * M_llist_bin_node_val ( const M_llist_bin_node_t n,
size_t *  len 
)

Get the value for a node.

Parameters
[in]nThe node.
[out]lenThe length of val.
Returns
The node's value.
See also
M_llist_bin_take_node

◆ M_llist_bin_duplicate()

M_llist_bin_t * M_llist_bin_duplicate ( const M_llist_bin_t d)

Duplicate an existing list. Will copy all elements of the list.

Parameters
[in]dlist to duplicate.
Returns
New list.

◆ M_llist_bin_merge()

void M_llist_bin_merge ( M_llist_bin_t **  dest,
M_llist_bin_t src,
M_bool  include_duplicates 
)

Merge two lists together.

The second (src) list will be destroyed automatically upon completion of this function. Any value pointers for the list will be directly copied over to the destination list, they will not be duplicated.

Parameters
[in,out]destPointer by reference to the list receiving the values. if this is NULL, the pointer will simply be switched out for src.
[in,out]srcPointer to the list giving up its values.
[in]include_duplicatesWhen M_TRUE any values in 'dest' that also exist in 'src' will be included in 'dest'. When M_FALSE any duplicate values will not be added to 'dest'.