Utilities#

Retrieve Length#

size_t ntl_length(ntl_t p)#

Return the null-terminated list length.

Analogous to strlen(), will iterate over the NTL until a NULL is found. If p is NULL, it will return 0.

Parameters:
  • p – the NTL pointer

Returns:

the NTL length

Retrieve Length (with threshold)#

size_t ntl_length_max(ntl_t p, size_t max)#

Return the null-terminated list length under a threshold.

Behaves like ntl_length() but will stop at a threshold max

Parameters:
  • p – the NTL pointer

  • max – the threshold length that the function will stop at

Returns:

the NTL length

Callback function for each element#

void ntl_apply(void *cxt, ntl_t p, void (*f)(void *cxt, void *elem_p))#

Call a user-defined callback for each NTL element.

Parameters:
  • cxt – an optional user-arbitrary data to be passed along the callbacks

  • p – the NTL pointer

  • f – the user-defined callback

Append Element#

void ntl_append2(ntl_t *p, size_t elem_size, void *added_elem)#

Append a element to the null-terminated list.

Append a element to the NTL, this is not efficient for many appends.

Note

Its the caller’s responsibility to make sure added_elem has the same type and size as the NTL.

Parameters:
  • p – the NTL pointer

  • elem_size – the size of each NTL element

  • added_elem – the element to be appended

Map Elements#

typedef void (*ntl_elem_map)(void *cxt, void *from_elem, void *to_elem)#

Callback function for creating and mapping a NTL to another.

ntl_t ntl_fmap(void *cxt, ntl_t in_list, size_t out_elem_size, ntl_elem_map map)#

Behaves similarly to Haskell list’s fmap.

Parameters:
  • cxt – an optional user-arbitrary data to be passed along the callbacks

  • in_list – the input NTL

  • out_elem_size – the size of each output element

  • map – the callback function to map each in_list element to the returned NTL element

Returns:

the new NTL

Is Member (Bool)#

int ntl_is_a_member(ntl_t p, void *elem)#

Check if an element is part of a null-terminated list by its address.

Parameters:
  • p – the NTL

  • elem – the element to be checked against p

Returns:

1 if elem is a member of the NTL, 0 otherwise