Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
list.h File Reference

List management. More...

#include "defs.h"
Include dependency graph for list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  reduct_list_node_t
 List node structure. More...
 
struct  reduct_list_t
 List structure. More...
 
struct  reduct_list_iter_t
 List iterator structure. More...
 

Macros

#define REDUCT_LIST_BITS   2
 Number of bits per level in the trie.
 
#define REDUCT_LIST_WIDTH   (1 << REDUCT_LIST_BITS)
 The number of children per node.
 
#define REDUCT_LIST_MASK   (REDUCT_LIST_WIDTH - 1)
 Mask for the index at each level.
 
#define REDUCT_LIST_TAIL_OFFSET(_list)   (((_list)->length > 0) ? (((_list)->length - 1) & ~REDUCT_LIST_MASK) : 0)
 Calculate the offset of the tail node.
 
#define REDUCT_LIST_ITER(_list)   {(_list), 0, REDUCT_NULL, REDUCT_LIST_TAIL_OFFSET(_list)}
 Create a initializer for a list iterator.
 
#define REDUCT_LIST_ITER_AT(_list, _start)   {(_list), (_start), REDUCT_NULL, REDUCT_LIST_TAIL_OFFSET(_list)}
 Create a initializer for a list iterator start at a specific index.
 
#define REDUCT_LIST_FOR_EACH(_handle, _list)    for (reduct_list_iter_t _iter = REDUCT_LIST_ITER(_list); reduct_list_iter_next(&_iter, (_handle));)
 Macro for iterating over all elements in a list.
 
#define REDUCT_LIST_FOR_EACH_AT(_handle, _list, _start)    for (reduct_list_iter_t _iter = REDUCT_LIST_ITER_AT(_list, _start); reduct_list_iter_next(&_iter, (_handle));)
 Macro for iterating over elements in a list starting from a specific index.
 

Functions

REDUCT_API reduct_list_treduct_list_new (struct reduct *reduct)
 Create a new editable list.
 
REDUCT_API reduct_list_treduct_list_assoc (struct reduct *reduct, reduct_list_t *list, reduct_size_t index, reduct_handle_t val)
 Create a new list with an updated value at the specified index.
 
REDUCT_API reduct_list_treduct_list_dissoc (struct reduct *reduct, reduct_list_t *list, reduct_size_t index)
 Create a new list with the element at the specified index removed.
 
REDUCT_API reduct_list_treduct_list_slice (struct reduct *reduct, reduct_list_t *list, reduct_size_t start, reduct_size_t end)
 Create a new list by slicing an existing list.
 
REDUCT_API reduct_handle_t reduct_list_nth (struct reduct *reduct, reduct_list_t *list, reduct_size_t index)
 Get the nth element of the list.
 
REDUCT_API struct reduct_item * reduct_list_nth_item (struct reduct *reduct, reduct_list_t *list, reduct_size_t index)
 Get the nth element of the list as an item.
 
REDUCT_API void reduct_list_append (struct reduct *reduct, reduct_list_t *list, reduct_handle_t val)
 Append an element to the list.
 
REDUCT_API void reduct_list_append_list (struct reduct *reduct, reduct_list_t *list, reduct_list_t *other)
 Append all elements from one list to another.
 
REDUCT_API reduct_bool_t reduct_list_iter_next (reduct_list_iter_t *iter, reduct_handle_t *out)
 Get the next element from the iterator.
 

Detailed Description

List management.

Definition in file list.h.

Macro Definition Documentation

◆ REDUCT_LIST_BITS

#define REDUCT_LIST_BITS   2

Number of bits per level in the trie.

Definition at line 27 of file list.h.

◆ REDUCT_LIST_WIDTH

#define REDUCT_LIST_WIDTH   (1 << REDUCT_LIST_BITS)

The number of children per node.

Definition at line 28 of file list.h.

◆ REDUCT_LIST_MASK

#define REDUCT_LIST_MASK   (REDUCT_LIST_WIDTH - 1)

Mask for the index at each level.

Definition at line 29 of file list.h.

◆ REDUCT_LIST_TAIL_OFFSET

#define REDUCT_LIST_TAIL_OFFSET (   _list)    (((_list)->length > 0) ? (((_list)->length - 1) & ~REDUCT_LIST_MASK) : 0)

Calculate the offset of the tail node.

Definition at line 149 of file list.h.

◆ REDUCT_LIST_ITER

#define REDUCT_LIST_ITER (   _list)    {(_list), 0, REDUCT_NULL, REDUCT_LIST_TAIL_OFFSET(_list)}

Create a initializer for a list iterator.

Parameters
_listThe list to iterate over.

Definition at line 156 of file list.h.

◆ REDUCT_LIST_ITER_AT

#define REDUCT_LIST_ITER_AT (   _list,
  _start 
)    {(_list), (_start), REDUCT_NULL, REDUCT_LIST_TAIL_OFFSET(_list)}

Create a initializer for a list iterator start at a specific index.

Parameters
_listThe list to iterate over.
_startThe starting index.

Definition at line 164 of file list.h.

◆ REDUCT_LIST_FOR_EACH

#define REDUCT_LIST_FOR_EACH (   _handle,
  _list 
)     for (reduct_list_iter_t _iter = REDUCT_LIST_ITER(_list); reduct_list_iter_next(&_iter, (_handle));)

Macro for iterating over all elements in a list.

Parameters
_handleThe reduct_handle_t variable to store each element.
_listPointer to the reduct_list_t to iterate.

Definition at line 181 of file list.h.

◆ REDUCT_LIST_FOR_EACH_AT

#define REDUCT_LIST_FOR_EACH_AT (   _handle,
  _list,
  _start 
)     for (reduct_list_iter_t _iter = REDUCT_LIST_ITER_AT(_list, _start); reduct_list_iter_next(&_iter, (_handle));)

Macro for iterating over elements in a list starting from a specific index.

Parameters
_handleThe reduct_handle_t variable to store each element.
_listPointer to the reduct_list_t to iterate.
_startThe starting index.

Definition at line 191 of file list.h.

Function Documentation

◆ reduct_list_new()

REDUCT_API reduct_list_t * reduct_list_new ( struct reduct *  reduct)

Create a new editable list.

Parameters
reductPointer to the Reduct structure.
Returns
A pointer to the newly created list.
Here is the caller graph for this function:

◆ reduct_list_assoc()

REDUCT_API reduct_list_t * reduct_list_assoc ( struct reduct *  reduct,
reduct_list_t list,
reduct_size_t  index,
reduct_handle_t  val 
)

Create a new list with an updated value at the specified index.

Parameters
reductPointer to the Reduct structure.
listPointer to the source list.
indexThe index to update.
valThe new value to set.
Returns
A pointer to the newly created list.

Definition at line 74 of file list_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_list_dissoc()

REDUCT_API reduct_list_t * reduct_list_dissoc ( struct reduct *  reduct,
reduct_list_t list,
reduct_size_t  index 
)

Create a new list with the element at the specified index removed.

Parameters
reductPointer to the Reduct structure.
listPointer to the source list.
indexThe index of the element to remove.
Returns
A pointer to the newly created list.
Todo:
There is definetly a better way to do this

Definition at line 106 of file list_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_list_slice()

REDUCT_API reduct_list_t * reduct_list_slice ( struct reduct *  reduct,
reduct_list_t list,
reduct_size_t  start,
reduct_size_t  end 
)

Create a new list by slicing an existing list.

Parameters
reductPointer to the Reduct structure.
listPointer to the source list.
startThe starting index (inclusive).
endThe ending index (exclusive).
Returns
A pointer to the newly created list slice.

Definition at line 131 of file list_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_list_nth()

REDUCT_API reduct_handle_t reduct_list_nth ( struct reduct *  reduct,
reduct_list_t list,
reduct_size_t  index 
)

Get the nth element of the list.

Parameters
reductPointer to the Reduct structure.
listPointer to the list.
indexThe index of the element to retrieve.
Returns
The handle of the nth element.

Definition at line 157 of file list_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_list_nth_item()

REDUCT_API struct reduct_item * reduct_list_nth_item ( struct reduct *  reduct,
reduct_list_t list,
reduct_size_t  index 
)

Get the nth element of the list as an item.

Parameters
reductPointer to the Reduct structure.
listPointer to the list.
indexThe index of the element to retrieve.
Returns
A pointer to the item of the nth element.

Definition at line 172 of file list_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_list_append()

REDUCT_API void reduct_list_append ( struct reduct *  reduct,
reduct_list_t list,
reduct_handle_t  val 
)

Append an element to the list.

Parameters
reductPointer to the Reduct structure.
listThe target list (must be editable).
valHandle to the value to append.
Here is the caller graph for this function:

◆ reduct_list_append_list()

REDUCT_API void reduct_list_append_list ( struct reduct *  reduct,
reduct_list_t list,
reduct_list_t other 
)

Append all elements from one list to another.

Parameters
reductPointer to the Reduct structure.
listThe target list (must be editable).
otherThe source list to copy from.
Here is the caller graph for this function:

◆ reduct_list_iter_next()

REDUCT_API reduct_bool_t reduct_list_iter_next ( reduct_list_iter_t iter,
reduct_handle_t out 
)

Get the next element from the iterator.

Parameters
iterPointer to the iterator.
outPointer to store the retrieved handle.
Returns
REDUCT_TRUE if an element was retrieved, REDUCT_FALSE if the end was reached.

Definition at line 255 of file list_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function: