Skip to main content

Module bijectivemap

Module bijectivemap 

Source
Expand description

Skeleton module for the bijective hashmap assignment.

Be sure to read the assignment description in the C++ version of this program that you’re supposed to emulate.

This module currently compiles and provides you with some helpful code, but there are four methods that you must implement properly (see documentation for each BijectiveMap method).

Go into the csc_7b_fc crate and git pull the latest updates. Then cargo new a fresh crate for your assignment and optionally add the path to csc_7b_fc to Cargo.toml as you did for the first Rust assignment.

Do not touch the csc_7b_fc crate. Copy the bijectivemap.rs file to the src directory of your own crate, then place the following in the main.rs of your crate.

   mod bijectivemap;
   use bijectivemap::*;

NOTE: DO NOT EDIT THE csc_7b_fc CRATE. Copy the skeleton code to your own crate!

When you have completed the implementation, emulate the main in the C++ program to test it. It can begin with …

    let mut daynum:BijectiveMap<&'static str,u8> = BijectiveMap::new();
    let days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
    for i in 0..days.len() { daynum.set(days[i],(i+1) as u8); }
    daynum.get_by_key(&"Wednesday").map(|d|{
      println!("Wednesday is day {}",d);
    });

The studenthasher component that tests hash collisions is optional.

Structs§

BijectiveMap
This is your bijective map struct
HashStealer
The HashStealer struct and methods allows you to “steal” the hash functions from Rust, and base_hash can be called on any key that implements Hash+Eq. Hashing requires equality and must be consistent with it: if x==y then hash(x)==hash(y).