You will write a simple C program (location: task-5/solution-5.c) which sorts given binary objects. This program will be compiled and invoked in the following way:
$ gcc -Werror -Wall -o fastsort solution-5.c # Compilation
$ ./fastsort inputfile outputfile # Execution
The built executable (i.e., fastsort) takes two command line arguments: an input file (named inputfile) containing the binary objects to be sorted and an output file (named outputfile) to store the sorted results.
Input: The inputfile contains binary data1 that needs to be sorted. The binary data consists of a series of 100-byte binary objects (aka blobs). Each object is a key-value pair, where the first four bytes represent an unsigned integer key and the remaining 96 bytes is the corresponding value. Each value (i.e., the remaining 96 bytes) actually represents a record consisting of 24 unsigned integers. Therefore, each binary object looks something as follows (where each letter represents 4 bytes):
kRRRRRRRRRRRRRRRRRRRRRRRR
How to generate such input files?: Input files are generated by a given program called task-5/generate.c, which can be complied as follows:
$ gcc -Wall -Werror -o generate generate.c
$ ./generate -h
usage: ./generate [-s random_seed] [-n number_of_objects] [-o generated_filename]
The generate program takes three optional arguments:
-s: This option specifies a random seed that this program will use as the seed for a new sequence of (pseudo-)random integers. This allows you to generate input files with different data while testing your fastsort.
-n: This option specifies how many binary objects to write to the generated filename file. Each object is of 100 bytes.
-o: This options specifies the filename where the number of objects binary objects will be stored.
A sample execution of generate is shown below. Note that the generated file (test.in) can be used as the input file to your fastsort.
$ ./generate -s 0 -n 100 -o test.in
Output: Your sorting program (named fastsort) must take in one of these generated files and sorts it based on the 4-byte key (the remainder of the object (i.e., the record) should be kept with the same key). The output is written to the specified output file. While writing the output, you should only write the sorted binary objects, no additional characters (e.g., '\n).
NOTE: All these programs related to this task need the header file sort.h during their compilation. This header is located at task-5/sort.h.
Assumptions:
Error checking: Your program should do appropriate error checking.