pub fn for_each_cht_group<Header, I, F, P>(
	cht_size: u64,
	blocks: I,
	mut functor: F,
	mut functor_param: P,
) -> ClientResult<()>
	where
		Header: HeaderT,
		I: IntoIterator<Item=Header::Number>,
		F: FnMut(P, Header::Number, Vec<Header::Number>) -> ClientResult<P>,
{
	let mut current_cht_num = None;
	let mut current_cht_blocks = Vec::new();
	for block in blocks {
		let new_cht_num = match block_to_cht_number(cht_size, block.as_()) {
			Some(new_cht_num) => new_cht_num,
			None => return Err(ClientErrorKind::Backend(format!(
				"Cannot compute CHT root for the block #{}", block)).into()
			),
		};

		let advance_to_next_cht = current_cht_num.is_some() && current_cht_num != Some(new_cht_num);
		if advance_to_next_cht {
			let current_cht_num = current_cht_num.expect("advance_to_next_cht is true;
				it is true only when current_cht_num is Some; qed");
			assert!(new_cht_num > current_cht_num, "for_each_cht_group only supports ordered iterators");

			functor_param = functor(
				functor_param,
				As::sa(current_cht_num),
				::std::mem::replace(&mut current_cht_blocks, Vec::new()),
			)?;
		}

		current_cht_blocks.push(block);
		current_cht_num = Some(new_cht_num);
	}

	if let Some(current_cht_num) = current_cht_num {
		functor(
			functor_param,
			As::sa(current_cht_num),
			::std::mem::replace(&mut current_cht_blocks, Vec::new()),
		)?;
	}

	Ok(())
}
/// Group ordered blocks by CHT number and call functor with blocks of each group.
Group ordered blocks by CHT number and call functor with blocks of each group.
Group ordered blocks by CHT number and call functor with blocks of each group .
pub fn for_each_cht_group<Header, I, F, P>(
	cht_size: u64,
	blocks: I,
	mut functor: F,
	mut functor_param: P,
) -> ClientResult<()>
	where
		Header: HeaderT,
		I: IntoIterator<Item=Header::Number>,
		F: FnMut(P, Header::Number, Vec<Header::Number>) -> ClientResult<P>,
{
	let mut current_cht_num = None;
	let mut current_cht_blocks = Vec::new();
	for block in blocks {
		let new_cht_num = match block_to_cht_number(cht_size, block.as_()) {
			Some(new_cht_num) => new_cht_num,
			None => return Err(ClientErrorKind::Backend(format!(
				"Cannot compute CHT root for the block #{}", block)).into()
			),
		};
		let advance_to_next_cht = current_cht_num.is_some() && current_cht_num != Some(new_cht_num);
		if advance_to_next_cht {
			let current_cht_num = current_cht_num.expect("advance_to_next_cht is true;
				it is true only when current_cht_num is Some; qed");
			assert!(new_cht_num > current_cht_num, "for_each_cht_group only supports ordered iterators");
			functor_param = functor(
				functor_param,
				As::sa(current_cht_num),
				::std::mem::replace(&mut current_cht_blocks, Vec::new()),
			)?;
		}
		current_cht_blocks.push(block);
		current_cht_num = Some(new_cht_num);
	}
	if let Some(current_cht_num) = current_cht_num {
		functor(
			functor_param,
			As::sa(current_cht_num),
			::std::mem::replace(&mut current_cht_blocks, Vec::new()),
		)?;
	}
	Ok(())
}
pub fn for_each_cht_group < Header , I , F , P > ( cht_size : u64 , blocks : I , mut functor : F , mut functor_param : P , ) -> ClientResult < ( ) > where Header : HeaderT , I : IntoIterator < Item = Header :: Number > , F : FnMut ( P , Header :: Number , Vec < Header :: Number > ) -> ClientResult < P > , { let mut current_cht_num = None ; let mut current_cht_blocks = Vec :: new ( ) ; for block in blocks { let new_cht_num = match block_to_cht_number ( cht_size , block . as_ ( ) ) { Some ( new_cht_num ) => new_cht_num , None => return Err ( ClientErrorKind :: Backend ( format ! ( " " block ) ) . into ( ) ) , } ; let advance_to_next_cht = current_cht_num . is_some ( ) && current_cht_num != Some ( new_cht_num ) ; if advance_to_next_cht { let current_cht_num = current_cht_num . expect ( " " ) ; assert ! ( new_cht_num current_cht_num " " ) ; functor_param = functor ( functor_param , As :: sa ( current_cht_num ) , :: std :: mem :: replace ( & mut current_cht_blocks , Vec :: new ( ) ) , ) ? ; } current_cht_blocks . push ( block ) ; current_cht_num = Some ( new_cht_num ) ; } if let Some ( current_cht_num ) = current_cht_num { functor ( functor_param , As :: sa ( current_cht_num ) , :: std :: mem :: replace ( & mut current_cht_blocks , Vec :: new ( ) ) , ) ? ; } Ok ( ( ) ) }
Group ordered blocks by CHT number and call functor with blocks of each group.
Group ordered blocks by CHT number and call functor with blocks of each group .
cht_size
u64
blocks
I
functor
F
functor_param
P
cht_size
u64
blocks
I
functor
F
functor_param
P