fn ghost_find_merge_point<'a, F>(
		&'a self,
		node_key: H,
		active_node: &'a Entry<H, N, V>,
		force_constrain: Option<(H, N)>,
		condition: F,
	) -> Subchain<H, N>
	where
		F: Fn(&V) -> bool,
	{
		let mut descendent_nodes: Vec<_> = active_node
			.descendents
			.iter()
			.map(|h| self.entries.get(h).expect("descendents always present in node storage; qed"))
			.filter(|n| {
				if let Some((ref h, num)) = force_constrain {
					n.in_direct_ancestry(h, num).unwrap_or(false)
				} else {
					true
				}
			})
			.collect();

		let base_number = active_node.number;
		let mut best_number = active_node.number;
		let mut descendent_blocks = Vec::with_capacity(descendent_nodes.len());
		let mut hashes = vec![node_key];

		// TODO: for long ranges of blocks this could get inefficient
		let mut offset = N::zero();
		loop {
			offset = offset + N::one();

			let mut new_best = None;
			for d_node in &descendent_nodes {
				if let Some(d_block) = d_node.ancestor_block(base_number + offset) {
					match descendent_blocks.binary_search_by_key(&d_block, |&(ref x, _)| x) {
						Ok(idx) => {
							descendent_blocks[idx].1 += &d_node.cumulative_vote;
							if condition(&descendent_blocks[idx].1) {
								new_best = Some(d_block.clone());
								break
							}
						},
						Err(idx) => descendent_blocks
							.insert(idx, (d_block.clone(), d_node.cumulative_vote.clone())),
					}
				}
			}

			match new_best {
				Some(new_best) => {
					best_number = best_number + N::one();

					descendent_blocks.clear();
					descendent_nodes
						.retain(|n| n.in_direct_ancestry(&new_best, best_number).unwrap_or(false));

					hashes.push(new_best);
				},
				None => break,
			}
		}

		Subchain { hashes, best_number }
	}
// given a key, node pair (which must correspond), assuming this node fulfills the condition,
// this function will find the highest point at which its descendents merge, which may be the
// node itself.
given a key, node pair (which must correspond), assuming this node fulfills the condition,
this function will find the highest point at which its descendents merge, which may be the
node itself.
given a key node pair ( which must correspond ) assuming this node fulfills the condition this function will find the highest point at which its descendents merge which may be the node itself .
fn ghost_find_merge_point<'a, F>(
		&'a self,
		node_key: H,
		active_node: &'a Entry<H, N, V>,
		force_constrain: Option<(H, N)>,
		condition: F,
	) -> Subchain<H, N>
	where
		F: Fn(&V) -> bool,
	{
		let mut descendent_nodes: Vec<_> = active_node
			.descendents
			.iter()
			.map(|h| self.entries.get(h).expect("descendents always present in node storage; qed"))
			.filter(|n| {
				if let Some((ref h, num)) = force_constrain {
					n.in_direct_ancestry(h, num).unwrap_or(false)
				} else {
					true
				}
			})
			.collect();
		let base_number = active_node.number;
		let mut best_number = active_node.number;
		let mut descendent_blocks = Vec::with_capacity(descendent_nodes.len());
		let mut hashes = vec![node_key];
		// TODO: for long ranges of blocks this could get inefficient
		let mut offset = N::zero();
		loop {
			offset = offset + N::one();
			let mut new_best = None;
			for d_node in &descendent_nodes {
				if let Some(d_block) = d_node.ancestor_block(base_number + offset) {
					match descendent_blocks.binary_search_by_key(&d_block, |&(ref x, _)| x) {
						Ok(idx) => {
							descendent_blocks[idx].1 += &d_node.cumulative_vote;
							if condition(&descendent_blocks[idx].1) {
								new_best = Some(d_block.clone());
								break
							}
						},
						Err(idx) => descendent_blocks
							.insert(idx, (d_block.clone(), d_node.cumulative_vote.clone())),
					}
				}
			}
			match new_best {
				Some(new_best) => {
					best_number = best_number + N::one();
					descendent_blocks.clear();
					descendent_nodes
						.retain(|n| n.in_direct_ancestry(&new_best, best_number).unwrap_or(false));
					hashes.push(new_best);
				},
				None => break,
			}
		}
		Subchain { hashes, best_number }
	}
fn ghost_find_merge_point < ' a , F > ( & ' a self , node_key : H , active_node : & ' a Entry < H , N , V > , force_constrain : Option < ( H , N ) > , condition : F , ) -> Subchain < H , N > where F : Fn ( & V ) -> bool , { let mut descendent_nodes : Vec < _ > = active_node . descendents . iter ( ) . map ( | h | self . entries . get ( h ) . expect ( " " ) ) . filter ( | n | { if let Some ( ( ref h , num ) ) = force_constrain { n . in_direct_ancestry ( h , num ) . unwrap_or ( false ) } else { true } } ) . collect ( ) ; let base_number = active_node . number ; let mut best_number = active_node . number ; let mut descendent_blocks = Vec :: with_capacity ( descendent_nodes . len ( ) ) ; let mut hashes = vec ! [ node_key ] ; // TODO: for long ranges of blocks this could get inefficient let mut offset = N :: zero ( ) ; loop { offset = offset + N :: one ( ) ; let mut new_best = None ; for d_node in & descendent_nodes { if let Some ( d_block ) = d_node . ancestor_block ( base_number + offset ) { match descendent_blocks . binary_search_by_key ( & d_block , | & ( ref x , _ ) | x ) { Ok ( idx ) => { descendent_blocks [ idx ] . 1 += & d_node . cumulative_vote ; if condition ( & descendent_blocks [ idx ] . 1 ) { new_best = Some ( d_block . clone ( ) ) ; break } } , Err ( idx ) => descendent_blocks . insert ( idx , ( d_block . clone ( ) , d_node . cumulative_vote . clone ( ) ) ) , } } } match new_best { Some ( new_best ) => { best_number = best_number + N :: one ( ) ; descendent_blocks . clear ( ) ; descendent_nodes . retain ( | n | n . in_direct_ancestry ( & new_best , best_number ) . unwrap_or ( false ) ) ; hashes . push ( new_best ) ; } , None => break , } } Subchain { hashes , best_number } }
given a key, node pair (which must correspond), assuming this node fulfills the condition,
this function will find the highest point at which its descendents merge, which may be the
node itself.
given a key node pair ( which must correspond ) assuming this node fulfills the condition this function will find the highest point at which its descendents merge which may be the node itself .
&'a self
node_key
H
active_node
&'a Entry<H, N, V>
force_constrain
Option<(H, N)>
condition
F
&'a self
node_key
H
active_node
&'a Entry<H, N, V>
force_constrain
Option<(H, N)>
condition
F