Last active
August 29, 2015 14:16
-
-
Save bvssvni/e9333849873e830ef6a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl<'a> ToIndex<usize, &'a [usize]> for Permutation<Data> { | |
fn to_index(&self, dim: usize, pos: &'a [usize]) -> usize { | |
let mut index = 0; | |
let mut count = self.count(dim); | |
for (i, &x) in pos.iter().enumerate() { | |
count /= dim - i; | |
let lower = pos[..i].iter().fold(0, |a, &y| | |
if y < x { a + 1 } else { a }); | |
index += count * (x - lower); | |
} | |
index | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment