/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* find_place.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/29 22:01:12 by maiboyer #+# #+# */ /* Updated: 2024/02/08 14:06:05 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "app/find_place.h" #include "app/types/type_i64_bool.h" #include "me/vec/vec_i64_bool.h" static void find_place_iter(t_usize index, t_i64_bool *elem, t_find_place_iter_state *state) { (void)(index); if (!(elem->active || elem->value == state->to_find_elem)) return ; if (elem->value == state->to_find_elem) state->found_index = state->current_index; state->current_index++; } t_usize find_place(t_i64 elem, t_state *state) { t_find_place_iter_state iter_state; iter_state.current_index = 0; iter_state.found_index = 0; iter_state.to_find_elem = elem; vec_i64_bool_iter(&state->sorted, (void (*)())find_place_iter, &iter_state); return (iter_state.found_index); } /* state .sorted .iter() .copied() .filter(|&(e, active)| active || elem == e) .enumerate() .find(|(_, (e, _))| *e == elem) .map(|(i, _)| i) .unwrap_or_else(|| { println!("why..."); 0 }) */