libft
Loading...
Searching...
No Matches
vec.h File Reference
#include <stdlib.h>
#include "libft.h"

Go to the source code of this file.

Data Structures

struct  s_vec
 

Typedefs

typedef struct s_vec t_vec
 

Functions

int vec_append (t_vec *dst, t_vec *src)
 Appends vector to a vector.
 
int vec_copy (t_vec *dst, t_vec *src)
 
void vec_free (t_vec *src)
 Frees vectors memory.
 
int vec_from (t_vec *dst, void *src, size_t len, size_t elem_size)
 Creates a new vector from src.
 
int vec_new (t_vec *dst, size_t init_len, size_t elem_size)
 Creates a new vector.
 
int vec_prepend (t_vec *dst, t_vec *src)
 Prepends memory to a vector.
 
int vec_push (t_vec *dst, void *src)
 Push element to the end of the vector.
 
int vec_resize (t_vec *src, size_t target_len)
 Resizes vector.
 
int vec_remove (t_vec *src, size_t index)
 Removes item at index.
 

Typedef Documentation

◆ t_vec

typedef struct s_vec t_vec

Function Documentation

◆ vec_append()

int vec_append ( t_vec dst,
t_vec src 
)

Appends vector to a vector.

Appends *src memory to end of *dst memory.

Parameters
dstt_vec*
srct_vec*
Returns
int -1 if malloc fails otherwise 1

Definition at line 17 of file vec_append.c.

◆ vec_copy()

int vec_copy ( t_vec dst,
t_vec src 
)

Definition at line 22 of file vec_copy.c.

◆ vec_free()

void vec_free ( t_vec src)

Frees vectors memory.

Frees *memory and sets elem_size, alloc_size and len to 0.

Parameters
srct_vec

Definition at line 15 of file vec_free.c.

◆ vec_from()

int vec_from ( t_vec dst,
void *  src,
size_t  len,
size_t  elem_size 
)

Creates a new vector from src.

Allocates len * elem_size bytes of memory and copies *src to it.

Parameters
dstt_vec*
srcvoid*
init_lensize_t
elem_sizesize_t
Returns
int -1 if malloc fails otherwise 1
Attention
Allocates memory

Definition at line 15 of file vec_from.c.

◆ vec_new()

int vec_new ( t_vec dst,
size_t  init_len,
size_t  elem_size 
)

Creates a new vector.

Allocates init_len * elem_size bytes of memory.

Parameters
dstt_vec*
init_lensize_t
elem_sizesize_t
Returns
int -1 if malloc fails otherwise 1
Attention
Allocates memory

Definition at line 16 of file vec_new.c.

◆ vec_prepend()

int vec_prepend ( t_vec dst,
t_vec src 
)

Prepends memory to a vector.

Prepends *src memory to the start of the *dst memory.

Parameters
dstt_vec*
srct_vec*
Returns
int -1 if malloc fails otherwise 1

◆ vec_push()

int vec_push ( t_vec dst,
void *  src 
)

Push element to the end of the vector.

Takes in a vector and a pointer to an element to be pushed to the end of the vector.

Parameters
dstt_vec*
srcvoid*
Returns
int -1 if malloc fails otherwise 1

Definition at line 17 of file vec_push.c.

◆ vec_remove()

int vec_remove ( t_vec src,
size_t  index 
)

Removes item at index.

Parameters
srct_vec
index
Returns
int

Definition at line 15 of file vec_remove.c.

◆ vec_resize()

int vec_resize ( t_vec src,
size_t  target_len 
)

Resizes vector.

Creates a new srcs elem_size * target_len bytes sized vector and copies srcs memory to it, frees the src memory and sets src to be the newly created vector.

Parameters
srct_vec
target_lensize_t length of the resized vector
Returns
int -1 if malloc fails otherwise 1

Definition at line 17 of file vec_resize.c.