pub fn find_ancestor<F>(&self, mut hash: H, mut number: N, condition: F) -> Option<(H, N)>
	where
		F: Fn(&V) -> bool,
	{
		loop {
			match self.find_containing_nodes(hash.clone(), number) {
				None => {
					// The block has a vote-node in the graph.
					let node =
						self.entries.get(&hash).expect("by defn of find_containing_nodes; qed");
					// If the weight is sufficient, we are done.
					if condition(&node.cumulative_vote) {
						return Some((hash, number))
					}
					// Not enough weight, check the parent block.
					match node.ancestors.get(0) {
						None => return None,
						Some(a) => {
							hash = a.clone();
							number = node.number - N::one();
						},
					}
				},
				Some(children) => {
					// If there are no vote-nodes below the block in the graph,
					// the block is not in the graph at all.
					if children.is_empty() {
						return None
					}
					// The block is "contained" in the graph (i.e. in the ancestry-chain
					// of at least one vote-node) but does not itself have a vote-node.
					// Check if the accumulated weight on all child vote-nodes is sufficient.
					let mut v = V::default();
					for c in &children {
						let e = self.entries.get(c).expect("all children in graph; qed");
						v += &e.cumulative_vote;
					}
					if condition(&v) {
						return Some((hash, number))
					}

					// Not enough weight, check the parent block.
					let child = children.last().expect("children not empty; qed");
					let entry = self.entries.get(child).expect("all children in graph; qed");
					let offset = (entry.number - number).as_();
					match entry.ancestors.get(offset) {
						None => return None, // Reached base without sufficient weight.
						Some(parent) => {
							hash = parent.clone();
							number = number - N::one();
						},
					}
				},
			}
		}
	}
/// Find the block with the highest block number in the chain with the given head
/// which fulfills the given condition.
///
/// Returns `None` if the given head is not in the graph or no node fulfills the
/// given condition.
Find the block with the highest block number in the chain with the given head
which fulfills the given condition.

Returns `None` if the given head is not in the graph or no node fulfills the
given condition.
Find the block with the highest block number in the chain with the given head which fulfills the given condition . Returns ` None ` if the given head is not in the graph or no node fulfills the given condition .
pub fn find_ancestor<F>(&self, mut hash: H, mut number: N, condition: F) -> Option<(H, N)>
	where
		F: Fn(&V) -> bool,
	{
		loop {
			match self.find_containing_nodes(hash.clone(), number) {
				None => {
					// The block has a vote-node in the graph.
					let node =
						self.entries.get(&hash).expect("by defn of find_containing_nodes; qed");
					// If the weight is sufficient, we are done.
					if condition(&node.cumulative_vote) {
						return Some((hash, number))
					}
					// Not enough weight, check the parent block.
					match node.ancestors.get(0) {
						None => return None,
						Some(a) => {
							hash = a.clone();
							number = node.number - N::one();
						},
					}
				},
				Some(children) => {
					// If there are no vote-nodes below the block in the graph,
					// the block is not in the graph at all.
					if children.is_empty() {
						return None
					}
					// The block is "contained" in the graph (i.e. in the ancestry-chain
					// of at least one vote-node) but does not itself have a vote-node.
					// Check if the accumulated weight on all child vote-nodes is sufficient.
					let mut v = V::default();
					for c in &children {
						let e = self.entries.get(c).expect("all children in graph; qed");
						v += &e.cumulative_vote;
					}
					if condition(&v) {
						return Some((hash, number))
					}
					// Not enough weight, check the parent block.
					let child = children.last().expect("children not empty; qed");
					let entry = self.entries.get(child).expect("all children in graph; qed");
					let offset = (entry.number - number).as_();
					match entry.ancestors.get(offset) {
						None => return None, // Reached base without sufficient weight.
						Some(parent) => {
							hash = parent.clone();
							number = number - N::one();
						},
					}
				},
			}
		}
	}
pub fn find_ancestor < F > ( & self , mut hash : H , mut number : N , condition : F ) -> Option < ( H , N ) > where F : Fn ( & V ) -> bool , { loop { match self . find_containing_nodes ( hash . clone ( ) , number ) { None => { // The block has a vote-node in the graph. let node = self . entries . get ( & hash ) . expect ( " " ) ; // If the weight is sufficient, we are done. if condition ( & node . cumulative_vote ) { return Some ( ( hash , number ) ) } // Not enough weight, check the parent block. match node . ancestors . get ( 0 ) { None => return None , Some ( a ) => { hash = a . clone ( ) ; number = node . number - N :: one ( ) ; } , } } , Some ( children ) => { // If there are no vote-nodes below the block in the graph, // the block is not in the graph at all. if children . is_empty ( ) { return None } // The block is "contained" in the graph (i.e. in the ancestry-chain // of at least one vote-node) but does not itself have a vote-node. // Check if the accumulated weight on all child vote-nodes is sufficient. let mut v = V :: default ( ) ; for c in & children { let e = self . entries . get ( c ) . expect ( " " ) ; v += & e . cumulative_vote ; } if condition ( & v ) { return Some ( ( hash , number ) ) } // Not enough weight, check the parent block. let child = children . last ( ) . expect ( " " ) ; let entry = self . entries . get ( child ) . expect ( " " ) ; let offset = ( entry . number - number ) . as_ ( ) ; match entry . ancestors . get ( offset ) { None => return None , // Reached base without sufficient weight. Some ( parent ) => { hash = parent . clone ( ) ; number = number - N :: one ( ) ; } , } } , } } }
Find the block with the highest block number in the chain with the given head
which fulfills the given condition.
Find the block with the highest block number in the chain with the given head which fulfills the given condition .
&self
hash
H
number
N
condition
F
&self
hash
H
number
N
condition
F