MCPcopy Create free account
hub / github.com/ddd/gpb / estimate_fullscan_workload

Function estimate_fullscan_workload

src/utils/estimation.rs:138–179  ·  view source on GitHub ↗

Estimate workload for full scan (number generation) mode

(
    country_code: &str,
    prefix: &str,
    suffix: &str,
    infix: Option<&str>,
    digits_override: Option<usize>
)

Source from the content-addressed store, hash-verified

136
137/// Estimate workload for full scan (number generation) mode
138fn estimate_fullscan_workload(
139 country_code: &str,
140 prefix: &str,
141 suffix: &str,
142 infix: Option<&str>,
143 digits_override: Option<usize>
144) -> Result<u64, Error> {
145 // Try to get country format
146 match get_country_format(country_code) {
147 Ok(format) => {
148 // Create a generator to get estimate
149 let generator = PhoneNumberGenerator::new(
150 &format,
151 if prefix.is_empty() { None } else { Some(prefix.to_string()) },
152 if suffix.is_empty() { None } else { Some(suffix.to_string()) },
153 infix.map(|s| s.to_string()),
154 digits_override
155 )?;
156
157 Ok(generator.estimate_total())
158 },
159 Err(_) => {
160 // If no format, use digits parameter
161 if let Some(digit_count) = digits_override {
162 let total = 10_u64.pow(digit_count as u32);
163
164 // Apply reduction for infix if present
165 let adjusted_total = if let Some(infix_val) = infix {
166 // Each digit in the infix reduces the probability by a factor of 10
167 let infix_factor = 10_u64.pow(infix_val.len() as u32);
168 std::cmp::max(1, total / infix_factor)
169 } else {
170 total
171 };
172
173 Ok(adjusted_total)
174 } else {
175 Err(anyhow!("Cannot estimate: No country format found and no digits override provided"))
176 }
177 }
178 }
179}

Callers 1

calculate_estimateFunction · 0.85

Calls 2

get_country_formatFunction · 0.85
estimate_totalMethod · 0.80

Tested by

no test coverage detected