Rename Memory to Computer

This commit is contained in:
Wesley Moore 2019-12-07 17:25:55 +11:00
parent 102a98fc82
commit b53033b15d
No known key found for this signature in database
GPG key ID: BF67766C0BC2D0EE
2 changed files with 5 additions and 5 deletions

View file

@ -4,7 +4,7 @@ use std::{fs, io};
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
let input = fs::read_to_string("input/day5.txt")?; let input = fs::read_to_string("input/day5.txt")?;
let mut data = input::read_separated_line(',', &input)?; let mut data = input::read_separated_line(',', &input)?;
let mut program = computer::Memory::new(&mut data); let mut program = computer::Computer::new(&mut data);
program.run(None, None); program.run(None, None);

View file

@ -23,7 +23,7 @@ enum Mode {
Address, Address,
} }
pub struct Memory<'a> { pub struct Computer<'a> {
mem: &'a mut [i32], mem: &'a mut [i32],
} }
@ -66,9 +66,9 @@ fn decode(mut instruction: i32) -> Instruction {
} }
} }
impl<'a> Memory<'a> { impl<'a> Computer<'a> {
pub fn new(mem: &'a mut [i32]) -> Self { pub fn new(mem: &'a mut [i32]) -> Self {
Memory { mem } Computer { mem }
} }
fn read(&self, value: i32, mode: Mode) -> i32 { fn read(&self, value: i32, mode: Mode) -> i32 {
@ -191,7 +191,7 @@ mod tests {
fn test_day2() { fn test_day2() {
let input = fs::read_to_string("input/day2.txt").unwrap(); let input = fs::read_to_string("input/day2.txt").unwrap();
let mut data = input::read_separated_line(',', &input).unwrap(); let mut data = input::read_separated_line(',', &input).unwrap();
let mut program = Memory::new(&mut data); let mut program = Computer::new(&mut data);
// Check that day2 still works wirh run through this implementation // Check that day2 still works wirh run through this implementation
program.run(Some(12), Some(2)); program.run(Some(12), Some(2));