forked from amethyst/specs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitset.rs
43 lines (34 loc) · 959 Bytes
/
bitset.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extern crate hibitset;
extern crate specs;
use hibitset::{BitSet, BitSetNot};
use specs::prelude::*;
const COUNT: u32 = 100;
fn main() {
let mut every3 = BitSet::new();
for i in 0..COUNT {
if i % 3 == 0 {
every3.add(i);
}
}
let mut every5 = BitSet::new();
for i in 0..COUNT {
if i % 5 == 0 {
every5.add(i);
}
}
// over engineered fizzbuzz because why not
let mut list: Vec<String> = Vec::with_capacity(COUNT as usize);
for id in 0..COUNT {
list.push(format!("{}", id));
}
for (id, _) in (&BitSetNot(&every3), &every5).join() {
list[id as usize] = format!("fizz {}", id);
}
for (id, _) in (&BitSetNot(&every5), &every3).join() {
list[id as usize] = format!("buzz {}", id);
}
for (id, _) in (&every3, &every5).join() {
list[id as usize] = format!("fizzbuzz {}", id);
}
println!("{:#?}", list);
}