Skip to content

Fixed algorithm to match shootout requirements #27636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions src/test/bench/shootout-fasta-redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,12 @@ static HOMO_SAPIENS: [AminoAcid;4] = [
AminoAcid { c: 't' as u8, p: 0.3015094502008 },
];

// FIXME: Use map().
fn sum_and_scale(a: &'static [AminoAcid]) -> Vec<AminoAcid> {
let mut result = Vec::new();
let mut p = 0f32;
for a_i in a {
let mut a_i = *a_i;
p += a_i.p;
a_i.p = p * LOOKUP_SCALE;
result.push(a_i);
}
let mut result: Vec<AminoAcid> = a.iter().map(|a_i| {
p += a_i.p;
AminoAcid { c: a_i.c, p: p * LOOKUP_SCALE }
}).collect();
let result_len = result.len();
result[result_len - 1].p = LOOKUP_SCALE;
result
Expand Down Expand Up @@ -177,17 +173,17 @@ impl<'a, W: Write> RandomFasta<'a, W> {

fn rng(&mut self, max: f32) -> f32 {
self.seed = (self.seed * IA + IC) % IM;
max * (self.seed as f32) / (IM as f32)
(max * self.seed as f32) / (IM as f32)
}

fn nextc(&mut self) -> u8 {
let r = self.rng(1.0);
for a in &self.lookup[..] {
if a.p >= r {
return a.c;
let r = self.rng(LOOKUP_SCALE);
for i in (r as usize..LOOKUP_SIZE) {
if self.lookup[i].p >= r {
return self.lookup[i].c;
}
}
0
unreachable!();
}

fn make(&mut self, n: usize) -> io::Result<()> {
Expand Down Expand Up @@ -216,8 +212,9 @@ fn main() {
} else {
5
};

let mut out = io::stdout();

let stdout = io::stdout();
let mut out = stdout.lock();

out.write_all(b">ONE Homo sapiens alu\n").unwrap();
{
Expand Down