Reduct  v4.0.5-1-g4851deb
A functional and immutable language.
Loading...
Searching...
No Matches
list.h File Reference

List management. More...

#include <reduct/arena.h>
#include <reduct/defs.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stddef.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_t
 List structure. More...
 
struct  reduct_list_entry_t
 A key-value pair for creating association lists. More...
 

Macros

#define REDUCT_LIST_SMALL_MAX   4
 The maximum number of elements in a small list.
 
#define REDUCT_LIST_LARGE_MIN   16
 The minimum number of elements in a large list.
 
#define REDUCT_LIST_EXTRA_ROOM_FACTOR   2
 The factor of extra capacity to allocate around large lists.
 
#define REDUCT_LIST_FLAG_NONE   0
 No flags.
 
#define REDUCT_LIST_FLAG_LARGE   (1 << 0)
 List has an allocated buffer within an arena.
 
#define REDUCT_LIST_FLAG_USED_HEAD   (1 << 1)
 Reserved headroom has been used by a derivative list.
 
#define REDUCT_LIST_FLAG_USED_TAIL   (1 << 2)
 Reserved tailroom has been used by a derivative list.
 

Typedefs

typedef uint8_t reduct_list_flags_t
 

Functions

REDUCT_API reduct_list_treduct_list_new (struct reduct *reduct, size_t length)
 Create a new editable list.
 
REDUCT_API reduct_list_treduct_list_new_handles (struct reduct *reduct, size_t count, reduct_handle_t *handles)
 Create a new list from an array of handles.
 
REDUCT_API reduct_list_treduct_list_new_alist (struct reduct *reduct, size_t count,...)
 Create a new association list (list storing key-value pairs) from a variable number of pairs.
 
REDUCT_API reduct_list_treduct_list_new_alist_entries (struct reduct *reduct, size_t count, const reduct_list_entry_t *entries)
 Create a new association list from an array of entries.
 
REDUCT_API reduct_list_treduct_list_slice (struct reduct *reduct, reduct_list_t *list, size_t start, size_t end)
 Create a new list by slicing an existing list.
 
REDUCT_API reduct_list_treduct_list_append (struct reduct *reduct, reduct_list_t *list, reduct_handle_t val)
 Create a new list by appending an element to an existing list.
 
REDUCT_API reduct_list_treduct_list_prepend (struct reduct *reduct, reduct_list_t *list, reduct_handle_t val)
 Create a new list by prepending an element to an existing list.
 
REDUCT_API reduct_list_treduct_list_concat (struct reduct *reduct, reduct_list_t *a, reduct_list_t *b)
 Create a new list by concatenating two existing lists.
 
REDUCT_API void reduct_list_retain (struct reduct *reduct, reduct_list_t *list)
 Retain a list, preventing it from being collected by the garbage collector.
 
REDUCT_API void reduct_list_release (struct reduct *reduct, reduct_list_t *list)
 Release a list, potentially allowing the garbage collector to collect it.
 

Detailed Description

List management.

Definition in file list.h.

Macro Definition Documentation

◆ REDUCT_LIST_SMALL_MAX

#define REDUCT_LIST_SMALL_MAX   4

The maximum number of elements in a small list.

Definition at line 37 of file list.h.

◆ REDUCT_LIST_LARGE_MIN

#define REDUCT_LIST_LARGE_MIN   16

The minimum number of elements in a large list.

Definition at line 38 of file list.h.

◆ REDUCT_LIST_EXTRA_ROOM_FACTOR

#define REDUCT_LIST_EXTRA_ROOM_FACTOR   2

The factor of extra capacity to allocate around large lists.

Definition at line 39 of file list.h.

◆ REDUCT_LIST_FLAG_NONE

#define REDUCT_LIST_FLAG_NONE   0

No flags.

Definition at line 42 of file list.h.

◆ REDUCT_LIST_FLAG_LARGE

#define REDUCT_LIST_FLAG_LARGE   (1 << 0)

List has an allocated buffer within an arena.

Definition at line 43 of file list.h.

◆ REDUCT_LIST_FLAG_USED_HEAD

#define REDUCT_LIST_FLAG_USED_HEAD   (1 << 1)

Reserved headroom has been used by a derivative list.

Definition at line 44 of file list.h.

◆ REDUCT_LIST_FLAG_USED_TAIL

#define REDUCT_LIST_FLAG_USED_TAIL   (1 << 2)

Reserved tailroom has been used by a derivative list.

Definition at line 45 of file list.h.

Typedef Documentation

◆ reduct_list_flags_t

typedef uint8_t reduct_list_flags_t

Definition at line 41 of file list.h.

Function Documentation

◆ reduct_list_new()

REDUCT_API reduct_list_t * reduct_list_new ( struct reduct *  reduct,
size_t  length 
)

Create a new editable list.

Parameters
reductPointer to the Reduct structure.
lengthThe predetermined length of the list.
Returns
A pointer to the newly created list.

◆ reduct_list_new_handles()

REDUCT_API reduct_list_t * reduct_list_new_handles ( struct reduct *  reduct,
size_t  count,
reduct_handle_t handles 
)

Create a new list from an array of handles.

Parameters
reductPointer to the Reduct structure.
countThe number of handles.
handlesThe array of handles.
Returns
A pointer to the newly created list.

◆ reduct_list_new_alist()

REDUCT_API reduct_list_t * reduct_list_new_alist ( struct reduct *  reduct,
size_t  count,
  ... 
)

Create a new association list (list storing key-value pairs) from a variable number of pairs.

Parameters
reductPointer to the Reduct structure.
countThe number of pairs.
...Each pair should be provided as a (const char*, reduct_handle_t).
Returns
A pointer to the newly created association list.

◆ reduct_list_new_alist_entries()

REDUCT_API reduct_list_t * reduct_list_new_alist_entries ( struct reduct *  reduct,
size_t  count,
const reduct_list_entry_t entries 
)

Create a new association list from an array of entries.

Parameters
reductPointer to the Reduct structure.
countNumber of entries.
entriesArray of key-value pairs.

◆ reduct_list_slice()

REDUCT_API reduct_list_t * reduct_list_slice ( struct reduct *  reduct,
reduct_list_t list,
size_t  start,
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.

◆ reduct_list_append()

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

Create a new list by appending an element to an existing list.

Parameters
reductPointer to the Reduct structure.
listPointer to the source list.
valThe value to append.
Returns
A pointer to the newly created list.

◆ reduct_list_prepend()

REDUCT_API reduct_list_t * reduct_list_prepend ( struct reduct *  reduct,
reduct_list_t list,
reduct_handle_t  val 
)

Create a new list by prepending an element to an existing list.

Parameters
reductPointer to the Reduct structure.
listPointer to the source list.
valThe value to prepend.
Returns
A pointer to the newly created list.

◆ reduct_list_concat()

REDUCT_API reduct_list_t * reduct_list_concat ( struct reduct *  reduct,
reduct_list_t a,
reduct_list_t b 
)

Create a new list by concatenating two existing lists.

Parameters
reductPointer to the Reduct structure.
aPointer to the first list.
bPointer to the second list.
Returns
A pointer to the newly created list.

◆ reduct_list_retain()

REDUCT_API void reduct_list_retain ( struct reduct *  reduct,
reduct_list_t list 
)

Retain a list, preventing it from being collected by the garbage collector.

Parameters
reductPointer to the Reduct structure.
listPointer to the list.

◆ reduct_list_release()

REDUCT_API void reduct_list_release ( struct reduct *  reduct,
reduct_list_t list 
)

Release a list, potentially allowing the garbage collector to collect it.

Parameters
reductPointer to the Reduct structure.
listPointer to the list.