// append a vote-node onto the chain-tree. This should only be called if
// no node in the tree keeps the target anyway.
append a vote-node onto the chain-tree. This should only be called if
no node in the tree keeps the target anyway.
append a vote - node onto the chain - tree . This should only be called if no node in the tree keeps the target anyway .
fn append<C: Chain<H, N>>(&mut self, hash: H, number: N, chain: &C) -> Result<(), Error> {
		let mut ancestry = chain.ancestry(self.base.clone(), hash.clone())?;
		ancestry.push(self.base.clone()); // ancestry doesn't include base.
		let mut ancestor_index = None;
		for (i, ancestor) in ancestry.iter().enumerate() {
			if let Some(entry) = self.entries.get_mut(ancestor) {
				entry.descendents.push(hash.clone());
				ancestor_index = Some(i);
				break
			}
		}
		let ancestor_index = ancestor_index.expect(
			"base is kept; \
			chain returns ancestry only if the block is a descendent of base; qed",
		);
		let ancestor_hash = ancestry[ancestor_index].clone();
		ancestry.truncate(ancestor_index + 1);
		self.entries.insert(
			hash.clone(),
			Entry {
				number,
				ancestors: ancestry,
				descendents: Vec::new(),
				cumulative_vote: V::default(),
			},
		);
		self.heads.remove(&ancestor_hash);
		self.heads.insert(hash);
		Ok(())
	}
fn append < C : Chain < H , N > > ( & mut self , hash : H , number : N , chain : & C ) -> Result < ( ) , Error > { let mut ancestry = chain . ancestry ( self . base . clone ( ) , hash . clone ( ) ) ? ; ancestry . push ( self . base . clone ( ) ) ; // ancestry doesn't include base. let mut ancestor_index = None ; for ( i , ancestor ) in ancestry . iter ( ) . enumerate ( ) { if let Some ( entry ) = self . entries . get_mut ( ancestor ) { entry . descendents . push ( hash . clone ( ) ) ; ancestor_index = Some ( i ) ; break } } let ancestor_index = ancestor_index . expect ( " \
 " , ) ; let ancestor_hash = ancestry [ ancestor_index ] . clone ( ) ; ancestry . truncate ( ancestor_index + 1 ) ; self . entries . insert ( hash . clone ( ) , Entry { number , ancestors : ancestry , descendents : Vec :: new ( ) , cumulative_vote : V :: default ( ) , } , ) ; self . heads . remove ( & ancestor_hash ) ; self . heads . insert ( hash ) ; Ok ( ( ) ) }
append a vote-node onto the chain-tree.
append a vote - node onto the chain - tree .
&mut self
hash
H
number
N
chain
&C