Skip to content

Commit 6f08c9f

Browse files
committed
Fix panic
1 parent 2640c9a commit 6f08c9f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/combinatorial.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ static MARKER_TABLES: Lazy<HashMap<u8, Vec<u128>>> = Lazy::new(|| {
1111
let mut m = HashMap::new();
1212
for k in 1..10u8 {
1313
let mut table = vec![0u128; MARKER_TABLE_SIZE];
14-
let mut table_size = table.len();
15-
if k == 1 {
16-
table_size = 128;
14+
let table_size = if k == 1 {
15+
128
1716
} else if k == 2 {
18-
table_size = 8128;
19-
}
17+
8128
18+
} else {
19+
table.len()
20+
};
2021

2122
table[0] = ((1 << k) - 1) as u128;
2223
for i in 1..table_size {
@@ -34,7 +35,7 @@ pub fn rank(value: usize, k: u8) -> u128 {
3435
// a bad value (0) if value > (128 choose k) and k == 1 or 2
3536
if value as usize >= MARKER_TABLE_SIZE {
3637
let mut marker = MARKER_TABLES[&k][MARKER_TABLE_SIZE - 1];
37-
for _ in 0..(value - MARKER_TABLE_SIZE) {
38+
for _ in 1..(value - MARKER_TABLE_SIZE) {
3839
marker = next_rank(marker);
3940
}
4041
marker
@@ -105,7 +106,7 @@ pub fn choose(n: u64, k: u8) -> u64 {
105106
#[inline]
106107
fn next_rank(marker: u128) -> u128 {
107108
if marker == 0 {
108-
unreachable!("WOOPS");
109+
unreachable!("Got next_rank called with marker == 0");
109110
}
110111
let t = marker | (marker - 1);
111112
(t + 1) | (((!t & (t + 1)) - 1) >> (marker.trailing_zeros() + 1))

0 commit comments

Comments
 (0)