/
naive.rs
42 lines (33 loc) · 1.03 KB
/
naive.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
// ------------------------------------------------------ snip ------------------------------------------------------ //
pub struct ParkingSystem {
slots: [u32; 3],
}
impl ParkingSystem {
fn new(big: i32, medium: i32, small: i32) -> Self {
Self {
slots: [big as _, medium as _, small as _],
}
}
fn add_car(&mut self, car_type: i32) -> bool {
let slot = &mut self.slots[car_type as u32 as usize - 1];
let is_available = *slot != 0;
*slot -= u32::from(is_available);
is_available
}
}
// ------------------------------------------------------ snip ------------------------------------------------------ //
impl super::ParkingSystem for ParkingSystem {
fn new(big: i32, medium: i32, small: i32) -> Self {
Self::new(big, medium, small)
}
fn add_car(&mut self, car_type: i32) -> bool {
self.add_car(car_type)
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_solution() {
super::super::tests::run::<super::ParkingSystem>();
}
}