fn lower_bound_max_digest(
	config: &Configuration,
	max: u64,
	begin: u64,
	end: u64,
) -> Result<(u64, u64, u64, u32), String> {
	if end > max || begin > end {
		return Err("invalid changes range".into());
	}

	let mut digest_level = 0u32;
	let mut digest_step = 1u64;
	let mut digest_interval = 0u64;
	let mut current = end;
	let mut current_begin = begin;
	if begin != end {
		while digest_level != config.digest_levels {
			let new_digest_level = digest_level + 1;
			let new_digest_step = digest_step * config.digest_interval;
			let new_digest_interval = config.digest_interval * {
				if digest_interval == 0 { 1 } else { digest_interval }
			};
			let new_digest_begin = ((current - 1) / new_digest_interval) * new_digest_interval;
			let new_digest_end = new_digest_begin + new_digest_interval;
			let new_current = new_digest_begin + new_digest_interval;

			if new_digest_end > max {
				if begin < new_digest_begin {
					current_begin = new_digest_begin;
				}
				break;
			}

			digest_level = new_digest_level;
			digest_step = new_digest_step;
			digest_interval = new_digest_interval;
			current = new_current;
			current_begin = new_digest_begin;

			if new_digest_begin <= begin && new_digest_end >= end {
				break;
			}
		}
	}

	Ok((
		current,
		current_begin,
		digest_step,
		digest_level,
	))
}
/// Returns parameters of highest level digest block that includes the end of given range
/// and tends to include the whole range.
Returns parameters of highest level digest block that includes the end of given range
and tends to include the whole range.
Returns parameters of highest level digest block that includes the end of given range and tends to include the whole range .
fn lower_bound_max_digest(
	config: &Configuration,
	max: u64,
	begin: u64,
	end: u64,
) -> Result<(u64, u64, u64, u32), String> {
	if end > max || begin > end {
		return Err("invalid changes range".into());
	}
	let mut digest_level = 0u32;
	let mut digest_step = 1u64;
	let mut digest_interval = 0u64;
	let mut current = end;
	let mut current_begin = begin;
	if begin != end {
		while digest_level != config.digest_levels {
			let new_digest_level = digest_level + 1;
			let new_digest_step = digest_step * config.digest_interval;
			let new_digest_interval = config.digest_interval * {
				if digest_interval == 0 { 1 } else { digest_interval }
			};
			let new_digest_begin = ((current - 1) / new_digest_interval) * new_digest_interval;
			let new_digest_end = new_digest_begin + new_digest_interval;
			let new_current = new_digest_begin + new_digest_interval;
			if new_digest_end > max {
				if begin < new_digest_begin {
					current_begin = new_digest_begin;
				}
				break;
			}
			digest_level = new_digest_level;
			digest_step = new_digest_step;
			digest_interval = new_digest_interval;
			current = new_current;
			current_begin = new_digest_begin;
			if new_digest_begin <= begin && new_digest_end >= end {
				break;
			}
		}
	}
	Ok((
		current,
		current_begin,
		digest_step,
		digest_level,
	))
}
fn lower_bound_max_digest ( config : & Configuration , max : u64 , begin : u64 , end : u64 , ) -> Result < ( u64 , u64 , u64 , u32 ) , String > { if end > max || begin > end { return Err ( " " . into ( ) ) ; } let mut digest_level = 0u32 ; let mut digest_step = 1u64 ; let mut digest_interval = 0u64 ; let mut current = end ; let mut current_begin = begin ; if begin != end { while digest_level != config . digest_levels { let new_digest_level = digest_level + 1 ; let new_digest_step = digest_step * config . digest_interval ; let new_digest_interval = config . digest_interval * { if digest_interval == 0 { 1 } else { digest_interval } } ; let new_digest_begin = ( ( current - 1 ) / new_digest_interval ) * new_digest_interval ; let new_digest_end = new_digest_begin + new_digest_interval ; let new_current = new_digest_begin + new_digest_interval ; if new_digest_end > max { if begin < new_digest_begin { current_begin = new_digest_begin ; } break ; } digest_level = new_digest_level ; digest_step = new_digest_step ; digest_interval = new_digest_interval ; current = new_current ; current_begin = new_digest_begin ; if new_digest_begin <= begin && new_digest_end >= end { break ; } } } Ok ( ( current , current_begin , digest_step , digest_level , ) ) }
Returns parameters of highest level digest block that includes the end of given range
and tends to include the whole range.
Returns parameters of highest level digest block that includes the end of given range and tends to include the whole range .
config
&Configuration
max
u64
begin
u64
end
u64
config
&Configuration
max
u64
begin
u64
end
u64