/** Returns whether the two chains form a loop ie. they share a common element

Due to how nesting works, if the two chains share a common element then
the biggest pair of nodes of the same size are equal
*/
Returns whether the two chains form a loop ie. they share a common element
Due to how nesting works, if the two chains share a common element then
the biggest pair of nodes of the same size are equal
Returns whether the two chains form a loop ie . they share a common element Due to how nesting works if the two chains share a common element then the biggest pair of nodes of the same size are equal
fn chains_form_loop(left: &HexChain, right: &HexChain) -> bool {
	if let (Some(left_head), Some(right_head)) = (left.first(), right.first()) {
		match left_head.size - right_head.size {
			x if x < 0 => {
				right.get(-x as usize)
					.map(|right_elt| left_head == right_elt)
					.unwrap_or( false )
			},
			0 => left_head == right_head,
			x if x > 0 => {
				left.get(x as usize)
					.map(|left_elt| left_elt == right_head)
					.unwrap_or( false )
			},
			_ => unreachable!(),
		}
	} else {
		false
	}
}
fn chains_form_loop ( left : & HexChain , right : & HexChain ) -> bool { if let ( Some ( left_head ) , Some ( right_head ) ) = ( left . first ( ) , right . first ( ) ) { match left_head . size - right_head . size { x if x < 0 => { right . get ( - x as usize ) . map ( | right_elt | left_head == right_elt ) . unwrap_or ( false ) } , 0 => left_head == right_head , x if x > 0 => { left . get ( x as usize ) . map ( | left_elt | left_elt == right_head ) . unwrap_or ( false ) } , _ => unreachable ! ( ) , } } else { false } }
Returns whether the two chains form a loop ie.
Returns whether the two chains form a loop ie .
left
&HexChain
right
&HexChain