This assignment is designed to let you explore further uses of binary trees and linked lists.
Hash trees are a data structure used in distributed systems. They have the property that given the root of the hash tree, you can later verify that a given value is in the tree.
For this assignment, we’re going to be creating hash trees. We’re then going to create a linked list out of the root of the trees, where each node in the list has both a pointer to a tree root and to the previous node in the list.
Hash trees have two types of nodes: leaves and branches. Leaves contain the data. Branches contain the hash of the children concatenated together. Each leaf has one branch node that contains the hash of the data. For example, in the image below, Hash 0-0 contains the hash of just L1 and Hash 0-1 contains the hash of L2. Then, Hash 0 contains the hash of (Hash 0-0 and Hash 0-1 concatenated together).
Each element in the hashtreelist has a height. Height is a non negative number, where the earliest node in the list has height 0, the second earliest node in the list has height 1, etc.
In a file named hashtree.c, implement all the functions declared in hashtree.h. Create your own testing file testhashtree.c that tests your code.
You will need to use the SHA 256 hash function provided here: https://github.com/ryancdotorg/lonesha256-ansi/blob/master/lonesha256.h. This was chosen since it is ANSI C compliant and does not rely on external dependencies. You do not have to comment this code or understand it.
We will cover hash tree proofs and work towards writing some of that code during lecture. The rest of the program doesn’t depend on this, so please don’t hold off on writing the rest of this beforehand.
If you’re noticing that your code randomly seg faults or causes stack smashing issues or runs differently on your laptop than a server, that is probably a memory management issue.
Valgrind not only tests if objects allocated on the heap are adequately freed, it also tests improper memory accesses. Your code will need to have no improper memory access issues.
Some tips: Incrementally test your code so that you can more easily isolate the issue. Explicitly null terminate your strings. Using calloc instead of malloc will fix some issues with strings not null terminated properly. malloc of a struct pointer instead of a struct will act differently on different versions of gcc and other c compilers.
In a file named hashtreelist.c, implement the functions declared in hashtreelist.h. Create your own testing file testhashtreelist.c that tests your code.
You will need to fully implement and test hashtree.c before moving on to this.
The final step is to read/write the input for the other programs from file, in a program entitled readtree.c. You will be given an arbitrary number of files. You can test your code with files.zip. hashtree.in will contain a list of files to read in. The first line will have the name of a file corresponding to the first node in the hashtreelist (plus a new line character). The last line will have the name of a file corresponding to the latest node in the hashtreelist.
Each file that contains tree elements will be non empty and will contain all of the leaves in the tree. Each leaf will be separated by a new line character.
The testing files for this portion of the assignment will be provided to you. You will not have to write additional testing code for this portion of the assignment.
Zip your files and turn the zip file in via the hw-09 folder in the course dropbox.
As per usual, all code needs to be able to be compiled on moons.cs.unm.edu with the /usr/bin/gcc -ansi -Wall -pedantic command.