Distributed File System 1
Distributed file system in C
Loading...
Searching...
No Matches
list.h File Reference
#include "lib.h"

Go to the source code of this file.

Classes

struct  NodeOpaque
 This is the data at each node on a List. More...

Macros

#define DefList(type)
#define ImplList(type)

Typedefs

typedef void * Opaque
 An opaque type.
typedef struct NodeOpaqueListOpaque
 This is the actual type of the List.

Functions

void ListOpaque_deinit (ListOpaque list)
 Deinitialize the List.
Opaque ListOpaque_car (struct NodeOpaque node)
 Returns the element at the head of the List.
struct NodeOpaqueListOpaque_cdr (struct NodeOpaque node)
 Returns the rest of the List, ignoring the first element.
ListOpaque ListOpaque_cons (Opaque fst, ListOpaque list)
 Prepend an element to the List.
ListOpaque ListOpaque_rev (ListOpaque list, ListOpaque acc)
 Helper function for ListOpaque_reverse.
ListOpaque ListOpaque_reverse (ListOpaque list)
 Reverses a List.
size_t ListOpaque_length (ListOpaque list)
 Returns the length of the List.
Opaque ListOpaque_at (ListOpaque list, size_t index)
 The indexing function for a List.

Macro Definition Documentation

◆ DefList

#define DefList ( type)
Value:
struct Node##type { \
type head; \
struct Node##type* rest; \
}; \
typedef struct Node##type* List##type; \
void List##type##_deinit(List##type list); \
type List##type##_car(struct Node##type node); \
struct Node##type* List##type##_cdr(struct Node##type node); \
List##type List##type##_cons(type a, List##type list); \
List##type List##type##_rev(List##type list, List##type a); \
List##type List##type##_reverse(List##type list); \
size_t List##type##_length(List##type list); \
type List##type##_at(List##type list, size_t index); \
List##type List##type##_drop(List##type list, size_t n); \
List##type List##type##_drop(List##type list, size_t n);
void list(Enchufe cliente)
Definition meta-data.c:14

◆ ImplList

#define ImplList ( type)

Typedef Documentation

◆ ListOpaque

typedef struct NodeOpaque* ListOpaque

This is the actual type of the List.

◆ Opaque

typedef void* Opaque

An opaque type.

Function Documentation

◆ ListOpaque_at()

Opaque ListOpaque_at ( ListOpaque list,
size_t index )

The indexing function for a List.

This will crash your program if you index outside of the List. INFO: the first index is 1. Similar: to https://cppreference.com/w/cpp/container/vector/at.html.

Parameters
listthe List to get the element from
indexthe index of the element in the List
Returns
the element at that index

◆ ListOpaque_car()

Opaque ListOpaque_car ( struct NodeOpaque node)

Returns the element at the head of the List.

This exists in case you want a functional style.

Parameters
nodethe node to get the head from
Returns
the element at the head of the List

◆ ListOpaque_cdr()

struct NodeOpaque * ListOpaque_cdr ( struct NodeOpaque node)

Returns the rest of the List, ignoring the first element.

This exists in case you want a functional style.

Parameters
nodethe node to get the list from
Returns
the rest of the List

◆ ListOpaque_cons()

ListOpaque ListOpaque_cons ( Opaque fst,
ListOpaque list )

Prepend an element to the List.

This is the main way of actually creating lists. For more information you can visit: https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-List.html#t:List INFO: Caller must free memory

Parameters
fstthe element you want to prepend
listthe list you want to prepend to
Returns
a List where the first element is fst and the rest of the List is list

◆ ListOpaque_deinit()

void ListOpaque_deinit ( ListOpaque list)

Deinitialize the List.

Parameters
listthe List to deinitialize

◆ ListOpaque_length()

size_t ListOpaque_length ( ListOpaque list)

Returns the length of the List.

Parameters
listthe List that you want the length for
Returns
the length of that List

◆ ListOpaque_rev()

ListOpaque ListOpaque_rev ( ListOpaque list,
ListOpaque acc )

Helper function for ListOpaque_reverse.

Parameters
listthe List that is being reversed
accthe accumulator
Returns
a reversed List

◆ ListOpaque_reverse()

ListOpaque ListOpaque_reverse ( ListOpaque list)

Reverses a List.

Implementation taken from: https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-List.html#v:reverse INFO: Memory is freed for caller.

Parameters
listthe List to reverse
Returns
a reversed List