ft_vec_erase.c \
ft_vec_access.c \
ft_vec_free.c \
+ ft_vec_find.c \
+ ft_vec_find_index.c \
\
ft_mat_init.c \
ft_mat_append.c \
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_vec_find.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/01/11 11:04:05 by ljiriste #+# #+# */
+/* Updated: 2024/01/11 12:27:10 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+void *ft_vec_find(t_vec *vec, void *wanted)
+{
+ size_t i;
+
+ if (!vec || !wanted)
+ return (NULL);
+ i = 0;
+ while (i < vec->size)
+ {
+ if (!ft_memcmp(ft_vec_access(vec, i), wanted, vec->el_size))
+ {
+ return (ft_vec_access(vec, i));
+ }
+ ++i;
+ }
+ return (NULL);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_vec_find_index.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/01/11 11:49:41 by ljiriste #+# #+# */
+/* Updated: 2024/01/12 17:10:23 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+t_arr_stat ft_vec_find_index(t_vec *vec, void *wanted, size_t *index)
+{
+ if (!vec || !wanted || !index)
+ return (invalid_input);
+ wanted = ft_vec_find(vec, wanted);
+ if (wanted == NULL)
+ return (non_specific_failure);
+ *index = (size_t)(((char *)wanted - (char *)vec->vec) / vec->el_size);
+ return (success);
+}
/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/09 13:58:15 by ljiriste #+# #+# */
-/* Updated: 2024/01/12 19:13:06 by ljiriste ### ########.fr */
+/* Updated: 2024/01/12 21:25:42 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
* Also implement access function that casts to desired type
* eg. int *int_access(t_vec *vec, size_t ind){return ((int *)vec->vec + ind);}
*/
+void *ft_vec_find(t_vec *vec, void *wanted);
+t_arr_stat ft_vec_find_index(t_vec *vec, void *wanted, size_t *index);
t_arr_stat ft_mat_init(t_mat *mat, size_t el_size);
void ft_mat_free(t_mat *mat, void (*free_el)(void *));