From 8039d1c21f6bd87f7d7d1f4e7e1485ca2c8d35fc Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <6977238-fiplox@users.noreply.gitlab.com> Date: Sat, 31 Oct 2020 18:05:23 +0100 Subject: [PATCH] function to create hash map from Vec --- src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.rs b/src/main.rs index 0c6e249..e9e1c5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,12 @@ fn check_collisions(r: &robot::Robot, h: &HashMap) -> Resu } } +fn create_hash_map(pool: &Vec, hash: &mut HashMap) { + for r in pool { + hash.insert(robot::Position { x: r.p.x, y: r.p.y }, r.id); + } +} + /// Parse the config file, generate the world and robot pool. fn parse_config(conf: String, pool: &mut Vec) -> Result { let mut lines = conf.lines(); @@ -209,6 +215,8 @@ fn main() -> Result<(), Box> { let mut robot_pool: Vec = Vec::new(); let world: world::World = parse_config(raw_conf, &mut robot_pool)?; + let mut hash: HashMap = HashMap::new(); + create_hash_map(&robot_pool, &mut hash); Ok(()) }