CS253

CS253: Software Development with C++                

Spring 2017                

Hash                

Hash Lab                

In this lab, we will look at a simple hashing container. The files are in ~cs253/Labs/Hash.                 

A Hash Template                

In main.cc, we have a program that uses the hset (for hash set) template. An hset is much like a set—it takes a single (for now) template argument, that is, the type to be contained. Compile main.cc and run it. Observe that the order of the output is not the same as the order of the input. (At least, for the strings. It’s hard to tell for the random numbers.)                 

Understanding the code                

Look at hset.h, hset_iter.h, and hasher.h, and understand the following:                 

Exercises                

  1. An hset is a vector of lists, and the vector is stuck at size 8. Change that size to be a mandatory second template parameter.
  2. Add empty() to hset. Make it more efficient than just size()==0.
  3. Add a hset<double> to main, and insert a series of doubles between 1.0 and 2.0. Observe that it works poorly. Why? How does it even compile?
  4. Improve Hasher to hash doubles.
  5. The design of hset_iter is horrible.
    1. What is the O( ) of hset_iter::operator* ?
    2. Improve it.

Modified: 2017-04-21T14:28                 

User: Guest                 

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building