// introduce a branch to given vote-nodes.
//
// `descendents` is a list of nodes with ancestor-edges containing the given ancestor.
//
// This function panics if any member of `descendents` is not a vote-node
// or does not have ancestor with given hash and number OR if `ancestor_hash`
// is already a known entry.
introduce a branch to given vote-nodes.
`descendents` is a list of nodes with ancestor-edges containing the given ancestor.

This function panics if any member of `descendents` is not a vote-node
or does not have ancestor with given hash and number OR if `ancestor_hash`
is already a known entry.
introduce a branch to given vote - nodes . ` descendents ` is a list of nodes with ancestor - edges containing the given ancestor . This function panics if any member of ` descendents ` is not a vote - node or does not have ancestor with given hash and number OR if ` ancestor_hash ` is already a known entry .
fn introduce_branch(&mut self, descendents: Vec<H>, ancestor_hash: H, ancestor_number: N) {
		let produced_entry = descendents.into_iter().fold(None, |mut maybe_entry, descendent| {
			let entry = self
				.entries
				.get_mut(&descendent)
				.expect("this function only invoked with keys of vote-nodes; qed");
			debug_assert!(entry.in_direct_ancestry(&ancestor_hash, ancestor_number).unwrap());
			// example: splitting number 10 at ancestor 4
			// before: [9 8 7 6 5 4 3 2 1]
			// after: [9 8 7 6 5 4], [3 2 1]
			// we ensure the `entry.ancestors` is drained regardless of whether
			// the `new_entry` has already been constructed.
			{
				let prev_ancestor = entry.ancestor_node();
				let offset_usize: usize = if ancestor_number > entry.number {
					panic!("this function only invoked with direct ancestors; qed")
				} else {
					(entry.number - ancestor_number).as_()
				};
				let new_ancestors = entry.ancestors.drain(offset_usize..);
				let &mut (ref mut new_entry, _) = maybe_entry.get_or_insert_with(move || {
					let new_entry = Entry {
						number: ancestor_number,
						ancestors: new_ancestors.collect(),
						descendents: vec![],
						cumulative_vote: V::default(),
					};
					(new_entry, prev_ancestor)
				});
				new_entry.descendents.push(descendent);
				new_entry.cumulative_vote += &entry.cumulative_vote;
			}
			maybe_entry
		});
		if let Some((new_entry, prev_ancestor)) = produced_entry {
			if let Some(prev_ancestor) = prev_ancestor {
				let prev_ancestor_node = self
					.entries
					.get_mut(&prev_ancestor)
					.expect("Prior ancestor is referenced from a node; qed");
				prev_ancestor_node.descendents.retain(|h| !new_entry.descendents.contains(h));
				prev_ancestor_node.descendents.push(ancestor_hash.clone());
			}
			assert!(
				self.entries.insert(ancestor_hash, new_entry).is_none(),
				"thus function is only invoked when there is no entry for the ancestor already; qed",
			)
		}
	}
fn introduce_branch ( & mut self , descendents : Vec < H > , ancestor_hash : H , ancestor_number : N ) { let produced_entry = descendents . into_iter ( ) . fold ( None , | mut maybe_entry , descendent | { let entry = self . entries . get_mut ( & descendent ) . expect ( " " ) ; debug_assert ! ( entry in_direct_ancestry ( ancestor_hash ancestor_number ) unwrap ( ) ) ; // example: splitting number 10 at ancestor 4 // before: [9 8 7 6 5 4 3 2 1] // after: [9 8 7 6 5 4], [3 2 1] // we ensure the `entry.ancestors` is drained regardless of whether // the `new_entry` has already been constructed. { let prev_ancestor = entry . ancestor_node ( ) ; let offset_usize : usize = if ancestor_number > entry . number { panic ! ( " " ) } else { ( entry . number - ancestor_number ) . as_ ( ) } ; let new_ancestors = entry . ancestors . drain ( offset_usize .. ) ; let & mut ( ref mut new_entry , _ ) = maybe_entry . get_or_insert_with ( move | | { let new_entry = Entry { number : ancestor_number , ancestors : new_ancestors . collect ( ) , descendents : vec ! [ ] , cumulative_vote : V :: default ( ) , } ; ( new_entry , prev_ancestor ) } ) ; new_entry . descendents . push ( descendent ) ; new_entry . cumulative_vote += & entry . cumulative_vote ; } maybe_entry } ) ; if let Some ( ( new_entry , prev_ancestor ) ) = produced_entry { if let Some ( prev_ancestor ) = prev_ancestor { let prev_ancestor_node = self . entries . get_mut ( & prev_ancestor ) . expect ( " " ) ; prev_ancestor_node . descendents . retain ( | h | ! new_entry . descendents . contains ( h ) ) ; prev_ancestor_node . descendents . push ( ancestor_hash . clone ( ) ) ; } assert ! ( self entries insert ( ancestor_hash new_entry ) is_none ( ) " " ) } }
introduce a branch to given vote-nodes.
introduce a branch to given vote - nodes .
&mut self
descendents
Vec<H>
ancestor_hash
H
ancestor_number
N