From b2fc03d7bbcf70bb5fee2c3bdd32360f45330fc3 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Sat, 27 Jul 2024 15:45:25 +0800 Subject: [PATCH] Refactor --- .../union_find.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/problem_1970_last_day_where_you_can_still_cross/union_find.rs b/src/problem_1970_last_day_where_you_can_still_cross/union_find.rs index fd22e949..cbac2abf 100644 --- a/src/problem_1970_last_day_where_you_can_still_cross/union_find.rs +++ b/src/problem_1970_last_day_where_you_can_still_cross/union_find.rs @@ -8,17 +8,17 @@ use std::{mem, ptr}; type State = (Cell, Cell); impl Solution { - fn get_node(array: &[State], value: &State) -> u16 { - ((ptr::from_ref(value) as usize - array.as_ptr() as usize) / mem::size_of::()) as _ + fn get_node(union_find: &[State], state: &State) -> u16 { + ((ptr::from_ref(state) as usize - union_find.as_ptr() as usize) / mem::size_of::()) as _ } - fn find_root<'a>(union_find: &'a [State], node_state: &'a State) -> &'a State { - let parent = node_state.0.get(); + fn find_root<'a>(union_find: &'a [State], state: &'a State) -> &'a State { + let parent = state.0.get(); - union_find.get(usize::from(parent)).map_or(node_state, |parent_state| { + union_find.get(usize::from(parent)).map_or(state, |parent_state| { let root = Self::find_root(union_find, parent_state); - node_state.0.set(Self::get_node(union_find, root)); + state.0.set(Self::get_node(union_find, root)); root })