This starter code will be basically the same for P2.
make testexecutes all build commands to run firsttest_bytes.cand thentest_assoc.cmake runruns the interactivemain.cmake debugdebugs the interactivemain.c--> will run it via gdb so you get line numbers from segfaults.make cleanwill delete all temporary build files.
CMake doesn't come with the ability to create actions; traditionally you give it its own build directory to do its thing. This will port over to Windows and other platforms better than the older Makefile approach.
cd build && cmake ..
make test_assoc && ./test_assoc
make test_bytes && ./test_bytes
make main && ./mainRight now the hash_new method creates a HashTable_t with 8 buckets (pointers to HashEntry_t). This is enough buckets (1 is enough) to pass any of the tests.
Having functional hash_put and hash_get methods are worth 40 points; they are the most critical.
If you're struggling with the HashEntry_t** buckets; remember it is an array of pointers -- these are pointers to the head of a linked-list.
You can import your lab6 code and change these buckets to be AssocList_t* buckets; treating the collision handling part of your code as delegated to your prior assignment. This will involve slightly modifying the Makefile or CMakeLists.txt.
Since hash_remove is the most difficult method, it is worth additional points.
There are two private methods in hashtable.c; static on a function in C is like private in Java -- it means that the function is only visible in the current file.
boolean hash_should_resize(HashTable_t *self)should be complete already.- (12)
void hash_resize(HashTable_t* self)needs work. I suggest usingcallocto create another new array, since it fills it with zeros (NULLs). - (8) Also, you'll need to fiddle with
test_associn order to trigger yourHashTable_tto resize!
Extra points will be available for:
- (5) Resizing to only numbers of buckets that are reasonably prime (e.g.,
(2 ** x) - 1) ... I don't expect you to come up with this algorithm by yourself - cite your googling. - (?) Not relying on
hash_putto do this logic; it is much more efficient if you're storinghashvalues in your entries to duplicate some logic here.
This is much like the previous section, but more points will be available for re-using code as much as possible.
The last 20 points of this assignment are for memory correctness and style -- you may earn all of the previous listed points with memory leaks; however, this is intended to be a long running program, so think of ways to manage memory safely.
Similarly, some of these points will be awarded for clearer, simpler solutions.
Reading the section in "Dive into Systems" on valgrind will provide you with tools to help track the leaking memory.