list_words
First, read list.h
to understand the API. Focus on the examples given in the big docstring in the beginning of the file. For more information about the PintOS list data structure, please also see the PintOS list documentation.
Next, thoroughly read through the data structures and methods in word_count.h
. In particular, pay attention to the word_count_t
and word_count_list_t
structs. You may find it beneficial to see the compiler flags used in the Makefile
and how that affects the struct definitions. You may also want to (re)read the Study Guide: C, trying to answer all the questions.
Finally, complete word_count_list.c
to properly implement the word count API given in word_count.h
. You must use the PintOS list API. After you finish making this change, list_words
should work properly (i.e. exhibit the same behavior as the frequency mode of words
, you don’t need to specify the '-f'
command line argument, though).
You are permitted (and explicitly encouraged) to re-use and adapt the relevant parts of the code you wrote in Assignment 0. This will greatly simplify the task at hand.
The wordcount_sort
function sorts the word_count
list according to the comparator passed as an argument. Although list_words
uses the less_count
function from word_helpers.h
as the less
argument, the wordcount_sort
function should be generic enough to work with any valid comparator passed in as the less
argument. For example, passing the less_word
function from word_helpers.h
as the less
parameter should work. Check out some basics on function pointers if you’re having trouble understanding and writing the syntax.
You should check the validity of all arguments provided to the functions you implement. Please refer to the section Error Handling related to the words
assignment for details.
To verify that your code does the right thing you may run make check_list
. This will execute your list_words
program by generating word counts for the files in the gutenberg/
directory.
These files were generated from select stories from Project Gutenberg, making sure to choose short stories so that the word count program does not take too long to run. The results
directory also contains files (with the file extension .frequencies
) that have been generated by a correctly working version of the code. make check_list
compares the output generated by your version with the content of those files.
Next up: pthread.