HOMEWORK 2.1 READAHEAD SCENARIOS

Const Annotations Note that this bit is optional. For example checking for the presence of a certain key. Further, note that each call to strtok will return a pointer into the string it is tokenizing, meaning that once you have a word that you want to store as a key in the hash table, you will want to make a copy of the word e. If and when we generalise hash tables to support arbitrary values, we either need to force the user to make copies lots of extra work and easy to forget , or inform the hash table how to make copies of values values can be arbitrarily complicated, for example another hash table! Otherwise, it is good to write the code yourself.

What does that require us to do or know in our test programs? This requires an array that reserves space for storage of at least 1. Whatever value we pick, we restrict the usage of our map in programs. As part of your way of getting here, you have written some tests. By now you should have demonstrated a few achievements, or at least have accumulated enough insights to be able to demonstrate. In this case, a central function is going to be the one that adds words to the hash table. Things that Valgrind will help us spot are:

Since the latter will require an extra function that must be maintained, that seems like too much work to me. So keep up the good work and have a great school year.

homework 2.1 readahead scenarios

This preserves maximal freedom for us to change the implementation as we continue to improve our code, and also helps us protect the invariants of the data structure.

Next step is to add support for removing an entry for a given key.

For a lot of things in programming, there is no inherent right or wrong — this may vary from case to case scenxrios also be strongly influenced by what you perceive as natural or intuitive. Pick a solution that works and think about how this relates to or even demonstrates key concepts in the course like modularity, encapsulation, coupling and cohesion.

  DISSERTATION RACINE ANDROMAQUE

What does that require us to do or know in our test programs? Complete correlations will need to show where and how the mathematical content AND the eight mathematical homswork are in evidence within lessons and throughout chapters and texts.

That entails the following:.

Homework 2.1 readahead scenarios

If you compile and run the homewkrk below, this is the output you will get: For example, if we want P to produce an array of booleans so we can see what key, value pair did not satisfy Pwe could pass this array to P via x. You should document how your functions interact with errno — what functions set it, to what, and under what circumstances.

homework 2.1 readahead scenarios

The linked list overview implements a defensive approach that lets all indexes be valid by e. When we allocate memory in C using mallocC will return a pointer to memory whose contents are unknown. When you run time to test if an optimisation paid of, you should ideally run the program many times and pick e.

Similarly, we are also going to add support for checking the existence of at least one key, value entry in a hash table for which P holds:. A comment is a good way to explain why it was chosen, so that a future coder will know to change it if the number of buckets change at least if they stumble across the code and read the comment.

Future tests will test the correctness of the implementation of the data representation, but for now creation and destruction can be tested together. To get going, let us start with something easy: Adapting the Number of Buckets 7. For inserting values, there are going to be two, possibly three important basic cases to test for:.

  ENGINEERING PROBLEM SOLVING WITH C++ DELORES M ETTER

Do not forget to include string. You are encouraged to use MongoProc to continuously test your progress until you are ready to grade the homework.

Homework readahead scenarios,

Note that Assignment 2 will be built on-top of the data structures you develop now, and be a lot more free. Given that we are printing keys in lexicographic order, this will require some thought. Your task is to change usages of integer types in our programs where the int refers to a size.

Run your tests through Valgrind. Also note down how the numbers were obtained. Construct viable arguments and critique the reasoning of others. How do we meet the non-functional requirements on prepend, append, and size in constant time? Looking for Keys and Values In our series of common operations on hash tables, we have arrived at asking whether a hash table contains a specific key or value.

For example, the following code checks if P holds for all key and value pairs. For now, we will dodge and consider only lists that store integers. Also think about what input to use that exercises the functions you are interested in. If we put it in a file of its own, that is good for keeping files smaller and easier to navigate, etc. Word Wise and Content Rich, Grades 7—

Author: admin