|
8 | 8 | { |
9 | 9 | let mut cache = BTreeMap::new(); |
10 | 10 | let mut predicate = |idx: usize, rm_no, lm_yes| { |
11 | | - let range = lm_yes - rm_no + 1; |
| 11 | + let range: usize = lm_yes - rm_no + 1; |
12 | 12 | // FIXME: This does not consider unknown_ranges. |
13 | 13 | let remaining = range / 2; |
14 | | - let estimate = estimate_steps(range); |
| 14 | + let estimate = if range < 3 { 0 } else { range.ilog2() as usize }; |
15 | 15 | *cache |
16 | 16 | .entry(idx) |
17 | 17 | .or_insert_with(|| predicate(&slice[idx], remaining, estimate)) |
@@ -76,33 +76,10 @@ where |
76 | 76 | } |
77 | 77 | } |
78 | 78 |
|
79 | | -fn estimate_steps(range: usize) -> usize { |
80 | | - // Replace with int_log when it is stabilized. |
81 | | - let log2 = |mut n| { |
82 | | - let mut r = 0; |
83 | | - while n > 1 { |
84 | | - r += 1; |
85 | | - n >>= 1; |
86 | | - } |
87 | | - r |
88 | | - }; |
89 | | - if range < 3 { |
90 | | - return 0; |
91 | | - } |
92 | | - let n = log2(range); |
93 | | - let e = 1 << n; |
94 | | - let x = range - e; |
95 | | - if e < 3 * x { |
96 | | - n |
97 | | - } else { |
98 | | - n - 1 |
99 | | - } |
100 | | -} |
101 | | - |
102 | 79 | #[cfg(test)] |
103 | 80 | mod tests { |
104 | 81 | use super::Satisfies::{No, Unknown, Yes}; |
105 | | - use super::{estimate_steps, least_satisfying, Satisfies}; |
| 82 | + use super::{least_satisfying, Satisfies}; |
106 | 83 | use quickcheck::{QuickCheck, TestResult}; |
107 | 84 |
|
108 | 85 | fn prop(xs: Vec<Option<bool>>) -> TestResult { |
@@ -186,22 +163,6 @@ mod tests { |
186 | 163 | fn qc_prop() { |
187 | 164 | QuickCheck::new().quickcheck(prop as fn(_) -> _); |
188 | 165 | } |
189 | | - |
190 | | - #[test] |
191 | | - fn estimates() { |
192 | | - for (n, expect) in &[ |
193 | | - (0, 0), |
194 | | - (1, 0), |
195 | | - (2, 0), |
196 | | - (3, 1), |
197 | | - (4, 1), |
198 | | - (5, 1), |
199 | | - (6, 2), |
200 | | - (150, 6), |
201 | | - ] { |
202 | | - assert_eq!(estimate_steps(*n), *expect); |
203 | | - } |
204 | | - } |
205 | 166 | } |
206 | 167 |
|
207 | 168 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
|
0 commit comments