minishell
ft_vect.h File Reference
#include <stddef.h>
#include <stdbool.h>
Include dependency graph for ft_vect.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  t_vect
 

Macros

#define FT_VECT_EXPAND_STEP   32
 

Functions

t_vect vect_init (size_t cap, size_t elemsize)
 
bool vect_reserve (t_vect *vect, size_t newcap)
 
void * vect_at (const t_vect *vect, size_t index)
 
bool vect_append_str (t_vect *vect, const char *value, size_t count)
 
bool vect_append_range (t_vect *vect, const void *value, size_t count)
 
bool vect_push_back (t_vect *vect, const void *elem, size_t *written_index)
 
bool vect_set (t_vect *vect, const void *elem, size_t index)
 
bool vect_remove (t_vect *vect, size_t index)
 
void vect_dispose (t_vect *vect)
 
void vect_dispose_each (t_vect *vect, void(*disposer)(void *))
 
void vect_dispose_ptrarr (t_vect *vect)
 

Macro Definition Documentation

◆ FT_VECT_EXPAND_STEP

#define FT_VECT_EXPAND_STEP   32

Definition at line 20 of file ft_vect.h.

Function Documentation

◆ vect_append_range()

bool vect_append_range ( t_vect vect,
const void *  value,
size_t  count 
)

Definition at line 43 of file vect_append_range.c.

44 {
45  return (vect_append_internal(vect, value, count, g_flag_not_string));
46 }
static const int g_flag_not_string
static bool vect_append_internal(t_vect *vect, const void *value, size_t count, int is_str)
Here is the call graph for this function:

◆ vect_append_str()

bool vect_append_str ( t_vect vect,
const char *  value,
size_t  count 
)

Definition at line 48 of file vect_append_range.c.

49 {
50  return (vect_append_internal(vect, value, count, g_flag_string));
51 }
static const int g_flag_string
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vect_at()

void* vect_at ( const t_vect vect,
size_t  index 
)

Definition at line 15 of file vect_at.c.

16 {
17  unsigned char *p;
18 
19  if (vect->len <= index)
20  return (NULL);
21  p = vect->p;
22  return (p + (vect->elemsize * index));
23 }
size_t elemsize
Definition: ft_vect.h:27
void * p
Definition: ft_vect.h:28
size_t len
Definition: ft_vect.h:26
Here is the caller graph for this function:

◆ vect_dispose()

void vect_dispose ( t_vect vect)

Definition at line 16 of file vect_dispose.c.

17 {
18  vect->len = 0;
19  vect->cap = 0;
20  vect->elemsize = 0;
21  free(vect->p);
22  vect->p = NULL;
23 }
size_t cap
Definition: ft_vect.h:25
Here is the caller graph for this function:

◆ vect_dispose_each()

void vect_dispose_each ( t_vect vect,
void(*)(void *)  disposer 
)

Definition at line 25 of file vect_dispose.c.

26 {
27  size_t pos;
28 
29  pos = 0;
30  if (disposer != NULL)
31  while (pos < vect->len)
32  disposer(vect_at(vect, pos++));
33  vect_dispose(vect);
34 }
void * vect_at(const t_vect *vect, size_t index)
Definition: vect_at.c:15
void vect_dispose(t_vect *vect)
Definition: vect_dispose.c:16
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vect_dispose_ptrarr()

void vect_dispose_ptrarr ( t_vect vect)

Definition at line 41 of file vect_dispose.c.

42 {
44 }
static void ptrarr_disposer(void *ptr)
Definition: vect_dispose.c:36
void vect_dispose_each(t_vect *vect, void(*disposer)(void *))
Definition: vect_dispose.c:25
Here is the call graph for this function:

◆ vect_init()

t_vect vect_init ( size_t  cap,
size_t  elemsize 
)

Definition at line 16 of file vect_init.c.

17 {
18  t_vect ret;
19 
20  ret.p = ft_calloc_nofill(cap, elemsize);
21  if (ret.p != NULL)
22  {
23  ret.cap = cap;
24  ret.len = 0;
25  ret.elemsize = elemsize;
26  }
27  return (ret);
28 }
void * ft_calloc_nofill(size_t count, size_t size)
Definition: ft_calloc.c:17
Definition: ft_vect.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vect_push_back()

bool vect_push_back ( t_vect vect,
const void *  elem,
size_t *  written_index 
)

Definition at line 15 of file vect_push_back.c.

16 {
17  size_t index;
18 
19  index = vect->len;
20  if (!vect_set(vect, elem, index))
21  return (false);
22  if (written_index != NULL)
23  *written_index = index;
24  return (true);
25 }
bool vect_set(t_vect *vect, const void *elem, size_t index)
Definition: vect_set.c:16
Here is the call graph for this function:

◆ vect_remove()

bool vect_remove ( t_vect vect,
size_t  index 
)

Definition at line 16 of file vect_remove.c.

17 {
18  if (vect->len <= index)
19  return (false);
20  if ((index + 1) < vect->len)
21  ft_memmove(vect_at(vect, index), vect_at(vect, index + 1),
22  (vect->len - index + 1) * vect->elemsize);
23  vect->len -= 1;
24  return (true);
25 }
void * ft_memmove(void *dst, const void *src, size_t n)
Definition: ft_memmove.c:16
Here is the call graph for this function:

◆ vect_reserve()

bool vect_reserve ( t_vect vect,
size_t  newcap 
)

Definition at line 17 of file vect_reserve.c.

18 {
19  void *p_new;
20 
21  if (vect->elemsize == 0 || newcap <= vect->len)
22  return (false);
23  if (newcap == 0)
24  p_new = NULL;
25  else
26  {
27  p_new = ft_calloc_nofill(newcap, vect->elemsize);
28  if (p_new == NULL)
29  return (false);
30  ft_memmove(p_new, vect->p, vect->elemsize * vect->len);
31  free(vect->p);
32  }
33  vect->p = p_new;
34  vect->cap = newcap;
35  return (true);
36 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vect_set()

bool vect_set ( t_vect vect,
const void *  elem,
size_t  index 
)

Definition at line 16 of file vect_set.c.

17 {
18  unsigned char *p;
19 
20  if (vect->p == NULL || vect->elemsize == 0 || vect->len < index)
21  return (false);
22  if (vect->cap <= index
23  && !vect_reserve(vect, index + FT_VECT_EXPAND_STEP))
24  return (false);
25  p = vect->p;
26  ft_memmove(p + (index * vect->elemsize), elem, vect->elemsize);
27  if (vect->len == index)
28  vect->len += 1;
29  return (true);
30 }
#define FT_VECT_EXPAND_STEP
Definition: ft_vect.h:20
bool vect_reserve(t_vect *vect, size_t newcap)
Definition: vect_reserve.c:17
Here is the call graph for this function:
Here is the caller graph for this function: