CS problem.
a1-code/save_deltas.o
a1-code/test_print_graph_data.sh
#!/bin/bash T=0 # global test number ((T++)) tnames[T]="demo-test" # read -r -d '' output[$T] <<"ENDOUT" DEMO DATA 1 =========== length: 22 min: 0 max: 20 range: 20 max_height: 10 units_per_height: 2.00 +----+----+----+----+- 20 | X 18 | XX 16 | XXX 14 | XXXX 12 | XXXXX 10 | X XXXXXXX 8 | XXX XXXXXXXX 6 | XXXXX XXXXXXXXX 4 | XXXXXXX XXXXXXXXXX 2 | XXXXXXXXXXXXXXXXXXXX 0 |XXXXXXXXXXXXXXXXXXXXXX +----+----+----+----+- 0 5 10 15 20 DEMO DATA 2 =========== length: 22 min: 0 max: 20 range: 20 max_height: 20 units_per_height: 1.00 +----+----+----+----+- 20 | X 19 | X 18 | XX 17 | XX 16 | XXX 15 | XXX 14 | XXXX 13 | XXXX 12 | XXXXX 11 | XXXXX 10 | X XXXXXXX 9 | XX XXXXXXX 8 | XXX XXXXXXXX 7 | XXXX XXXXXXXX 6 | XXXXX XXXXXXXXX 5 | XXXXXX XXXXXXXXX 4 | XXXXXXX XXXXXXXXXX 3 | XXXXXXXX XXXXXXXXXX 2 | XXXXXXXXXXXXXXXXXXXX 1 | XXXXXXXXXXXXXXXXXXXXX 0 |XXXXXXXXXXXXXXXXXXXXXX +----+----+----+----+- 0 5 10 15 20 DEMO DATA 3 =========== length: 50 min: 13 max: 996 range: 983 max_height: 10 units_per_height: 98.30 +----+----+----+----+----+----+----+----+----+---- 996 | X 897 | X X X X 799 | X X X X X X X X X 701 | XX X X X XXX X XX XXX X X XX 602 | XX X X XX XXX X X XX XXXX XX X XX 504 | XX XXX XX XXX XX X XXX XXXX XX XX X XX 406 | XX X XXX XXXX XXX XX X XXX XXX XXXXXXXXXX X XX 307 | XXX X XXX XXXXXXXXXXX X XXXX XXXXXXXXXXXXXXX X XX 209 | XXX XXXXXXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXXXXXX XX 111 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 13 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +----+----+----+----+----+----+----+----+----+---- 0 5 10 15 20 25 30 35 40 45 DEMO DATA 4 =========== length: 50 min: 13 max: 996 range: 983 max_height: 18 units_per_height: 54.61 +----+----+----+----+----+----+----+----+----+---- 996 | X 941 | X X 886 | X X X X 832 | X X X X X X 777 | X X X X XXX X X XXX XX 722 | XX X X X XXX X X XXX XX 668 | XX X X X XXX X XX XXXX X X XX 613 | XX X X XX XXX X XX XXXX XX X XX 559 | XX XXX XX XXX XX X XX XXXX X XX X XX 504 | XX XXX XX XXX XX X XXX XXXX XX XX X XX 449 | XX X XXX XXXX XXX XX X X XXX XXXX XX XX X XX 395 | XXX X XXX XXXX XXX XX X XXX XXX XXXXXXXXXX X XX 340 | XXX X XXX XXXXXXXXXXX X XXX XXXXXXXXXXXXXXX X XX 286 | XXX X XXX XXXXXXXXXXX X XXXX XXXXXXXXXXXXXXX X XX 231 | XXX X XXXXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXXXXXX XX 176 | XXX XXXXXXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXXXXXXXXX 122 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 67 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 13 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +----+----+----+----+----+----+----+----+----+---- 0 5 10 15 20 25 30 35 40 45 ENDOUT
__MACOSX/a1-code/._test_print_graph_data.sh
a1-code/.DS_Store
__MACOSX/a1-code/._.DS_Store
a1-code/print_graph_demo.c
#include <stdio.h> void print_graph(int *data, int len, int max_height); int main(int argc, char *argv[]){ printf("DEMO DATA 1\n"); printf("===========\n"); int data1[22] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 10,}; int len1 = 22; print_graph(data1, len1, 10); printf("\n"); printf("DEMO DATA 2\n"); printf("===========\n"); print_graph(data1, len1, 20); printf("\n"); printf("DEMO DATA 3\n"); printf("===========\n"); int data2[50] = { 13 , 397, 813, 745, 154, 473, 212, 939, 593, 849, 247, 453, 662, 806, 478, 390, 996, 792, 929, 372, 603, 577, 146, 801, 276, 328, 422, 481, 438, 126, 701, 988, 555, 376, 674, 781, 795, 780, 415, 521, 581, 412, 701, 617, 367, 258, 704, 192, 869, 791, }; int len2 = 50; print_graph(data2, len2, 10); printf("\n"); printf("DEMO DATA 4\n"); printf("===========\n"); print_graph(data2, len2, 18); printf("\n"); return 0; }
__MACOSX/a1-code/._print_graph_demo.c
a1-code/deltas.txt
10 2 5 -2 -5 -5 -6 4
a1-code/test_hash_main.sh
#!/bin/bash # tests for print_graph_demo, run as one of # > ./test_tree_main.sh # run everything # > ./test_tree_main.sh 2 # run only tests 2 # # 15 points for tests # 5 points for valgrind tests function major_sep(){ printf '%s\n' '=====================================' } function minor_sep(){ printf '%s\n' '-------------------------------------' } major_sep printf "PROBLEM 3 hash_main.c\n" generate=1 run_norm=1 # run normal tests run_valg=1 # run valgrind tests valg_denom=3 # divide valgrind score by this for points # Determine column width of the terminal if [[ -z "$COLUMNS" ]]; then printf "Setting COLUMNS based on stty\n" COLUMNS=$(stty size | awk '{print $2}') fi if (($COLUMNS == 0)); then COLUMNS=126 fi printf "COLUMNS is $COLUMNS\n" DIFF="diff -bBy -W $COLUMNS" # -b ignore whitespace, -B ignore blank lines, -y do side-by-side comparison, -W to increase width of columns VALGRIND="valgrind --leak-check=full --show-leak-kinds=all" INPUT=test-data/input.tmp # name for expected output file EXPECT=test-data/expect.tmp # name for expected output file ACTUAL=test-data/actual.tmp # name for actual output file DIFFOUT=test-data/diff.tmp # name for diff output file VALGOUT=test-data/valgrind.tmp # name for valgrind output file printf "Loading tests... " source test_hash_main_data.sh printf "%d tests loaded\n" "$T" NTESTS=$T VTESTS=$T NPASS=0 NVALG=0 all_tests=$(seq $NTESTS) case "$1" in norm) run_valg=0 shift ;; valg) run_norm=0 shift ;; esac # Check whether a single test is being run single_test=$1 if ((single_test > 0 && single_test <= NTESTS)); then printf "Running single TEST %d\n" "$single_test" all_tests=$single_test NTESTS=1 VTESTS=1 else printf "Running %d tests\n" "$NTESTS" fi # printf "tests: %s\n" "$all_tests" printf "\n" # Run normal tests: capture output and check against expected if [ "$run_norm" = "1" ]; then minor_sep printf "hash_main NORMAL TESTS\n" for i in $all_tests; do printf "TEST %2d %-18s : " "$i" "${tnames[i]}" FAIL="0" # Run the test # run program with given input { printf "%s\n" "${input[i]}" | ./hash_main -echo ; } >& $ACTUAL # generate expected output printf "%s\n" "${output[i]}" > $EXPECT # Check for output differences, print side-by-side diff if problems if ! $DIFF $EXPECT $ACTUAL > $DIFFOUT then printf "FAIL: Output Incorrect\n" minor_sep printf "INPUT:\n%s\n" "${input[i]}" # Mac OSX has a different version sed so use awk to add on the ACTUAL/EXPECT $DIFF <(awk 'BEGIN{print "***EXPECT OUTPUT***"} {print}' $EXPECT) <(awk 'BEGIN{print "***ACTUAL OUTPUT***"} {print}' $ACTUAL) > $DIFFOUT # regen the diff with the headers cat $DIFFOUT if [ "$generate" == "1" ]; then printf "%s\n" "---FULL ACTUAL---" cat $ACTUAL echo fi minor_sep FAIL="1" fi if [ -n "${tfiles[i]}" ]; then # if there is an output file to check TEXPECT=test-data/texpect.tmp # name for expected output file TACTUAL="${tfiles[i]}" # name for actual output file TDIFFOUT=test-data/tdiff.tmp # name for diff output file # generate expected output printf "%s\n" "${tfiles_expect[i]}" > $TEXPECT # Check for output differences, print side-by-side diff if problems if ! $DIFF $TEXPECT $TACTUAL > $TDIFFOUT then printf "FAIL: File %s incorrect\n" "$TACTUAL" minor_sep printf "INPUT:\n%s\n" "${input[i]}" printf "OUTPUT: EXPECT vs ACTUAL\n" cat $TDIFFOUT if [ "$generate" == "1" ]; then printf "%s\n" "---FULL ACTUAL---" cat $TACTUAL fi minor_sep FAIL="1" fi fi if (( FAIL == 0 )); then printf "OK\n" ((NPASS++)) fi done printf "Finished:\n" printf "%2d / %2d Normal correct\n" "$NPASS" "$NTESTS" printf "\n" fi # ================================================================================ # Run valgrind tests: check only for problems identified by valgrind if [ "$run_valg" = "1" ]; then minor_sep printf "hash_main.c VALGRIND TESTS\n" for i in $all_tests; do printf "TEST %2d %-18s : " "$i" "${tnames[i]}" # run code through valgrind { printf "%s\n" "${input[i]}" | $VALGRIND ./hash_main -echo ; } >& $VALGOUT # Check various outputs from valgrind if ! grep -q 'ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)' $VALGOUT || ! grep -q 'in use at exit: 0 bytes in 0 blocks' $VALGOUT || grep -q 'definitely lost: 0 bytes in 0 blocks' $VALGOUT; then printf "FAIL: Valgrind detected problems\n" minor_sep cat $VALGOUT minor_sep else printf "Valgrind OK\n" ((NVALG++)) fi done printf "Finished:\n" printf "%2d / %2d Valgrind correct\n" "$NVALG" "$VTESTS" printf "\n" fi NVALG=$((NVALG / valg_denom)) VTESTS=$((VTESTS / valg_denom)) major_sep printf "OVERALL:\n" printf "%2d / %2d Normal correct\n" "$NPASS" "$NTESTS" printf "%2d / %2d Valgrind points\n" "$NVALG" "$VTESTS" printf "RESULTS: %d / %d points for normal/valgrind tests\n" "$((NPASS+NVALG))" "$((NTESTS+VTESTS))"
__MACOSX/a1-code/._test_hash_main.sh
a1-code/test-data/README
This directory is for files generated during testing. It must be present for tests to work but the contents may be safely ignored. Files in this directory may be safely removed. The provided Makefile target make clean-tests will do this.
__MACOSX/a1-code/test-data/._README
__MACOSX/a1-code/._test-data
a1-code/test_graph_file.sh
#!/bin/bash # # tests for graph_file executable, run as one of # > ./test_graph_file.sh # run everything # > ./test_graph_file.sh 2 # run only tests 2 # > ./test_graph_file.sh norm # run only normal tests # > ./test_graph_file.sh valg # run only valgrind tests # > ./test_graph_file.sh norm 2 # run only normal test 2 # > ./test_graph_file.sh valg 2 # run only vaglgrind test 2 # # 1 point(s) per 10 normal tests # 0-3 point(s) penalty for memory problems under Valgrind function major_sep(){ printf '%s\n' '=====================================' } function minor_sep(){ printf '%s\n' '-------------------------------------' } # major_sep # printf "PROBLEM 2B graph_file.c\n" generate=1 run_norm=1 # run normal tests run_valg=1 # run valgrind tests valg_penalty_max=3 # maximum point deduction for valgrind problems VALGRIND="valgrind --leak-check=full --show-leak-kinds=all" DIFF="diff -bBy" # -b ignore whitespace, -B ignore blank lines, -y do side-by-side comparison INPUT=test-data/input.tmp # name for expected output file EXPECT=test-data/expect.tmp # name for expected output file ACTUAL=test-data/actual.tmp # name for actual output file DIFFOUT=test-data/testdiff.tmp # name for diff output file VALGOUT=test-data/valgrind.tmp # name for valgrind output file printf "Loading tests... " source test_graph_file_data.sh printf "%d tests loaded\n" "$T" NTESTS=$T VTESTS=$T NPASS=0 NVALG=0 all_tests=$(seq $NTESTS) # Turn off normal/valgrind test sections case "$1" in norm) run_valg=0 shift ;; valg) run_norm=0 shift ;; esac # Check whether a single test is being run single_test=$1 if ((single_test > 0 && single_test <= NTESTS)); then printf "Running single TEST %d\n" "$single_test" all_tests=$single_test NTESTS=1 VTESTS=1 else printf "Running %d tests\n" "$NTESTS" fi # printf "tests: %s\n" "$all_tests" printf "\n" # Run normal tests: capture output and check against expected if [ "$run_norm" = "1" ]; then minor_sep printf "graph_file.c NORMAL TESTS\n" for i in $all_tests; do printf "TEST %2d %-18s : " "$i" "${tnames[i]}" # Run the test # generate the input file printf "%s\n" "${input[i]}" | ./save_deltas "${format[i]}" $INPUT > /dev/null # run program on input file { ./graph_file "${format[i]}" $INPUT "${height[i]}" ; } >& $ACTUAL # generate expected output printf "%s\n" "${output[i]}" > $EXPECT # Check for failure, print side-by-side diff if problems if ! $DIFF $EXPECT $ACTUAL > $DIFFOUT then printf "FAIL: Output Incorrect\n" minor_sep printf "INPUT:\n%s\n" "${input[i]}" printf "OUTPUT: EXPECT vs ACTUAL\n" cat $DIFFOUT if [ "$generate" == "1" ]; then printf "FULL ACTUAL\n" cat $ACTUAL fi minor_sep else printf "OK\n" ((NPASS++)) fi done printf "Finished\n" printf "%2d / %2d Normal correct\n" "$NPASS" "$NTESTS" printf "\n" fi # ================================================================================ # Run valgrind tests: check only for problems identified by valgrind if [ "$run_valg" = "1" ]; then minor_sep printf "graph_file.c VALGRIND TESTS\n" for i in $all_tests; do printf "TEST %2d %-18s : " "$i" "${tnames[i]}" # Run the test # generate the input file printf "%s\n" "${input[i]}" | ./save_deltas "${format[i]}" $INPUT > /dev/null # run code through valgrind { $VALGRIND ./graph_file "${format[i]}" $INPUT "${height[i]}" ; } >& $VALGOUT # Check various outputs from valgrind if ! grep -q 'ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)' $VALGOUT || ! grep -q 'in use at exit: 0 bytes in 0 blocks' $VALGOUT || grep -q 'definitely lost: 0 bytes in 0 blocks' $VALGOUT; then printf "FAIL: Valgrind detected problems\n" minor_sep cat $VALGOUT minor_sep else printf "Valgrind OK\n" ((NVALG++)) fi done printf "Finished\n" printf "%2d / %2d Valgrind correct\n" "$NVALG" "$VTESTS" printf "\n" fi major_sep printf "OVERALL:\n" printf "%2d / %2d Normal correct\n" "$NPASS" "$NTESTS" printf "%2d / %2d Valgrind correct\n" "$NVALG" "$VTESTS" valg_penalty=$((VTESTS-NVALG)) if ((valg_penalty > valg_penalty_max)); then valg_penalty=$valg_penalty_max fi printf "Valgrind penalty: -%d\n" "$valg_penalty" SCORE=$((NPASS-valg_penalty)) if ((SCORE < 0)); then SCORE=0; fi printf "RESULTS: %d / %d points for normal/valgrind tests\n" "$SCORE" "$NTESTS"
__MACOSX/a1-code/._test_graph_file.sh
a1-code/read_deltas.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "deltas.h" #include <sys/types.h> #include <sys/stat.h> int *read_text_deltas(char *fname, int *len){ int num = 0; int count = 0; FILE *fp; fp = fopen(fname,"r"); if(fp == NULL){ *len = -1; return NULL; } while(!feof(fp)){ fscanf(fp,"%d", &num); count++; } rewind(fp); int *arr = (int*) malloc(count * sizeof(int)); int i=1; fscanf(fp,"%d", &num); arr[i - 1] = num; while(!feof(fp)){ fscanf(fp,"%d", &num); arr[i] = num; //printf("%d %d\n", i,arr[i-1] + num); arr[i] = arr[i-1] + num; i++; } *len = count - 1; fclose(fp); return arr; } int *read_int_deltas(char *fname, int *len){ struct stat buf; int num = 0; int result = stat(fname, &buf); if(result == -1 || buf.st_size < sizeof(int)){ return NULL; } int size = buf.st_size / 4; int *arr = (int*) malloc(size * sizeof(int)); FILE *fp; fp = fopen(fname,"r"); if(fp == NULL){ *len = -1; return NULL; } int i = 1; fread(&num,sizeof(int),1,fp); arr[i-1] = num; for(i = 1; i < size; i++){ fread(&num,sizeof(int),1,fp); //printf("%d %d\n", i,arr[i-1] + num); arr[i] = arr[i-1] + num; } *len = size; fclose(fp); return arr; }
__MACOSX/a1-code/._read_deltas.c
a1-code/binary.int
a1-code/Makefile
CFLAGS = -Wall -g -lm CC = gcc $(CFLAGS) SHELL = /bin/bash CWD = $(shell pwd | sed 's/.*\///g') PROGRAMS = \ save_deltas \ deltas_main \ print_graph_demo \ graph_file \ hash_main \ all : $(PROGRAMS) AN=a1 zip : rm -f $(AN)-code.zip cd .. && zip "$(CWD)/$(AN)-code.zip" -r "$(CWD)" @echo Zip created in $(AN)-code.zip @if (( $$(stat -c '%s' $(AN)-code.zip) > 10*(2**20) )); then echo "WARNING: $(AN)-code.zip seems REALLY big, check there are no abnormally large test files"; du -h $(AN)-code.zip; fi clean : rm -f $(PROGRAMS) *.o # int delta problem deltas_main.o : deltas_main.c deltas.h $(CC) -c $< deltas_main : deltas_main.o read_deltas.o $(CC) -o $@ $^ read_deltas.o : read_deltas.c deltas.h $(CC) -c $< save_deltas.o : save_deltas.c deltas.h $(CC) -c $< save_deltas : save_deltas.o $(CC) -o $@ $^ # print_graph print_graph.o : print_graph.c $(CC) -c $< print_graph_demo.o : print_graph_demo.c $(CC) -c $< print_graph_demo : print_graph_demo.o print_graph.o $(CC) -o $@ $^ graph_file.o : graph_file.c $(CC) -c $< graph_file : graph_file.o print_graph.o read_deltas.o $(CC) -o $@ $^ # hash problem hash_main : hash_main.o hash_funcs.o $(CC) -o $@ $^ hash_main.o : hash_main.c hashmap.h $(CC) -c $< hash_funcs.o : hash_funcs.c hashmap.h $(CC) -c $< # Testing Targets VALGRIND = valgrind --leak-check=full --show-leak-kinds=all test : test-p1 test-p2 test-p3 test-p1 : test-p1-norm test-p1-valg test-p1-norm : test_read_deltas @printf "===P1 Normal tests for read_deltas() via test_read_deltas===\n" ./test_read_deltas @printf "\n" test-p1-valg : test_read_deltas @printf "\n" @printf "===P1 Valgrind tests for read_deltas() via test_read_deltas===\n" @echo $(VALGRIND) ./test_read_deltas @$(VALGRIND) ./test_read_deltas >& test-data/p1-valgrind.tmp @chmod u+rx ./test_check_valgrind.sh @./test_check_valgrind.sh 5 'PROBLEM 1 Valgrind Memory Checks' test-data/p1-valgrind.tmp @printf "\n" test_read_deltas.o : test_read_deltas.c deltas.h $(CC) -c $< test_read_deltas : test_read_deltas.o read_deltas.o $(CC) -o $@ $^ test-p2 : test-p2a test-p2b test-p2a : print_graph_demo graph_file save_deltas @printf "===TESTS for P2A===\n" @printf "Testing print_graph() via print_graph_demo\n" @chmod u+rx ./test_print_graph.sh ./test_print_graph.sh test-p2b : print_graph_demo graph_file save_deltas @printf "===TESTS for P2B===\n" @printf "Testing graph_file\n" @chmod u+rx ./test_graph_file.sh ./test_graph_file.sh test-p3 : hash_main @printf "===TESTS for P3===\n" @chmod u+rx ./test_hash_main.sh ./test_hash_main.sh clean-tests : rm -f test_read_deltas rm -f test-data/*.tmp test-data/*.tree
__MACOSX/a1-code/._Makefile
a1-code/test_print_graph.sh
#!/bin/bash # # tests for print_graph_demo, run as one of # > ./test_print_graph.sh # run everything # > ./test_print_graph.sh 2 # run only tests 2 # > ./test_print_graph.sh norm # run only normal tests # > ./test_print_graph.sh valg # run only valgrind tests # > ./test_print_graph.sh norm 2 # run only normal test 2 # > ./test_print_graph.sh valg 2 # run only vaglgrind test 2 # # 4 point(s) for the single normal test # 1 point(s) for avoiding memory problems under Valgrind function major_sep(){ printf '%s\n' '=====================================' } function minor_sep(){ printf '%s\n' '-------------------------------------' } # major_sep # printf "PROBLEM 2A print_graph_demo.c\n" generate=1 run_norm=1 # run normal tests run_valg=1 # run valgrind tests norm_mult=4 # weighting for normal tests valg_mult=1 # weighting for valgrind tests VALGRIND="valgrind --leak-check=full --show-leak-kinds=all" DIFF="diff -bBy" # -b ignore whitespace, -B ignore blank lines, -y do side-by-side comparison INPUT=test-data/input.tmp # name for expected output file EXPECT=test-data/expect.tmp # name for expected output file ACTUAL=test-data/actual.tmp # name for actual output file DIFFOUT=test-data/diff.tmp # name for diff output file VALGOUT=test-data/valgrind.tmp # name for valgrind output file printf "Loading tests... " source test_print_graph_data.sh printf "%d tests loaded\n" "$T" NTESTS=$T VTESTS=$T NPASS=0 NVALG=0 all_tests=$(seq $NTESTS) case "$1" in norm) run_valg=0 shift ;; valg) run_norm=0 shift ;; esac # Check whether a single test is being run single_test=$1 if ((single_test > 0 && single_test <= NTESTS)); then printf "Running single TEST %d\n" "$single_test" all_tests=$single_test NTESTS=1 VTESTS=1 else printf "Running %d tests\n" "$NTESTS" fi printf "tests: %s\n" "$all_tests" printf "\n" # Run normal tests: capture output and check against expected if [ "$run_norm" = "1" ]; then minor_sep printf "print_graph_demo NORMAL TESTS\n" for i in $all_tests; do printf "TEST %2d %-18s : " "$i" "${tnames[i]}" # run program on input file { ./print_graph_demo ; } >& $ACTUAL # generate expected output printf "%s\n" "${output[i]}" > $EXPECT # Check for failure, print side-by-side diff if problems if ! $DIFF $EXPECT $ACTUAL > $DIFFOUT then printf "FAIL: Output Incorrect\n" minor_sep printf "INPUT:\n%s\n" "${input[i]}" printf "OUTPUT: EXPECT vs ACTUAL\n" cat $DIFFOUT if [ "$generate" == "1" ]; then printf "FULL ACTUAL\n" cat $ACTUAL fi minor_sep else printf "OK\n" ((NPASS++)) fi done printf "Finished\n" major_sep printf "%2d / %2d Normal correct\n" "$((NPASS*norm_mult))" "$((NTESTS*norm_mult))" printf "\n" fi # ================================================================================ # Run valgrind tests: check only for problems identified by valgrind if [ "$run_valg" = "1" ]; then minor_sep printf "print_graph_demo VALGRIND TESTS\n" for i in $all_tests; do printf "TEST %2d %-18s : " "$i" "${tnames[i]}" # Run the test # generate the input file printf "%s\n" "${input[i]}" | ./save_deltas "${format[i]}" $INPUT > /dev/null # run code through valgrind { $VALGRIND ./print_graph_demo ; } >& $VALGOUT # Check various outputs from valgrind if ! grep -q 'ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)' $VALGOUT || ! grep -q 'in use at exit: 0 bytes in 0 blocks' $VALGOUT || grep -q 'definitely lost: 0 bytes in 0 blocks' $VALGOUT; then printf "FAIL: Valgrind detected problems\n" minor_sep cat $VALGOUT minor_sep else printf "Valgrind OK\n" ((NVALG++)) fi done printf "Finished\n" major_sep printf "%2d / %2d Valgrind correct\n" "$((NVALG*valg_mult))" "$((VTESTS*valg_mult))" printf "\n" fi NPASS=$((NPASS*norm_mult)) NTESTS=$((NTESTS*norm_mult)) NVALG=$((NVALG*valg_mult)) VTESTS=$((VTESTS*valg_mult)) major_sep printf "OVERALL:\n" printf "%2d / %2d Normal correct\n" "$NPASS" "$NTESTS" printf "%2d / %2d Valgrind correct\n" "$NVALG" "$VTESTS" printf "RESULTS: %d / %d points for normal/valgrind tests\n" "$((NPASS+NVALG))" "$((NTESTS+VTESTS))"
__MACOSX/a1-code/._test_print_graph.sh
a1-code/hashmap.h
// hashmap.h: header for hashmap problem #ifndef HASHMAP_H #define HASHMAP_H 1 // Type for linked list nodes in hash map typedef struct hashnode { char key[128]; // string key for items in the map char val[128]; // string value for items in the map struct hashnode *next; // pointer to next node, NULL if last node } hashnode_t; // Type of hash table typedef struct { int item_count; // how many key/val pairs in the table int table_size; // how big is the table array hashnode_t **table; // array of pointers to nodes which contain key/val pairs } hashmap_t; #define HASHMAP_DEFAULT_TABLE_SIZE 5 // default size of table for main application // functions defined in hash_funcs.c long hashcode(char key[]); int next_prime(int num); void hashmap_init(hashmap_t *hm, int table_size); int hashmap_put(hashmap_t *hm, char key[], char value[]); void hashmap_expand(hashmap_t *hm); char *hashmap_get(hashmap_t *hm, char key[]); void hashmap_free_table(hashmap_t *hm); void hashmap_write_items(hashmap_t *hm, FILE *out); void hashmap_show_structure(hashmap_t *hm); void hashmap_save(hashmap_t *hm, char *filename); int hashmap_load(hashmap_t *hm, char *filename); #endif
__MACOSX/a1-code/._hashmap.h
a1-code/deltas_main.o
a1-code/save_deltas
a1-code/print_graph.c
void print_graph(int *data, int len, int max_height){ int i,j,min_element,max_element,range; double units_per_height, val; min_element = data[0]; max_element = data[0]; for(i = 1; i < len; i++){ if(min_element > data[i]) min_element = data[i]; if(max_element < data[i]) max_element = data[i]; } range = max_element - min_element; units_per_height = (double)range / max_height; printf("length: %d\n", len); printf("min: %d\n", min_element); printf("max: %d\n", max_element); printf("range: %d\n", range); printf("max_height: %d\n", max_height); printf("units_per_height: %.2lf\n", units_per_height); printf("\n\n%6c"); for(i = 0; i < len; i++){ if(i%5 == 0) printf("+"); else printf("-"); } printf("\n"); for(val = max_element; val >= 0; val -= units_per_height){ printf("%4d |" , (int)val); for(j = 0; j < len; j++){ if(data[j] >= val) printf("X"); else printf(" "); } printf("\n"); } printf("%6c"); for(i = 0; i < len; i++){ if(i%5 == 0) printf("+"); else printf("-"); } printf("\n%6c"); for(i = 0; i < len; i+=5){ printf("%-5d", i); } printf("\n"); }
__MACOSX/a1-code/._print_graph.c
a1-code/test_hash_main_data.sh
#!/bin/bash T=0 # global test number ((T++)) tnames[T]="start-print-quit" read -r -d '' input[$T] <<"ENDIN" print quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> print HM> quit ENDOUT ((T++)) tnames[T]="hashcode-get-empty" read -r -d '' input[$T] <<"ENDIN" print hashcode a hashcode A hashcode Aa hashcode apple hashcode banana get a get Aa get apple get banana quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> print HM> hashcode a 97 HM> hashcode A 65 HM> hashcode Aa 24897 HM> hashcode apple 1819308129 HM> hashcode banana 1634623842 HM> get a NOT FOUND HM> get Aa NOT FOUND HM> get apple NOT FOUND HM> get banana NOT FOUND HM> quit ENDOUT ((T++)) tnames[T]="get-single" read -r -d '' input[$T] <<"ENDIN" print put apple fruit get apple get banana quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> print HM> put apple fruit HM> get apple FOUND: fruit HM> get banana NOT FOUND HM> quit ENDOUT ((T++)) tnames[T]="put3" read -r -d '' input[$T] <<"ENDIN" put Kyle alive put Kenny dead put Stan alive print get Kyle get Kenny get Stan get Cartman get Token quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put Kyle alive HM> put Kenny dead HM> put Stan alive HM> print Kyle : alive Stan : alive Kenny : dead HM> get Kyle FOUND: alive HM> get Kenny FOUND: dead HM> get Stan FOUND: alive HM> get Cartman NOT FOUND HM> get Token NOT FOUND HM> quit ENDOUT ((T++)) tnames[T]="put-collisions" read -r -d '' input[$T] <<"ENDIN" put B 1 put D 2 put N 3 print get B get D get N get C get I put A 4 put C 5 put I 6 put X 7 put W 8 print get A get B get C get D get E get I get X get W get Z quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put B 1 HM> put D 2 HM> put N 3 HM> print B : 1 D : 2 N : 3 HM> get B FOUND: 1 HM> get D FOUND: 2 HM> get N FOUND: 3 HM> get C NOT FOUND HM> get I NOT FOUND HM> put A 4 HM> put C 5 HM> put I 6 HM> put X 7 HM> put W 8 HM> print A : 4 B : 1 C : 5 W : 8 D : 2 N : 3 I : 6 X : 7 HM> get A FOUND: 4 HM> get B FOUND: 1 HM> get C FOUND: 5 HM> get D FOUND: 2 HM> get E NOT FOUND HM> get I FOUND: 6 HM> get X FOUND: 7 HM> get W FOUND: 8 HM> get Z NOT FOUND HM> quit ENDOUT ((T++)) tnames[T]="put3-structure" read -r -d '' input[$T] <<"ENDIN" put B 1 put D 2 put N 3 print get B get D get N get C get I structure quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put B 1 HM> put D 2 HM> put N 3 HM> print B : 1 D : 2 N : 3 HM> get B FOUND: 1 HM> get D FOUND: 2 HM> get N FOUND: 3 HM> get C NOT FOUND HM> get I NOT FOUND HM> structure item_count: 3 table_size: 5 load_factor: 0.6000 0 : 1 : {(66) B : 1} 2 : 3 : {(68) D : 2} {(78) N : 3} 4 : HM> quit ENDOUT ((T++)) tnames[T]="put-overwrite" read -r -d '' input[$T] <<"ENDIN" put B 1 put D 2 put N 3 put A 4 put C 5 put I 6 put X 7 put W 8 structure put B 11 put I 66 put A 44 put W 88 structure get B get D get I get W get X quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put B 1 HM> put D 2 HM> put N 3 HM> put A 4 HM> put C 5 HM> put I 6 HM> put X 7 HM> put W 8 HM> structure item_count: 8 table_size: 5 load_factor: 1.6000 0 : {(65) A : 4} 1 : {(66) B : 1} 2 : {(67) C : 5} {(87) W : 8} 3 : {(68) D : 2} {(78) N : 3} {(73) I : 6} {(88) X : 7} 4 : HM> put B 11 Overwriting previous key/val HM> put I 66 Overwriting previous key/val HM> put A 44 Overwriting previous key/val HM> put W 88 Overwriting previous key/val HM> structure item_count: 8 table_size: 5 load_factor: 1.6000 0 : {(65) A : 44} 1 : {(66) B : 11} 2 : {(67) C : 5} {(87) W : 88} 3 : {(68) D : 2} {(78) N : 3} {(73) I : 66} {(88) X : 7} 4 : HM> get B FOUND: 11 HM> get D FOUND: 2 HM> get I FOUND: 66 HM> get W FOUND: 88 HM> get X FOUND: 7 HM> quit ENDOUT ((T++)) tnames[T]="larger-structure" read -r -d '' input[$T] <<"ENDIN" put Kyle alive put Kenny dead put Stan alive print structure put Cartman jerk put Timmy TIMMY! put MrGarrison odd put MrHat very-odd put Butters lovable put Chef disavowed print structure quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put Kyle alive HM> put Kenny dead HM> put Stan alive HM> print Kyle : alive Stan : alive Kenny : dead HM> structure item_count: 3 table_size: 5 load_factor: 0.6000 0 : {(1701607755) Kyle : alive} 1 : {(1851880531) Stan : alive} 2 : {(521543771467) Kenny : dead} 3 : 4 : HM> put Cartman jerk HM> put Timmy TIMMY! HM> put MrGarrison odd HM> put MrHat very-odd HM> put Butters lovable HM> put Chef disavowed HM> print Kyle : alive Cartman : jerk Butters : lovable Stan : alive MrHat : very-odd Kenny : dead MrGarrison : odd Timmy : TIMMY! Chef : disavowed HM> structure item_count: 9 table_size: 5 load_factor: 1.8000 0 : {(1701607755) Kyle : alive} {(31069370171154755) Cartman : jerk} {(32495402392778050) Butters : lovable} 1 : {(1851880531) Stan : alive} {(499848344141) MrHat : very-odd} 2 : {(521543771467) Kenny : dead} {(8316304022500241997) MrGarrison : odd} 3 : {(521526929748) Timmy : TIMMY!} 4 : {(1717921859) Chef : disavowed} HM> quit ENDOUT ((T++)) tnames[T]="put3-EOF" read -r -d '' input[$T] <<"ENDIN" put Kyle alive put Kenny dead put Stan alive print get Kyle ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put Kyle alive HM> put Kenny dead HM> put Stan alive HM> print Kyle : alive Stan : alive Kenny : dead HM> get Kyle FOUND: alive HM> ENDOUT ((T++)) tnames[T]="clear-put-clear" read -r -d '' input[$T] <<"ENDIN" clear print structure put Kyle alive put Kenny dead put Stan alive put Cartman jerk print structure clear print structure put Timmy TIMMY! put MrGarrison odd put MrHat very-odd put Butters lovable put Chef disavowed print structure clear print structure ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> clear HM> print HM> structure item_count: 0 table_size: 5 load_factor: 0.0000 0 : 1 : 2 : 3 : 4 : HM> put Kyle alive HM> put Kenny dead HM> put Stan alive HM> put Cartman jerk HM> print Kyle : alive Cartman : jerk Stan : alive Kenny : dead HM> structure item_count: 4 table_size: 5 load_factor: 0.8000 0 : {(1701607755) Kyle : alive} {(31069370171154755) Cartman : jerk} 1 : {(1851880531) Stan : alive} 2 : {(521543771467) Kenny : dead} 3 : 4 : HM> clear HM> print HM> structure item_count: 0 table_size: 5 load_factor: 0.0000 0 : 1 : 2 : 3 : 4 : HM> put Timmy TIMMY! HM> put MrGarrison odd HM> put MrHat very-odd HM> put Butters lovable HM> put Chef disavowed HM> print Butters : lovable MrHat : very-odd MrGarrison : odd Timmy : TIMMY! Chef : disavowed HM> structure item_count: 5 table_size: 5 load_factor: 1.0000 0 : {(32495402392778050) Butters : lovable} 1 : {(499848344141) MrHat : very-odd} 2 : {(8316304022500241997) MrGarrison : odd} 3 : {(521526929748) Timmy : TIMMY!} 4 : {(1717921859) Chef : disavowed} HM> clear HM> print HM> structure item_count: 0 table_size: 5 load_factor: 0.0000 0 : 1 : 2 : 3 : 4 : HM> ENDOUT ((T++)) tnames[T]="put3-save" read -r -d '' input[$T] <<"ENDIN" put A 1 put E 2 put C 3 put D 4 save test-data/put3.tmp quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put A 1 HM> put E 2 HM> put C 3 HM> put D 4 HM> save test-data/put3.tmp HM> quit ENDOUT # tfiles[T]="test-data/put3.tmp" read -r -d '' tfiles_expect[$T] <<"ENDOUT" 5 4 A : 1 C : 3 D : 4 E : 2 ENDOUT ((T++)) tnames[T]="put-many-save" read -r -d '' input[$T] <<"ENDIN" put Kyle alive put Kenny dead put Stan alive put Cartman jerk put Timmy TIMMY! put MrGarrison odd put MrHat very-odd put Butters lovable put Chef disavowed print structure save test-data/put-many.tmp ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put Kyle alive HM> put Kenny dead HM> put Stan alive HM> put Cartman jerk HM> put Timmy TIMMY! HM> put MrGarrison odd HM> put MrHat very-odd HM> put Butters lovable HM> put Chef disavowed HM> print Kyle : alive Cartman : jerk Butters : lovable Stan : alive MrHat : very-odd Kenny : dead MrGarrison : odd Timmy : TIMMY! Chef : disavowed HM> structure item_count: 9 table_size: 5 load_factor: 1.8000 0 : {(1701607755) Kyle : alive} {(31069370171154755) Cartman : jerk} {(32495402392778050) Butters : lovable} 1 : {(1851880531) Stan : alive} {(499848344141) MrHat : very-odd} 2 : {(521543771467) Kenny : dead} {(8316304022500241997) MrGarrison : odd} 3 : {(521526929748) Timmy : TIMMY!} 4 : {(1717921859) Chef : disavowed} HM> save test-data/put-many.tmp HM> ENDOUT # tfiles[T]="test-data/put-many.tmp" read -r -d '' tfiles_expect[$T] <<"ENDOUT" 5 9 Kyle : alive Cartman : jerk Butters : lovable Stan : alive MrHat : very-odd Kenny : dead MrGarrison : odd Timmy : TIMMY! Chef : disavowed ENDOUT ((T++)) tnames[T]="save-load" read -r -d '' input[$T] <<"ENDIN" put A 1 put E 2 put C 3 put D 4 save test-data/save-load.tmp clear print load test-data/save-load.tmp print structure get E get R get A put R 5 put S 6 print structure get R get S load test-data/save-load.tmp print structure get R get S load test-data/not-there.tmp print quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put A 1 HM> put E 2 HM> put C 3 HM> put D 4 HM> save test-data/save-load.tmp HM> clear HM> print HM> load test-data/save-load.tmp HM> print A : 1 C : 3 D : 4 E : 2 HM> structure item_count: 4 table_size: 5 load_factor: 0.8000 0 : {(65) A : 1} 1 : 2 : {(67) C : 3} 3 : {(68) D : 4} 4 : {(69) E : 2} HM> get E FOUND: 2 HM> get R NOT FOUND HM> get A FOUND: 1 HM> put R 5 HM> put S 6 HM> print A : 1 C : 3 R : 5 D : 4 S : 6 E : 2 HM> structure item_count: 6 table_size: 5 load_factor: 1.2000 0 : {(65) A : 1} 1 : 2 : {(67) C : 3} {(82) R : 5} 3 : {(68) D : 4} {(83) S : 6} 4 : {(69) E : 2} HM> get R FOUND: 5 HM> get S FOUND: 6 HM> load test-data/save-load.tmp HM> print A : 1 C : 3 D : 4 E : 2 HM> structure item_count: 4 table_size: 5 load_factor: 0.8000 0 : {(65) A : 1} 1 : 2 : {(67) C : 3} 3 : {(68) D : 4} 4 : {(69) E : 2} HM> get R NOT FOUND HM> get S NOT FOUND HM> load test-data/not-there.tmp ERROR: could not open file 'test-data/not-there.tmp' load failed HM> print A : 1 C : 3 D : 4 E : 2 HM> quit ENDOUT # tfiles[T]="test-data/save-load.tmp" read -r -d '' tfiles_expect[$T] <<"ENDOUT" 5 4 A : 1 C : 3 D : 4 E : 2 ENDOUT ((T++)) tnames[T]="prime-expand" read -r -d '' input[$T] <<"ENDIN" next_prime 5 next_prime 6 next_prime 10 next_prime 25 next_prime 1024 put A 1 put B 2 put C 3 put D 4 put E 5 put F 6 put G 7 print structure expand print structure expand print structure clear put Kyle alive put Kenny dead put Stan alive put Cartman jerk put Timmy TIMMY! put MrGarrison odd put MrHat very-odd put Butters lovable put Chef disavowed print structure expand print structure put Token dude put Wendy gal put Jimmy crutches put Damien evil put Santa bad put Jesus good put Marvin starvin print structure expand print structure expand print structure ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> next_prime 5 5 HM> next_prime 6 7 HM> next_prime 10 11 HM> next_prime 25 29 HM> next_prime 1024 1031 HM> put A 1 HM> put B 2 HM> put C 3 HM> put D 4 HM> put E 5 HM> put F 6 HM> put G 7 HM> print A : 1 F : 6 B : 2 G : 7 C : 3 D : 4 E : 5 HM> structure item_count: 7 table_size: 5 load_factor: 1.4000 0 : {(65) A : 1} {(70) F : 6} 1 : {(66) B : 2} {(71) G : 7} 2 : {(67) C : 3} 3 : {(68) D : 4} 4 : {(69) E : 5} HM> expand HM> print B : 2 C : 3 D : 4 E : 5 F : 6 G : 7 A : 1 HM> structure item_count: 7 table_size: 11 load_factor: 0.6364 0 : {(66) B : 2} 1 : {(67) C : 3} 2 : {(68) D : 4} 3 : {(69) E : 5} 4 : {(70) F : 6} 5 : {(71) G : 7} 6 : 7 : 8 : 9 : 10 : {(65) A : 1} HM> expand HM> print E : 5 F : 6 G : 7 A : 1 B : 2 C : 3 D : 4 HM> structure item_count: 7 table_size: 23 load_factor: 0.3043 0 : {(69) E : 5} 1 : {(70) F : 6} 2 : {(71) G : 7} 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : 11 : 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : {(65) A : 1} 20 : {(66) B : 2} 21 : {(67) C : 3} 22 : {(68) D : 4} HM> clear HM> put Kyle alive HM> put Kenny dead HM> put Stan alive HM> put Cartman jerk HM> put Timmy TIMMY! HM> put MrGarrison odd HM> put MrHat very-odd HM> put Butters lovable HM> put Chef disavowed HM> print Kyle : alive Cartman : jerk Butters : lovable Stan : alive MrHat : very-odd Kenny : dead MrGarrison : odd Timmy : TIMMY! Chef : disavowed HM> structure item_count: 9 table_size: 5 load_factor: 1.8000 0 : {(1701607755) Kyle : alive} {(31069370171154755) Cartman : jerk} {(32495402392778050) Butters : lovable} 1 : {(1851880531) Stan : alive} {(499848344141) MrHat : very-odd} 2 : {(521543771467) Kenny : dead} {(8316304022500241997) MrGarrison : odd} 3 : {(521526929748) Timmy : TIMMY!} 4 : {(1717921859) Chef : disavowed} HM> expand HM> print Cartman : jerk Butters : lovable Timmy : TIMMY! Kyle : alive MrHat : very-odd Kenny : dead Chef : disavowed Stan : alive MrGarrison : odd HM> structure item_count: 9 table_size: 11 load_factor: 0.8182 0 : {(31069370171154755) Cartman : jerk} {(32495402392778050) Butters : lovable} {(521526929748) Timmy : TIMMY!} 1 : {(1701607755) Kyle : alive} 2 : 3 : {(499848344141) MrHat : very-odd} 4 : {(521543771467) Kenny : dead} 5 : {(1717921859) Chef : disavowed} 6 : {(1851880531) Stan : alive} 7 : 8 : 9 : {(8316304022500241997) MrGarrison : odd} 10 : HM> put Token dude HM> put Wendy gal HM> put Jimmy crutches HM> put Damien evil HM> put Santa bad HM> put Jesus good HM> put Marvin starvin HM> print Cartman : jerk Butters : lovable Timmy : TIMMY! Santa : bad Kyle : alive Jimmy : crutches MrHat : very-odd Damien : evil Kenny : dead Token : dude Jesus : good Chef : disavowed Stan : alive Marvin : starvin MrGarrison : odd Wendy : gal HM> structure item_count: 16 table_size: 11 load_factor: 1.4545 0 : {(31069370171154755) Cartman : jerk} {(32495402392778050) Butters : lovable} {(521526929748) Timmy : TIMMY!} {(418565218643) Santa : bad} 1 : {(1701607755) Kyle : alive} {(521526929738) Jimmy : crutches} 2 : 3 : {(499848344141) MrHat : very-odd} {(121381839528260) Damien : evil} 4 : {(521543771467) Kenny : dead} {(474147942228) Token : dude} {(495891735882) Jesus : good} 5 : {(1717921859) Chef : disavowed} 6 : {(1851880531) Stan : alive} {(121399237828941) Marvin : starvin} 7 : 8 : 9 : {(8316304022500241997) MrGarrison : odd} 10 : {(521375999319) Wendy : gal} HM> expand HM> print Timmy : TIMMY! Santa : bad Marvin : starvin Damien : evil Wendy : gal Cartman : jerk Jimmy : crutches Kenny : dead Jesus : good Chef : disavowed MrHat : very-odd Butters : lovable Stan : alive MrGarrison : odd Kyle : alive Token : dude HM> structure item_count: 16 table_size: 23 load_factor: 0.6957 0 : 1 : 2 : {(521526929748) Timmy : TIMMY!} {(418565218643) Santa : bad} {(121399237828941) Marvin : starvin} 3 : 4 : 5 : 6 : 7 : 8 : 9 : {(121381839528260) Damien : evil} 10 : 11 : 12 : {(521375999319) Wendy : gal} 13 : {(31069370171154755) Cartman : jerk} 14 : 15 : {(521526929738) Jimmy : crutches} 16 : 17 : {(521543771467) Kenny : dead} {(495891735882) Jesus : good} {(1717921859) Chef : disavowed} 18 : {(499848344141) MrHat : very-odd} 19 : {(32495402392778050) Butters : lovable} {(1851880531) Stan : alive} {(8316304022500241997) MrGarrison : odd} 20 : {(1701607755) Kyle : alive} 21 : 22 : {(474147942228) Token : dude} HM> expand HM> print Jimmy : crutches Timmy : TIMMY! Kyle : alive Butters : lovable Cartman : jerk Stan : alive Wendy : gal Jesus : good Damien : evil MrGarrison : odd Kenny : dead Marvin : starvin Santa : bad Chef : disavowed MrHat : very-odd Token : dude HM> structure item_count: 16 table_size: 47 load_factor: 0.3404 0 : {(521526929738) Jimmy : crutches} 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : {(521526929748) Timmy : TIMMY!} 11 : 12 : 13 : 14 : 15 : {(1701607755) Kyle : alive} 16 : 17 : 18 : 19 : {(32495402392778050) Butters : lovable} 20 : {(31069370171154755) Cartman : jerk} {(1851880531) Stan : alive} 21 : 22 : 23 : {(521375999319) Wendy : gal} {(495891735882) Jesus : good} 24 : {(121381839528260) Damien : evil} 25 : 26 : {(8316304022500241997) MrGarrison : odd} 27 : 28 : 29 : 30 : 31 : {(521543771467) Kenny : dead} 32 : 33 : 34 : 35 : {(121399237828941) Marvin : starvin} 36 : 37 : 38 : 39 : 40 : {(418565218643) Santa : bad} 41 : 42 : 43 : {(1717921859) Chef : disavowed} 44 : {(499848344141) MrHat : very-odd} 45 : {(474147942228) Token : dude} 46 : HM> ENDOUT ((T++)) tnames[T]="stress" read -r -d '' input[$T] <<"ENDIN" put Kyle alive put Kenny dead put Stan alive put Cartman jerk put Timmy TIMMY! put MrGarrison odd put MrHat very-odd put Butters lovable put Chef disavowed structure expand structure save test-data/stress1.tmp put Token dude put Wendy gal put Jimmy crutches put Damien evil put Santa bad put Jesus good put Marvin starvin put Kenny ALIVE put MrHat MrStick structure expand expand structure save test-data/stress2.tmp load test-data/stress1.tmp structure get Santa get Marvin get Cartman get MrHat put Syndney Portier put Robert Smith expand expand expand structure get Cartman get Robert save test-data/stress3.tmp load test-data/stress2.tmp print structure get MrGarrison get MrHat get Kenny get Santa get Wendy get Marvin get Sydney put Kenny dead load test-data/stress3.tmp get Kenny structure expand structure quit ENDIN # read -r -d '' output[$T] <<"ENDOUT" Hashmap Demo Commands: hashcode <key> : prints out the numeric hash code for the given key (does not change the hash map) put <key> <val> : inserts the given key/val into the hash map, overwrites existing values if present get <key> : prints the value associated with the given key or NOT FOUND print : shows contents of the hashmap ordered by how they appear in the table structure : prints detailed structure of the hash map clear : reinitializes hash map to be empty with default size save <file> : writes the contents of the hash map the given file load <file> : clears the current hash map and loads the one in the given file next_prime <int> : if <int> is prime, prints it, otherwise finds the next prime and prints it expand : expands memory size of hashmap to reduce its load factor quit : exit the program HM> put Kyle alive HM> put Kenny dead HM> put Stan alive HM> put Cartman jerk HM> put Timmy TIMMY! HM> put MrGarrison odd HM> put MrHat very-odd HM> put Butters lovable HM> put Chef disavowed HM> structure item_count: 9 table_size: 5 load_factor: 1.8000 0 : {(1701607755) Kyle : alive} {(31069370171154755) Cartman : jerk} {(32495402392778050) Butters : lovable} 1 : {(1851880531) Stan : alive} {(499848344141) MrHat : very-odd} 2 : {(521543771467) Kenny : dead} {(8316304022500241997) MrGarrison : odd} 3 : {(521526929748) Timmy : TIMMY!} 4 : {(1717921859) Chef : disavowed} HM> expand HM> structure item_count: 9 table_size: 11 load_factor: 0.8182 0 : {(31069370171154755) Cartman : jerk} {(32495402392778050) Butters : lovable} {(521526929748) Timmy : TIMMY!} 1 : {(1701607755) Kyle : alive} 2 : 3 : {(499848344141) MrHat : very-odd} 4 : {(521543771467) Kenny : dead} 5 : {(1717921859) Chef : disavowed} 6 : {(1851880531) Stan : alive} 7 : 8 : 9 : {(8316304022500241997) MrGarrison : odd} 10 : HM> save test-data/stress1.tmp HM> put Token dude HM> put Wendy gal HM> put Jimmy crutches HM> put Damien evil HM> put Santa bad HM> put Jesus good HM> put Marvin starvin HM> put Kenny ALIVE Overwriting previous key/val HM> put MrHat MrStick Overwriting previous key/val HM> structure item_count: 16 table_size: 11 load_factor: 1.4545 0 : {(31069370171154755) Cartman : jerk} {(32495402392778050) Butters : lovable} {(521526929748) Timmy : TIMMY!} {(418565218643) Santa : bad} 1 : {(1701607755) Kyle : alive} {(521526929738) Jimmy : crutches} 2 : 3 : {(499848344141) MrHat : MrStick} {(121381839528260) Damien : evil} 4 : {(521543771467) Kenny : ALIVE} {(474147942228) Token : dude} {(495891735882) Jesus : good} 5 : {(1717921859) Chef : disavowed} 6 : {(1851880531) Stan : alive} {(121399237828941) Marvin : starvin} 7 : 8 : 9 : {(8316304022500241997) MrGarrison : odd} 10 : {(521375999319) Wendy : gal} HM> expand HM> expand HM> structure item_count: 16 table_size: 47 load_factor: 0.3404 0 : {(521526929738) Jimmy : crutches} 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : {(521526929748) Timmy : TIMMY!} 11 : 12 : 13 : 14 : 15 : {(1701607755) Kyle : alive} 16 : 17 : 18 : 19 : {(32495402392778050) Butters : lovable} 20 : {(31069370171154755) Cartman : jerk} {(1851880531) Stan : alive} 21 : 22 : 23 : {(521375999319) Wendy : gal} {(495891735882) Jesus : good} 24 : {(121381839528260) Damien : evil} 25 : 26 : {(8316304022500241997) MrGarrison : odd} 27 : 28 : 29 : 30 : 31 : {(521543771467) Kenny : ALIVE} 32 : 33 : 34 : 35 : {(121399237828941) Marvin : starvin} 36 : 37 : 38 : 39 : 40 : {(418565218643) Santa : bad} 41 : 42 : 43 : {(1717921859) Chef : disavowed} 44 : {(499848344141) MrHat : MrStick} 45 : {(474147942228) Token : dude} 46 : HM> save test-data/stress2.tmp HM> load test-data/stress1.tmp HM> structure item_count: 9 table_size: 11 load_factor: 0.8182 0 : {(31069370171154755) Cartman : jerk} {(32495402392778050) Butters : lovable} {(521526929748) Timmy : TIMMY!} 1 : {(1701607755) Kyle : alive} 2 : 3 : {(499848344141) MrHat : very-odd} 4 : {(521543771467) Kenny : dead} 5 : {(1717921859) Chef : disavowed} 6 : {(1851880531) Stan : alive} 7 : 8 : 9 : {(8316304022500241997) MrGarrison : odd} 10 : HM> get Santa NOT FOUND HM> get Marvin NOT FOUND HM> get Cartman FOUND: jerk HM> get MrHat FOUND: very-odd HM> put Syndney Portier HM> put Robert Smith HM> expand HM> expand HM> expand HM> structure item_count: 11 table_size: 97 load_factor: 0.1134 0 : 1 : 2 : 3 : {(521543771467) Kenny : dead} 4 : 5 : 6 : {(521526929748) Timmy : TIMMY!} 7 : 8 : 9 : 10 : 11 : 12 : 13 : 14 : 15 : {(32495402392778050) Butters : lovable} 16 : 17 : 18 : 19 : 20 : 21 : 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 : 30 : 31 : 32 : 33 : {(8316304022500241997) MrGarrison : odd} 34 : 35 : 36 : 37 : 38 : 39 : 40 : 41 : 42 : 43 : 44 : 45 : 46 : 47 : 48 : 49 : 50 : 51 : 52 : 53 : 54 : 55 : {(128034676043602) Robert : Smith} 56 : 57 : 58 : 59 : 60 : 61 : {(1717921859) Chef : disavowed} 62 : 63 : {(31069370171154755) Cartman : jerk} 64 : 65 : 66 : 67 : 68 : 69 : 70 : 71 : 72 : 73 : 74 : {(34169996987758931) Syndney : Portier} 75 : 76 : 77 : {(499848344141) MrHat : very-odd} 78 : 79 : 80 : 81 : 82 : 83 : 84 : {(1851880531) Stan : alive} 85 : 86 : 87 : 88 : 89 : 90 : 91 : 92 : 93 : 94 : 95 : 96 : {(1701607755) Kyle : alive} HM> get Cartman FOUND: jerk HM> get Robert FOUND: Smith HM> save test-data/stress3.tmp HM> load test-data/stress2.tmp HM> print Jimmy : crutches Timmy : TIMMY! Kyle : alive Butters : lovable Cartman : jerk Stan : alive Wendy : gal Jesus : good Damien : evil MrGarrison : odd Kenny : ALIVE Marvin : starvin Santa : bad Chef : disavowed MrHat : MrStick Token : dude HM> structure item_count: 16 table_size: 47 load_factor: 0.3404 0 : {(521526929738) Jimmy : crutches} 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : {(521526929748) Timmy : TIMMY!} 11 : 12 : 13 : 14 : 15 : {(1701607755) Kyle : alive} 16 : 17 : 18 : 19 : {(32495402392778050) Butters : lovable} 20 : {(31069370171154755) Cartman : jerk} {(1851880531) Stan : alive} 21 : 22 : 23 : {(521375999319) Wendy : gal} {(495891735882) Jesus : good} 24 : {(121381839528260) Damien : evil} 25 : 26 : {(8316304022500241997) MrGarrison : odd} 27 : 28 : 29 : 30 : 31 : {(521543771467) Kenny : ALIVE} 32 : 33 : 34 : 35 : {(121399237828941) Marvin : starvin} 36 : 37 : 38 : 39 : 40 : {(418565218643) Santa : bad} 41 : 42 : 43 : {(1717921859) Chef : disavowed} 44 : {(499848344141) MrHat : MrStick} 45 : {(474147942228) Token : dude} 46 : HM> get MrGarrison FOUND: odd HM> get MrHat FOUND: MrStick HM> get Kenny FOUND: ALIVE HM> get Santa FOUND: bad HM> get Wendy FOUND: gal HM> get Marvin FOUND: starvin HM> get Sydney NOT FOUND HM> put Kenny dead Overwriting previous key/val HM> load test-data/stress3.tmp HM> get Kenny FOUND: dead HM> structure item_count: 11 table_size: 97 load_factor: 0.1134 0 : 1 : 2 : 3 : {(521543771467) Kenny : dead} 4 : 5 : 6 : {(521526929748) Timmy : TIMMY!} 7 : 8 : 9 : 10 : 11 : 12 : 13 : 14 : 15 : {(32495402392778050) Butters : lovable} 16 : 17 : 18 : 19 : 20 : 21 : 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 : 30 : 31 : 32 : 33 : {(8316304022500241997) MrGarrison : odd} 34 : 35 : 36 : 37 : 38 : 39 : 40 : 41 : 42 : 43 : 44 : 45 : 46 : 47 : 48 : 49 : 50 : 51 : 52 : 53 : 54 : 55 : {(128034676043602) Robert : Smith} 56 : 57 : 58 : 59 : 60 : 61 : {(1717921859) Chef : disavowed} 62 : 63 : {(31069370171154755) Cartman : jerk} 64 : 65 : 66 : 67 : 68 : 69 : 70 : 71 : 72 : 73 : 74 : {(34169996987758931) Syndney : Portier} 75 : 76 : 77 : {(499848344141) MrHat : very-odd} 78 : 79 : 80 : 81 : 82 : 83 : 84 : {(1851880531) Stan : alive} 85 : 86 : 87 : 88 : 89 : 90 : 91 : 92 : 93 : 94 : 95 : 96 : {(1701607755) Kyle : alive} HM> expand HM> structure item_count: 11 table_size: 197 load_factor: 0.0558 0 : 1 : 2 : 3 : {(521543771467) Kenny : dead} 4 : 5 : 6 : 7 : 8 : 9 : 10 : 11 : {(521526929748) Timmy : TIMMY!} 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : 20 : 21 : 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 : 30 : 31 : 32 : 33 : 34 : 35 : 36 : 37 : 38 : 39 : 40 : 41 : 42 : 43 : 44 : 45 : 46 : 47 : 48 : 49 : 50 : 51 : 52 : 53 : 54 : 55 : 56 : 57 : 58 : {(499848344141) MrHat : very-odd} 59 : {(128034676043602) Robert : Smith} 60 : 61 : 62 : 63 : 64 : 65 : 66 : 67 : 68 : 69 : 70 : 71 : 72 : 73 : 74 : 75 : 76 : 77 : {(34169996987758931) Syndney : Portier} 78 : 79 : 80 : 81 : 82 : {(8316304022500241997) MrGarrison : odd} 83 : 84 : 85 : 86 : 87 : 88 : 89 : 90 : 91 : 92 : {(32495402392778050) Butters : lovable} 93 : 94 : 95 : 96 : 97 : 98 : 99 : 100 : 101 : 102 : 103 : 104 : {(1717921859) Chef : disavowed} 105 : 106 : 107 : 108 : 109 : 110 : 111 : 112 : 113 : 114 : 115 : 116 : 117 : 118 : 119 : 120 : 121 : 122 : 123 : 124 : 125 : 126 : 127 : 128 : 129 : 130 : 131 : 132 : 133 : 134 : 135 : 136 : 137 : 138 : 139 : 140 : 141 : 142 : 143 : 144 : 145 : 146 : 147 : 148 : 149 : 150 : 151 : 152 : 153 : 154 : 155 : {(1851880531) Stan : alive} 156 : 157 : 158 : 159 : 160 : 161 : {(1701607755) Kyle : alive} 162 : 163 : 164 : 165 : 166 : 167 : 168 : {(31069370171154755) Cartman : jerk} 169 : 170 : 171 : 172 : 173 : 174 : 175 : 176 : 177 : 178 : 179 : 180 : 181 : 182 : 183 : 184 : 185 : 186 : 187 : 188 : 189 : 190 : 191 : 192 : 193 : 194 : 195 : 196 : HM> quit ENDOUT
__MACOSX/a1-code/._test_hash_main_data.sh
a1-code/test_read_deltas.o
a1-code/save_deltas.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "deltas.h" #define MODE_TEXT 1 #define MODE_INT 2 #define MODE_4BIT 3 int main(int argc, char *argv[]){ if(argc < 3){ printf("usage: %s <format> <filename>\n",argv[0]); printf("reads input from stdin and outputs in given format to <filename>\n"); printf("if typing numbers in, press Ctrl-D to end input\n"); printf(" <format> is one of\n"); printf(" text : text ints are in the given filename\n"); printf(" int : binary ints are in the given filename\n"); printf(" 4bit : 4bit binary ints are in the given filename\n"); return 1; } char *format = argv[1]; char *fname = argv[2]; int mode = -1; if( strcmp("text", format)==0 ){ mode = MODE_TEXT; } else if( strcmp("int", format)==0 ){ mode = MODE_INT; } else if( strcmp("4bit", format)==0 ){ mode = MODE_4BIT; } else{ printf("Unknown format '%s'\n",format); return 1; } FILE *fout = fopen(fname,"w"); int curr, prev; int result = fscanf(stdin,"%d",&curr); // handle first number if(result == EOF){ fclose(fout); printf("error: no numbers given\n"); return 1; } if(mode == MODE_TEXT){ fprintf(fout,"%d ",curr); } else if(mode == MODE_INT || mode == MODE_4BIT ){ fwrite(&curr,sizeof(int),1,fout); } int count = 1; prev=curr; while(fscanf(stdin,"%d",&curr) != EOF){ if(mode == MODE_TEXT){ int delta = curr - prev; fprintf(fout,"%d ",delta); prev = curr; count++; } else if(mode == MODE_INT){ int delta = curr - prev; fwrite(&delta,sizeof(int),1,fout); prev = curr; count++; } else if(mode == MODE_4BIT){ int prev2 = prev; prev = curr; if(fscanf(stdin,"%d",&curr) == EOF){ printf("incorrect length of input for 4bit format\n"); fclose(fout); return 1; } int delta1 = prev - prev2; int delta2 = curr - prev; // printf("[%d]: %d\n",count,delta1); // printf("[%d]: %d\n",count+1,delta2); if(delta1 > 7 || delta1 < -8 || delta2 > 7 || delta2 < -8){ printf("index %d: too large for 4bit: %d %d\n", count,delta1, delta2); return 1; } char byte = ((delta1 << 0 ) & 0b00001111) | ((delta2 << 4 ) & 0b11110000); fwrite(&byte, 1, 1, fout); count+=2; prev = curr; } } if(MODE_TEXT){ fprintf(fout,"\n"); } fclose(fout); printf("wrote %d ints to %s in %s format\n", count, fname, format); return 0; }
__MACOSX/a1-code/._save_deltas.c
a1-code/make
a1-code/read_deltas.o
a1-code/graph_main.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "deltas.h" #include <sys/types.h> #include <sys/stat.h> int main(int argc, char const *argv[]) { if(argc < 3){ printf("usage: %s <format> <filename>\n",argv[0]); printf(" <format> is one of\n"); printf(" text : text ints are in the given filename\n"); printf(" int : binary ints are in the given filename\n"); printf(" 4bit : 4bit binary ints are in the given filename\n"); return 1; } char *format = argv[1]; char *fname = argv[2]; return 0; }
__MACOSX/a1-code/._graph_main.c
a1-code/test_graph_file_data.sh
#!/bin/bash T=0 # global test number ((T++)) tnames[T]="text-ten-5" format[T]="text" height[T]="5" read -r -d '' input[$T] <<"ENDIN" 0 1 2 3 4 5 6 7 8 9 10 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading text format length: 11 min: 0 max: 10 range: 10 max_height: 5 units_per_height: 2.00 +----+----+ 10 | X 8 | XXX 6 | XXXXX 4 | XXXXXXX 2 | XXXXXXXXX 0 |XXXXXXXXXXX +----+----+ 0 5 10 ENDOUT ((T++)) tnames[T]="text-ten-20" format[T]="text" height[T]="20" read -r -d '' input[$T] <<"ENDIN" 0 1 2 3 4 5 6 7 8 9 10 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading text format length: 11 min: 0 max: 10 range: 10 max_height: 20 units_per_height: 0.50 +----+----+ 10 | X 9 | XX 9 | XX 8 | XXX 8 | XXX 7 | XXXX 7 | XXXX 6 | XXXXX 6 | XXXXX 5 | XXXXXX 5 | XXXXXX 4 | XXXXXXX 4 | XXXXXXX 3 | XXXXXXXX 3 | XXXXXXXX 2 | XXXXXXXXX 2 | XXXXXXXXX 1 | XXXXXXXXXX 1 | XXXXXXXXXX 0 |XXXXXXXXXXX 0 |XXXXXXXXXXX +----+----+ 0 5 10 ENDOUT ((T++)) tnames[T]="text-21-5" format[T]="text" height[T]="5" read -r -d '' input[$T] <<"ENDIN" 20 18 14 10 7 2 3 1 5 9 5 7 7 5 5 5 7 8 3 7 4 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading text format length: 21 min: 1 max: 20 range: 19 max_height: 5 units_per_height: 3.80 +----+----+----+----+ 20 |X 16 |XX 12 |XXX 8 |XXXX X X 4 |XXXXX XXXXXXXXXX XX 1 |XXXXXXXXXXXXXXXXXXXXX +----+----+----+----+ 0 5 10 15 20 ENDOUT ((T++)) tnames[T]="text-21-12" format[T]="text" height[T]="12" read -r -d '' input[$T] <<"ENDIN" 20 18 14 10 7 2 3 1 5 9 5 7 7 5 5 5 7 8 3 7 4 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading text format length: 21 min: 1 max: 20 range: 19 max_height: 12 units_per_height: 1.58 +----+----+----+----+ 20 |X 18 |XX 16 |XX 15 |XX 13 |XXX 12 |XXX 10 |XXXX 8 |XXXX X X 7 |XXXXX X XX XX X 5 |XXXXX XXXXXXXXXX X 4 |XXXXX XXXXXXXXXX XX 2 |XXXXXXX XXXXXXXXXXXXX 1 |XXXXXXXXXXXXXXXXXXXXX +----+----+----+----+ 0 5 10 15 20 ENDOUT ((T++)) tnames[T]="int-21-7" format[T]="int" height[T]="7" read -r -d '' input[$T] <<"ENDIN" 20 18 14 10 7 2 3 1 5 9 5 7 7 5 5 5 7 8 3 7 4 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading binary int format length: 21 min: 1 max: 20 range: 19 max_height: 7 units_per_height: 2.71 +----+----+----+----+ 20 |X 17 |XX 14 |XXX 11 |XXX 9 |XXXX X 6 |XXXXX X XX XX X 3 |XXXXX X XXXXXXXXXXXXX 1 |XXXXXXXXXXXXXXXXXXXXX +----+----+----+----+ 0 5 10 15 20 ENDOUT ((T++)) tnames[T]="int-21-15" format[T]="int" height[T]="15" read -r -d '' input[$T] <<"ENDIN" 20 18 14 10 7 2 3 1 5 9 5 7 7 5 5 5 7 8 3 7 4 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading binary int format length: 21 min: 1 max: 20 range: 19 max_height: 15 units_per_height: 1.27 +----+----+----+----+ 20 |X 18 |XX 17 |XX 16 |XX 14 |XXX 13 |XXX 12 |XXX 11 |XXX 9 |XXXX X 8 |XXXX X X 7 |XXXXX X XX XX X 6 |XXXXX X XX XX X 4 |XXXXX XXXXXXXXXX XX 3 |XXXXX X XXXXXXXXXXXXX 2 |XXXXXXX XXXXXXXXXXXXX 1 |XXXXXXXXXXXXXXXXXXXXX +----+----+----+----+ 0 5 10 15 20 ENDOUT ((T++)) tnames[T]="text-wave-8" format[T]="text" height[T]="8" read -r -d '' input[$T] <<"ENDIN" 0 2 4 6 8 10 11 13 14 16 17 18 19 19 20 20 20 20 19 19 18 17 16 15 14 12 10 9 7 5 3 1 -1 -3 -5 -7 -9 -11 -12 -14 -15 -16 -17 -18 -19 -20 -20 -20 -20 -20 -19 -19 -18 -17 -15 -14 -13 -11 -9 -7 -6 -4 -2 0 2 4 6 8 10 11 13 14 16 17 18 19 19 20 20 20 20 19 19 18 17 16 15 14 12 10 9 7 5 3 1 -1 -3 -5 -7 -9 -11 -12 -14 -15 -16 -17 -18 -19 -20 -20 -20 -20 -20 -19 -19 -18 -17 -15 -14 -13 -11 -9 -7 -6 -4 -2 0 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading text format length: 127 min: -20 max: 20 range: 40 max_height: 8 units_per_height: 5.00 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+- 20 | XXXX XXXX 15 | XXXXXXXXXXXXXXX XXXXXXXXXXXXXXX 10 | XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX 5 | XXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX 0 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X -5 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX -10 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX -15 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXX -20 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+- 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 ENDOUT ((T++)) tnames[T]="int-wave-15" format[T]="int" height[T]="15" read -r -d '' input[$T] <<"ENDIN" 0 2 4 6 8 10 11 13 14 16 17 18 19 19 20 20 20 20 19 19 18 17 16 15 14 12 10 9 7 5 3 1 -1 -3 -5 -7 -9 -11 -12 -14 -15 -16 -17 -18 -19 -20 -20 -20 -20 -20 -19 -19 -18 -17 -15 -14 -13 -11 -9 -7 -6 -4 -2 0 2 4 6 8 10 11 13 14 16 17 18 19 19 20 20 20 20 19 19 18 17 16 15 14 12 10 9 7 5 3 1 -1 -3 -5 -7 -9 -11 -12 -14 -15 -16 -17 -18 -19 -20 -20 -20 -20 -20 -19 -19 -18 -17 -15 -14 -13 -11 -9 -7 -6 -4 -2 0 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading binary int format length: 127 min: -20 max: 20 range: 40 max_height: 15 units_per_height: 2.67 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+- 20 | XXXX XXXX 17 | XXXXXXXXXXXX XXXXXXXXXXXX 14 | XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX 12 | XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX 9 | XXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXX 6 | XXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXX 4 | XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX 1 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -1 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X -4 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX -6 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXX -9 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX -12 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX -14 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXX -17 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXX -20 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+- 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 ENDOUT ((T++)) tnames[T]="text-rand-14" format[T]="text" height[T]="14" read -r -d '' input[$T] <<"ENDIN" 18 9 84 26 41 90 60 61 78 17 71 38 24 83 18 53 85 79 21 36 16 14 52 95 21 34 11 42 95 71 49 7 58 77 62 84 24 14 47 8 87 94 96 17 55 75 89 73 79 94 76 37 59 66 86 92 15 7 75 30 67 7 5 42 55 39 2 75 81 26 14 59 48 59 89 25 96 77 35 36 46 26 8 47 7 15 47 98 75 67 90 5 83 85 43 90 40 94 43 84 38 75 22 13 37 77 83 13 12 9 18 67 79 39 61 83 52 72 34 63 44 5 14 51 14 49 91 24 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading text format length: 128 min: 2 max: 98 range: 96 max_height: 14 units_per_height: 6.86 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-- 98 | X 91 | X X XX X X X X X X 84 | X X X X X X XXX X X XX X X X X X X X X X 77 | X X X X XX X X X X XXX X XX XX X X XX X X XX X X X XX X X X 70 | X X X X X XX X XX X X XXX XXXXXX XX X XX X XX XX X XX X X X X XX X X X X 63 | X X X X X XX X XX X X XXX XXXXXX XXX X X XX X XX XXXX XX X X X X XX XX X X X X 56 | X XXXX X X XX X XX XXXX XXX XXXXXX XXXX X X XX X XX XX XXXX XX X X X X XX XX XX X X X 50 | X XXXX X X XXX XX XX XXXX XXX XXXXXXX XXXX X X X XX X XX XX XXXX XX X X X X XX XX XXXX X X X 43 | X XXXX X X XXX XX XXX XXXX X XXX XXXXXXX XXXX X X X XX XXXX XX X X XXXXX XXXX XXX X XX XX XXXX XX X XX 36 | X XXXXX XX X XXX X XX XXXX XXXX X XXX XXXXXXXXXXXX X X XXX XX XXXX XX XX X XXXXX XXXXXXXXXX XXX XXXXXXX XX X XX 29 | X XXXXX XX X XXX X XX X XXXX XXXX X XXX XXXXXXXXXXXX XXX XXX XX XXXX XXXXX X XXXXX XXXXXXXXXX XXX XXXXXXXXXX X XX 22 | XXXXXXX XXXX XXX X XX X XXXX XXXXX X XXX XXXXXXXXXXXX XXX XXX XXX XXXXXXXXXXX X XXXXX XXXXXXXXXXX XXX XXXXXXXXXX X XXX 15 |X XXXXXXXXXXXXXXXXXXX XXXX XXXX XXXXX X XXXXXXXXXXXXXXXXX XXX XXX XXX XXXXXXXXXXX X XXXXXX XXXXXXXXXXX XXX XXXXXXXXXXX X XXX 8 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX XXX XXX XXXXXXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX 2 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-- 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 ENDOUT ((T++)) tnames[T]="int-rand-32" format[T]="text" height[T]="32" read -r -d '' input[$T] <<"ENDIN" 18 9 84 26 41 90 60 61 78 17 71 38 24 83 18 53 85 79 21 36 16 14 52 95 21 34 11 42 95 71 49 7 58 77 62 84 24 14 47 8 87 94 96 17 55 75 89 73 79 94 76 37 59 66 86 92 15 7 75 30 67 7 5 42 55 39 2 75 81 26 14 59 48 59 89 25 96 77 35 36 46 26 8 47 7 15 47 98 75 67 90 5 83 85 43 90 40 94 43 84 38 75 22 13 37 77 83 13 12 9 18 67 79 39 61 83 52 72 34 63 44 5 14 51 14 49 91 24 ENDIN # read -r -d '' output[$T] <<"ENDOUT" Reading text format length: 128 min: 2 max: 98 range: 96 max_height: 32 units_per_height: 3.00 +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-- 98 | X 95 | X X X X X 92 | X X XX X X X X X 89 | X X X XX X X X X X X X X X X 86 | X X X XXX X X XX X X X X X X X 83 | X X X X X X X XXX X X XX X X X X XX X X X X X X 80 | X X X X X X X XXX X X XX X X X X X XX X X X X X X 77 | X X X X XX X X X X XXX X XX XX X X XX X X XX X X X XX X X X 74 | X X X X XX X X X X XXX XX XXX XX X XX X XX XX X XX X X X X XX X X X 71 | X X X X X XX X XX X X XXX XXXXXX XX X XX X XX XX X XX X X X X XX X X X X 68 | X X X X X XX X XX X X XXX XXXXXX XX X XX X XX XX X XX X X X X XX X X X X 65 | X X X X X XX X XX X X XXX XXXXXX XXX X X XX X XX XXXX XX X X X X XX XX X X X 62 | X X X X X XX X XX XXX XXX XXXXXX XXX X X XX X XX XXXX XX X X X X XX XX X X X X 59 | X XXXX X X XX X XX XXX XXX XXXXXX XXXX X X XX X XX XX XXXX XX X X X X XX XX XX X X X 56 | X XXXX X X XX X XX XXXX XXX XXXXXX XXXX X X XX X XX XX XXXX XX X X X X XX XX XX X X X 53 | X XXXX X X XXX X XX XXXX XXX XXXXXXX XXXX X X X XX X XX XX XXXX XX X X X X XX XX XX X X X 50 | X XXXX X X XXX XX XX XXXX XXX XXXXXXX XXXX X X X XX X XX XX XXXX XX X X X X XX XX XXXX X X X 47 | X XXXX X X XXX XX XXX XXXX X XXX XXXXXXX XXXX X X X XX XXXX XX X XXXXX XX X X X X XX XX XXXX X X XX 44 | X XXXX X X XXX XX XXX XXXX X XXX XXXXXXX XXXX X X X XX XXXX XX X X XXXXX XX X X X X XX XX XXXX XX X XX 41 | X XXXXX X X XXX XX XXXX XXXX X XXX XXXXXXX XXXX X X XX XX XXXX XX X X XXXXX XXXX XXX X XX XX XXXX XX X XX 38 | X XXXXX XX X XXX XX XXXX XXXX X XXX XXXXXXX XXXX X X XXX XX XXXX XX X X XXXXX XXXXXXXXXX XX XXXXXXX XX X XX 35 | X XXXXX XX X XXX X XX XXXX XXXX X XXX XXXXXXXXXXXX X X XXX XX XXXX XXXXX X XXXXX XXXXXXXXXX XXX XXXXXXX XX X XX 32 | X XXXXX XX X XXX X XX X XXXX XXXX X XXX XXXXXXXXXXXX X X XXX XX XXXX XXXXX X XXXXX XXXXXXXXXX XXX XXXXXXXXXX X XX 29 | X XXXXX XX X XXX X XX X XXXX XXXX X XXX XXXXXXXXXXXX XXX XXX XX XXXX XXXXX X XXXXX XXXXXXXXXX XXX XXXXXXXXXX X XX 26 | XXXXXXX XX X XXX X XX X XXXX XXXX X XXX XXXXXXXXXXXX XXX XXX XXX XXXX XXXXXX X XXXXX XXXXXXXXXX XXX XXXXXXXXXX X XX 23 | XXXXXXX XXXX XXX X XX X XXXX XXXXX X XXX XXXXXXXXXXXX XXX XXX XXX XXXXXXXXXXX X XXXXX XXXXXXXXXX XXX XXXXXXXXXX X XXX 20 | XXXXXXX XXXX XXXXX XXXX XXXX XXXXX X XXX XXXXXXXXXXXX XXX XXX XXX XXXXXXXXXXX X XXXXX XXXXXXXXXXX XXX XXXXXXXXXX X XXX 17 |X XXXXXXXXXXXXXXXXXX XXXX XXXX XXXXX X XXXXXXXXXXXXXXXX XXX XXX XXX XXXXXXXXXXX X XXXXX XXXXXXXXXXX XXX XXXXXXXXXXX X XXX 14 |X XXXXXXXXXXXXXXXXXXXXXXXX XXXX XXXXXXX XXXXXXXXXXXXXXXXX XXX XXX XXXXXXXXXXXXXXX X XXXXXX XXXXXXXXXXX XXX XXXXXXXXXXX XXXXXX 11 |X XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX XXXXXXXXXXXXXXXXX XXX XXX XXXXXXXXXXXXXXX X XXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXX XXXXXX 8 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX XXX XXX XXXXXXXXXXXXXXXXX XXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXX 5 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 2 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-- 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 ENDOUT
__MACOSX/a1-code/._test_graph_file_data.sh
a1-code/print_graph_demo.o
a1-code/deltas_main
a1-code/print_graph_demo
a1-code/data/short.actual.txt
20 18 14 10 7 2 3 1 5 9 5 7 7 5 5 5 7 8 3 7 4
__MACOSX/a1-code/data/._short.actual.txt
a1-code/data/names.txt
Mary James Patricia John Jennifer Robert Elizabeth Michael Linda William Barbara David Susan Richard Jessica Joseph Margaret Thomas Sarah Charles Karen Christopher Nancy Daniel Betty Matthew Lisa Anthony Dorothy Donald Sandra Mark Ashley Paul Kimberly Steven Donna Andrew Carol Kenneth Michelle George Emily Joshua Amanda Kevin Helen Brian Melissa Edward Deborah Ronald Stephanie Timothy Laura Jason Rebecca Jeffrey Sharon Ryan Cynthia Gary Kathleen Jacob Amy Nicholas Shirley Eric Anna Stephen Angela Jonathan Ruth Larry Brenda Justin Pamela Scott Nicole Frank Katherine Brandon Virginia Raymond Catherine Gregory Christine Benjamin Samantha Samuel Debra Patrick Janet Alexander Rachel Jack Carolyn Dennis Emma Jerry Maria Tyler Heather Aaron Diane Henry Julie Douglas Joyce Jose Evelyn Peter Frances Adam Joan Zachary Christina Nathan Kelly Walter Victoria Harold Lauren Kyle Martha Carl Judith Arthur Cheryl Gerald Megan Roger Andrea Keith Ann Jeremy Alice Terry Jean Lawrence Doris Sean Jacqueline Christian Kathryn Albert Hannah Joe Olivia Ethan Gloria Austin Marie Jesse Teresa Willie Sara Billy Janice Bryan Julia Bruce Grace Jordan Judy Ralph Theresa Roy Rose Noah Beverly Dylan Denise Eugene Marilyn Wayne Amber Alan Madison Juan Danielle Louis Brittany Russell Diana Gabriel Abigail Randy Jane Philip Natalie Harry Lori Vincent Tiffany Bobby Alexis Johnny Kayla Logan
__MACOSX/a1-code/data/._names.txt
a1-code/data/big.script
put Mary girl put James boy put Patricia girl put John boy put Jennifer girl put Robert boy put Elizabeth girl put Michael boy put Linda girl put William boy put Barbara girl put David boy put Susan girl put Richard boy put Jessica girl put Joseph boy put Margaret girl put Thomas boy put Sarah girl put Charles boy put Karen girl put Christopher boy put Nancy girl put Daniel boy put Betty girl put Matthew boy put Lisa girl put Anthony boy put Dorothy girl put Donald boy put Sandra girl put Mark boy put Ashley girl put Paul boy put Kimberly girl put Steven boy put Donna girl put Andrew boy put Carol girl put Kenneth boy put Michelle girl put George boy put Emily girl put Joshua boy put Amanda girl put Kevin boy put Helen girl put Brian boy put Melissa girl put Edward boy put Deborah girl put Ronald boy put Stephanie girl put Timothy boy put Laura girl put Jason boy put Rebecca girl put Jeffrey boy put Sharon girl put Ryan boy put Cynthia girl put Gary boy put Kathleen girl put Jacob boy put Amy girl put Nicholas boy put Shirley girl put Eric boy put Anna girl put Stephen boy put Angela girl put Jonathan boy put Ruth girl put Larry boy put Brenda girl put Justin boy put Pamela girl put Scott boy put Nicole girl put Frank boy put Katherine girl put Brandon boy put Virginia girl put Raymond boy put Catherine girl put Gregory boy put Christine girl put Benjamin boy put Samantha girl put Samuel boy put Debra girl put Patrick boy put Janet girl put Alexander boy put Rachel girl put Jack boy put Carolyn girl put Dennis boy put Emma girl put Jerry boy put Maria girl put Tyler boy put Heather girl put Aaron boy put Diane girl put Henry boy put Julie girl put Douglas boy put Joyce girl put Jose boy put Evelyn girl put Peter boy put Frances girl put Adam boy put Joan girl put Zachary boy put Christina girl put Nathan boy put Kelly girl put Walter boy put Victoria girl put Harold boy put Lauren girl put Kyle boy put Martha girl put Carl boy put Judith girl put Arthur boy put Cheryl girl put Gerald boy put Megan girl put Roger boy put Andrea girl put Keith boy put Ann girl put Jeremy boy put Alice girl put Terry boy put Jean girl put Lawrence boy put Doris girl put Sean boy put Jacqueline girl put Christian boy put Kathryn girl put Albert boy put Hannah girl put Joe boy put Olivia girl put Ethan boy put Gloria girl put Austin boy put Marie girl put Jesse boy put Teresa girl put Willie boy put Sara girl put Billy boy put Janice girl put Bryan boy put Julia girl put Bruce boy put Grace girl put Jordan boy put Judy girl put Ralph boy put Theresa girl put Roy boy put Rose girl put Noah boy put Beverly girl put Dylan boy put Denise girl put Eugene boy put Marilyn girl put Wayne boy put Amber girl put Alan boy put Madison girl put Juan boy put Danielle girl put Louis boy put Brittany girl put Russell boy put Diana girl put Gabriel boy put Abigail girl put Randy boy put Jane girl put Philip boy put Natalie girl put Harry boy put Lori girl put Vincent boy put Tiffany girl put Bobby boy put Alexis girl put Johnny boy put Kayla girl put Logan boy expand expand expand expand structure save big.hm
__MACOSX/a1-code/data/._big.script
a1-code/data/hash-demo.script~
add Lucas add Mike add Dustin add Will add El print preorder find Mike find Nancy add Nancy print find Max add Max print find Barb add Barb print save stranger.tree clear print add Demigorgon print load stranger.tree preorder add Jim add Joyce print load stranger.tree print quit
__MACOSX/a1-code/data/._hash-demo.script~
a1-code/data/other.script
put Lucas brash put Mike DM put Dustin corny put Will lost print get Dustin get El get Lucas get Jim put El weird put Steve hairy put Nancy torn put Barb ran-away? print hashcode Lucas hashcode Barb structure expand structure save stranger.hm clear print structure put Jim cop put Joyce worried print structure get Dustin get Joyce load stranger.hm print structure get Dustin get Joyce put Will found put Nancy decided put Mike girl-crazy print structure next_prime 10 next_prime 25 expand structure put Jim cop put Joyce worried put Erica capitalist put Barb gone put Max gamer put Robin clever save data/other.hm quit
__MACOSX/a1-code/data/._other.script
a1-code/data/short.txt
20 -2 -4 -4 -3 -5 1 -2 4 4 -4 2 -0 -2 -0 0 2 1 -5 4 -3
__MACOSX/a1-code/data/._short.txt
a1-code/data/other.hm
23 8 El : weird Barb : ran-away? Lucas : brash Dustin : corny Nancy : decided Mike : girl-crazy Steve : hairy Will : found
__MACOSX/a1-code/data/._other.hm
a1-code/data/big.script~
put Mary girl put James boy put Patricia girl put John boy put Jennifer girl put Robert boy put Elizabeth girl put Michael boy put Linda girl put William boy put Barbara girl put David boy put Susan girl put Richard boy put Jessica girl put Joseph boy put Margaret girl put Thomas boy put Sarah girl put Charles boy put Karen girl put Christopher boy put Nancy girl put Daniel boy put Betty girl put Matthew boy put Lisa girl put Anthony boy put Dorothy girl put Donald boy put Sandra girl put Mark boy put Ashley girl put Paul boy put Kimberly girl put Steven boy put Donna girl put Andrew boy put Carol girl put Kenneth boy put Michelle girl put George boy put Emily girl put Joshua boy put Amanda girl put Kevin boy put Helen girl put Brian boy put Melissa girl put Edward boy put Deborah girl put Ronald boy put Stephanie girl put Timothy boy put Laura girl put Jason boy put Rebecca girl put Jeffrey boy put Sharon girl put Ryan boy put Cynthia girl put Gary boy put Kathleen girl put Jacob boy put Amy girl put Nicholas boy put Shirley girl put Eric boy put Anna girl put Stephen boy put Angela girl put Jonathan boy put Ruth girl put Larry boy put Brenda girl put Justin boy put Pamela girl put Scott boy put Nicole girl put Frank boy put Katherine girl put Brandon boy put Virginia girl put Raymond boy put Catherine girl put Gregory boy put Christine girl put Benjamin boy put Samantha girl put Samuel boy put Debra girl put Patrick boy put Janet girl put Alexander boy put Rachel girl put Jack boy put Carolyn girl put Dennis boy put Emma girl put Jerry boy put Maria girl put Tyler boy put Heather girl put Aaron boy put Diane girl put Henry boy put Julie girl put Douglas boy put Joyce girl put Jose boy put Evelyn girl put Peter boy put Frances girl put Adam boy put Joan girl put Zachary boy put Christina girl put Nathan boy put Kelly girl put Walter boy put Victoria girl put Harold boy put Lauren girl put Kyle boy put Martha girl put Carl boy put Judith girl put Arthur boy put Cheryl girl put Gerald boy put Megan girl put Roger boy put Andrea girl put Keith boy put Ann girl put Jeremy boy put Alice girl put Terry boy put Jean girl put Lawrence boy put Doris girl put Sean boy put Jacqueline girl put Christian boy put Kathryn girl put Albert boy put Hannah girl put Joe boy put Olivia girl put Ethan boy put Gloria girl put Austin boy put Marie girl put Jesse boy put Teresa girl put Willie boy put Sara girl put Billy boy put Janice girl put Bryan boy put Julia girl put Bruce boy put Grace girl put Jordan boy put Judy girl put Ralph boy put Theresa girl put Roy boy put Rose girl put Noah boy put Beverly girl put Dylan boy put Denise girl put Eugene boy put Marilyn girl put Wayne boy put Amber girl put Alan boy put Madison girl put Juan boy put Danielle girl put Louis boy put Brittany girl put Russell boy put Diana girl put Gabriel boy put Abigail girl put Randy boy put Jane girl put Philip boy put Natalie girl put Harry boy put Lori girl put Vincent boy put Tiffany girl put Bobby boy put Alexis girl put Johnny boy put Kayla girl put Logan boy
__MACOSX/a1-code/data/._big.script~
a1-code/data/other.script~
put Lucas brash put Mike DM put Dustin corny put Will lost print get Dustin get El get Lucas get Jim put El weird put Steve hairy put Nancy torn put Barb ran-away? print hashcode Lucas hashcode Barb structure expand structure save stranger.hm clear print structure put Jim cop put Joyce worried print structure get Dustin get Joyce load stranger.hm print structure get Dustin get Joyce put Will found put Nancy decided put Mike girl-crazy print structure next_prime 10 next_prime 25 expand structure put Jim cop put Joyce worried put Erica capitalist put Barb gone put Max gamer save data/other.hm quit
__MACOSX/a1-code/data/._other.script~
a1-code/data/names.org
| 1 | James | 4,815,847 | Mary | 3,455,228 | | 2 | John | 4,636,242 | Patricia | 1,565,291 | | 3 | Robert | 4,600,785 | Jennifer | 1,464,890 | | 4 | Michael | 4,307,070 | Elizabeth | 1,449,478 | | 5 | William | 3,689,740 | Linda | 1,447,946 | | 6 | David | 3,553,094 | Barbara | 1,413,261 | | 7 | Richard | 2,496,587 | Susan | 1,106,614 | | 8 | Joseph | 2,398,378 | Jessica | 1,042,177 | | 9 | Thomas | 2,179,445 | Margaret | 1,016,433 | | 10 | Charles | 2,161,838 | Sarah | 997,223 | | 11 | Christopher | 2,010,788 | Karen | 984,334 | | 12 | Daniel | 1,866,234 | Nancy | 976,066 | | 13 | Matthew | 1,571,799 | Betty | 964,130 | | 14 | Anthony | 1,394,023 | Lisa | 964,099 | | 15 | Donald | 1,375,006 | Dorothy | 938,467 | | 16 | Mark | 1,342,682 | Sandra | 872,927 | | 17 | Paul | 1,316,094 | Ashley | 840,595 | | 18 | Steven | 1,276,216 | Kimberly | 833,129 | | 19 | Andrew | 1,241,121 | Donna | 825,431 | | 20 | Kenneth | 1,241,110 | Carol | 810,032 | | 21 | George | 1,225,477 | Michelle | 807,515 | | 22 | Joshua | 1,192,510 | Emily | 806,210 | | 23 | Kevin | 1,162,743 | Amanda | 771,396 | | 24 | Brian | 1,161,909 | Helen | 754,741 | | 25 | Edward | 1,146,548 | Melissa | 750,021 | | 26 | Ronald | 1,073,427 | Deborah | 739,055 | | 27 | Timothy | 1,063,014 | Stephanie | 736,098 | | 28 | Jason | 1,023,728 | Laura | 729,905 | | 29 | Jeffrey | 972,144 | Rebecca | 729,158 | | 30 | Ryan | 916,701 | Sharon | 720,788 | | 31 | Gary | 898,893 | Cynthia | 705,176 | | 32 | Jacob | 892,543 | Kathleen | 696,019 | | 33 | Nicholas | 881,085 | Amy | 677,725 | | 34 | Eric | 870,654 | Shirley | 675,723 | | 35 | Stephen | 841,664 | Anna | 661,870 | | 36 | Jonathan | 826,440 | Angela | 656,616 | | 37 | Larry | 802,374 | Ruth | 633,144 | | 38 | Justin | 769,098 | Brenda | 605,962 | | 39 | Scott | 768,539 | Pamela | 592,689 | | 40 | Frank | 753,168 | Nicole | 583,727 | | 41 | Brandon | 749,649 | Katherine | 581,835 | | 42 | Raymond | 709,374 | Virginia | 576,419 | | 43 | Gregory | 705,003 | Catherine | 571,890 | | 44 | Benjamin | 696,992 | Christine | 568,352 | | 45 | Samuel | 693,954 | Samantha | 564,316 | | 46 | Patrick | 659,877 | Debra | 548,265 | | 47 | Alexander | 635,536 | Janet | 546,524 | | 48 | Jack | 634,008 | Rachel | 545,838 | | 49 | Dennis | 611,555 | Carolyn | 545,185 | | 50 | Jerry | 604,063 | Emma | 529,564 | | 51 | Tyler | 579,411 | Maria | 525,054 | | 52 | Aaron | 562,595 | Heather | 524,166 | | 53 | Henry | 554,003 | Diane | 515,501 | | 54 | Douglas | 551,890 | Julie | 505,291 | | 55 | Jose | 549,130 | Joyce | 503,216 | | 56 | Peter | 545,690 | Evelyn | 474,000 | | 57 | Adam | 539,247 | Frances | 472,830 | | 58 | Zachary | 527,344 | Joan | 472,764 | | 59 | Nathan | 526,730 | Christina | 469,943 | | 60 | Walter | 511,381 | Kelly | 469,887 | | 61 | Harold | 483,142 | Victoria | 465,386 | | 62 | Kyle | 475,524 | Lauren | 464,370 | | 63 | Carl | 450,868 | Martha | 458,322 | | 64 | Arthur | 439,275 | Judith | 449,801 | | 65 | Gerald | 435,320 | Cheryl | 436,876 | | 66 | Roger | 432,480 | Megan | 435,470 | | 67 | Keith | 431,847 | Andrea | 428,133 | | 68 | Jeremy | 431,740 | Ann | 427,855 | | 69 | Terry | 421,381 | Alice | 427,303 | | 70 | Lawrence | 421,149 | Jean | 426,208 | | 71 | Sean | 414,781 | Doris | 421,334 | | 72 | Christian | 405,908 | Jacqueline | 418,546 | | 73 | Albert | 403,891 | Kathryn | 415,843 | | 74 | Joe | 403,754 | Hannah | 410,830 | | 75 | Ethan | 399,554 | Olivia | 410,090 | | 76 | Austin | 398,792 | Gloria | 408,902 | | 77 | Jesse | 389,149 | Marie | 408,571 | | 78 | Willie | 386,441 | Teresa | 405,545 | | 79 | Billy | 380,687 | Sara | 402,845 | | 80 | Bryan | 376,863 | Janice | 401,746 | | 81 | Bruce | 376,688 | Julia | 389,550 | | 82 | Jordan | 363,879 | Grace | 381,487 | | 83 | Ralph | 361,695 | Judy | 378,452 | | 84 | Roy | 354,239 | Theresa | 377,210 | | 85 | Noah | 353,487 | Rose | 372,754 | | 86 | Dylan | 351,480 | Beverly | 372,619 | | 87 | Eugene | 345,853 | Denise | 371,020 | | 88 | Wayne | 343,786 | Marilyn | 369,081 | | 89 | Alan | 342,690 | Amber | 367,827 | | 90 | Juan | 338,106 | Madison | 365,619 | | 91 | Louis | 336,476 | Danielle | 365,276 | | 92 | Russell | 329,810 | Brittany | 357,532 | | 93 | Gabriel | 327,097 | Diana | 354,757 | | 94 | Randy | 326,681 | Abigail | 344,032 | | 95 | Philip | 321,089 | Jane | 343,668 | | 96 | Harry | 320,488 | Natalie | 338,545 | | 97 | Vincent | 319,985 | Lori | 337,999 | | 98 | Bobby | 312,677 | Tiffany | 335,329 | | 99 | Johnny | 307,236 | Alexis | 334,364 | | 100 | Logan | 304,578 | Kayla | 333,475 |
__MACOSX/a1-code/data/._names.org
a1-code/data/wave.int
__MACOSX/a1-code/data/._wave.int
a1-code/data/short.int
__MACOSX/a1-code/data/._short.int
a1-code/data/new.hm
11 10 Will : lost Mike : DM Dustin : corny Steve : hairy Barb : ran-away? Nancy : torn Demigorgon : scary Jim : cop El : weird Lucas : brash
__MACOSX/a1-code/data/._new.hm
a1-code/data/stranger.hm
11 8 Will : lost Mike : DM Dustin : corny Steve : hairy Barb : ran-away? Nancy : torn El : weird Lucas : brash
__MACOSX/a1-code/data/._stranger.hm
a1-code/data/wave.actual.txt
0 2 4 6 8 10 11 13 14 16 17 18 19 19 20 20 20 20 19 19 18 17 16 15 14 12 10 9 7 5 3 1 -1 -3 -5 -7 -9 -11 -12 -14 -15 -16 -17 -18 -19 -20 -20 -20 -20 -20 -19 -19 -18 -17 -15 -14 -13 -11 -9 -7 -6 -4 -2 0 2 4 6 8 10 11 13 14 16 17 18 19 19 20 20 20 20 19 19 18 17 16 15 14 12 10 9 7 5 3 1 -1 -3 -5 -7 -9 -11 -12 -14 -15 -16 -17 -18 -19 -20 -20 -20 -20 -20 -19 -19 -18 -17 -15 -14 -13 -11 -9 -7 -6 -4 -2 0
__MACOSX/a1-code/data/._wave.actual.txt
a1-code/data/wave.txt
0 2 2 2 2 2 1 2 1 2 1 1 1 0 1 0 0 0 -1 0 -1 -1 -1 -1 -1 -2 -2 -1 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -1 -2 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 1 1 2 1 1 2 2 2 1 2 2 2 2 2 2 2 2 1 2 1 2 1 1 1 0 1 0 0 0 -1 0 -1 -1 -1 -1 -1 -2 -2 -1 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -1 -2 -1 -1 -1 -1 -1 -1 0 0 0 0 1 0 1 1 2 1 1 2 2 2 1 2 2 2
__MACOSX/a1-code/data/._wave.txt
a1-code/data/hash-demo.script
put Lucas brash put Mike DM put Dustin corny put Will lost print get Dustin get El get Lucas get Jim put El weird put Steve hairy put Nancy torn put Barb ran-away? print hashcode Lucas hashcode Barb structure expand structure save stranger.hm clear print structure put Jim cop put Joyce worried print structure get Dustin get Joyce load stranger.hm print structure get Dustin get Joyce put Will found put Nancy decided put Mike girl-crazy print structure next_prime 10 next_prime 25 expand structure save data/other.hm quit
__MACOSX/a1-code/data/._hash-demo.script
a1-code/data/wave.4bit
__MACOSX/a1-code/data/._wave.4bit
a1-code/data/big.hm
97 200 Joseph : boy Brenda : girl Jennifer : girl Grace : girl Evelyn : girl Sharon : girl Linda : girl Christopher : boy Ryan : boy Ronald : boy Janice : girl Gerald : boy Amber : girl Frank : boy Rose : girl Elizabeth : girl Sarah : girl Jessica : girl Timothy : boy Karen : girl Diane : girl Ralph : boy Andrea : girl Stephanie : girl Sandra : girl Tiffany : girl Kevin : boy Alice : girl Ann : girl Anna : girl Benjamin : boy Joshua : boy Gary : boy Laura : girl Judy : girl Jean : girl Willie : boy Jordan : boy Logan : boy Carol : girl Jeremy : boy Samantha : girl Tyler : boy Lisa : girl Joe : boy Joyce : girl Jacob : boy Mary : girl Cheryl : girl Carolyn : girl Billy : boy Carl : boy Brian : boy Gloria : girl Jeffrey : boy Sean : boy Paul : boy Amanda : girl Michelle : girl Austin : boy Heather : girl Lawrence : boy Andrew : boy Wayne : boy Pamela : girl Patricia : girl Daniel : boy Douglas : boy Patrick : boy Bryan : boy Denise : girl Lori : girl Abigail : girl Melissa : girl Walter : boy Harold : boy Hannah : girl Mark : boy Julia : girl Justin : boy Alexander : boy Russell : boy Eugene : boy Maria : girl Christian : boy Marilyn : girl Juan : boy Virginia : girl Peter : boy Madison : girl Amy : girl Lauren : girl Rebecca : girl Kathleen : girl Adam : boy Albert : boy Nicole : girl Richard : boy Jerry : boy Cynthia : girl Victoria : girl Stephen : boy Nathan : boy Ruth : girl Olivia : girl Alexis : girl Bruce : boy Sara : girl Rachel : girl George : boy Alan : boy Steven : boy Robert : boy Teresa : girl Joan : girl Johnny : boy Eric : boy Scott : boy Terry : boy Vincent : boy Nancy : girl Kimberly : girl Charles : boy Jason : boy Betty : girl Dylan : boy Susan : girl Randy : boy Jonathan : boy Gregory : boy Roger : boy Philip : boy Gabriel : boy Barbara : girl Zachary : boy Angela : girl Noah : boy Diana : girl Michael : boy Donna : girl Keith : boy Thomas : boy Brittany : girl Christine : girl Christina : girl Edward : boy Debra : girl Catherine : girl Raymond : boy Louis : boy Samuel : boy Natalie : girl Nicholas : boy Janet : girl Kayla : girl Doris : girl James : boy Jacqueline : girl Matthew : boy Kelly : girl Katherine : girl Theresa : girl Judith : girl Ashley : girl Megan : girl Martha : girl William : boy Kathryn : girl Brandon : boy Julie : girl Marie : girl Frances : girl Dennis : boy Helen : girl Beverly : girl Shirley : girl Roy : boy Dorothy : girl Jane : girl Jesse : boy Donald : boy Aaron : boy David : boy Bobby : boy Jack : boy Harry : boy Margaret : girl Emma : girl Arthur : boy Kenneth : boy Ethan : boy Deborah : girl Emily : girl Larry : boy Henry : boy Anthony : boy John : boy Danielle : girl Kyle : boy Jose : boy
__MACOSX/a1-code/data/._big.hm
a1-code/data/short.4bit
__MACOSX/a1-code/data/._short.4bit
__MACOSX/a1-code/._data
a1-code/print_graph.o
a1-code/test_read_deltas.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "deltas.h" int QUIET = 0; // controls if verbose error output is subverted int NTESTS = 0; int NPASS = 0; // Save a file in text delta format, based on code in save_deltas.c void save_text_deltas(char *filename, int *data, int len){ FILE *fout = fopen(filename,"w"); if(fout == NULL){ printf("failure to open output file %s\n",filename); exit(1); } fprintf(fout,"%5d\n",data[0]); // write initial value int total = data[0]; for(int i=1; i<len; i++){ fprintf(fout,"%d\n",data[i]-total); // write delta total = data[i]; } fclose(fout); } // Save a file in binary int delta format, based on code in save_deltas.c void save_int_deltas(char *filename, int *data, int len){ FILE *fout = fopen(filename,"w"); if(fout == NULL){ printf("failure to open output file %s\n",filename); exit(1); } int total = data[0]; fwrite(&total,sizeof(int),1,fout); // write initial value for(int i=1; i<len; i++){ int delta = data[i]-total; fwrite(&delta,sizeof(int),1,fout); // write delta total = data[i]; } fclose(fout); } // Not yet implemented void save_4bit_deltas(char *filename, int *data, int len){ printf("Not implemented: use save_deltas.c for testing\n"); exit(1); } #define MODE_TEXT 1 #define MODE_INT 2 #define MODE_4BIT 3 // Write a test data file the call read_text_deltas() to see if it // works properly void check_deltas(char *testname, int format, int *expect_data, int expect_len) { NTESTS++; char out_fname[512]; int actual_len = -10; int *actual_data = NULL; if(format == MODE_TEXT){ sprintf(out_fname,"test-data/%s_datafile.txt",testname); save_text_deltas(out_fname, expect_data, expect_len); actual_data = read_text_deltas(out_fname, &actual_len); } else if(format == MODE_INT){ sprintf(out_fname,"test-data/%s_datafile.int",testname); save_int_deltas(out_fname, expect_data, expect_len); actual_data = read_int_deltas(out_fname, &actual_len); } // COMMENT this block if not implementing the optional 4bit function // else if(format == MODE_4BIT){ // printf("Not implemented: use save_deltas.c for testing\n"); // exit(1); // } else{ printf("unknown format '%d'\n",format); exit(1); } if(actual_len != expect_len){ printf("FAIL\n"); if(!QUIET){ printf("----------------------------------------\n"); printf("Unexpected length:\n"); printf("EXPECT LENGTH: %d\n",expect_len); printf("ACTUAL LENGTH: %d\n",actual_len); printf("----------------------------------------\n"); } return; // failure } int mismatch = 0; int i; for(i=0; i<expect_len; i++){ if(expect_data[i] != actual_data[i]){ mismatch = 1; break; } } if(mismatch==1){ printf("FAIL\n"); if(!QUIET){ printf("----------------------------------------\n"); printf("Element at index %d is incorrect\n",i); printf("[%2s] %5s %5s\n","i","EXPECT","ACTUAL"); for(int i=0; i<expect_len; i++){ char *diff = ""; if(expect_data[i] != actual_data[i]){ diff = "***"; } printf("[%2d] %5d %5d %s\n", i,expect_data[i],actual_data[i],diff); } printf("----------------------------------------\n"); } return; } free(actual_data); printf("OK\n"); NPASS++; } void check_empty_deltas(char *testname, int format, int create_empty){ NTESTS++; char out_fname[512]; int actual_len = -8; int *actual_data = NULL; sprintf(out_fname,"test-data/%s_datafile.empty",testname); if(create_empty){ FILE *fout = fopen(out_fname,"w"); // create empty file fprintf(fout," "); // single space fclose(fout); } if(format == MODE_TEXT){ actual_data = read_text_deltas(out_fname, &actual_len); } else if(format == MODE_INT){ actual_data = read_int_deltas(out_fname, &actual_len); } // else if(format == MODE_4BIT){ // actual_data = read_4bit_deltas(out_fname, &actual_len); // } else{ printf("unknown format '%d'\n",format); exit(1); } if(actual_data!=NULL || actual_len!=-1){ printf("FAIL\n"); if(!QUIET){ printf("----------------------------------------\n"); printf("Unexpected result for empty/non-existent file:\n"); printf("EXPECT POINTER: (nil)\n"); printf("ACTUAL POINTER: %p\n",actual_data); printf("EXPECT LENGTH: -1\n"); printf("ACTUAL LENGTH: %d\n",actual_len); printf("----------------------------------------\n"); } return; } printf("OK\n"); NPASS++; } typedef struct{ char name[128]; int format; int len; int data[256]; } test_t; #define EMPTY_FILE -4 #define MISSING_FILE -8 int main(int argc, char *argv[]){ if( argc>1 && strcmp(argv[1],"-quiet")==0){ QUIET = 1; } printf("========================================\n"); printf("PROBLEM 1 read_deltas.c tests\n"); // printf("----------------------------------------\n"); test_t tests[] = { {.name="text-5", .format=MODE_TEXT, .len= 5, .data={1,2,3,4,5}}, // {.name="text-10", .format=MODE_TEXT, .len=10, .data={16, 17, 18, 0, 13, 5, 12, 8, 2, 4}}, // {.name="text-32", .format=MODE_TEXT, .len=32, .data={79, 43, 46, 74, 192, 172, 296, 275, 161, 163, 157, 137, 321, 48, 124, 233, 321, 226, 123, 86, 316, 197, 224, 161, 33, 300, 22, 298, 302, 69, 56, 105, }}, {.name="text-128", .format=MODE_TEXT, .len=32, .data={257, 278, 68, 12, 117, 109, 225, 36, 91, 1, 260, 101, 317, 302, 83, 313, 129, 77, 13, 55, 251, 177, 20, 90, 285, 176, 163, 64, 64, 318, 117, 282, 151, 125, 326, 304, 223, 184, 217, 199, 128, 283, 325, 138, 64, 44, 298, 34, 327, 156, 124, 14, 88, 326, 170, 43, 179, 130, 124, 111, 99, 39, 270, 135, 93, 80, 319, 152, 236, 256, 6, 274, 323, 83, 200, 283, 243, 276, 207, 254, 319, 264, 270, 276, 19, 9, 48, 33, 308, 56, 106, 20, 308, 322, 150, 102, 140, 9, 87, 306, 272, 153, 70, 85, 281, 37, 244, 80, 222, 317, 16, 14, 308, 147, 215, 136, 216, 208, 323, 96, 155, 206, 300, 237, 95, 100, 6, 145, }}, {.name="text-one", .format=MODE_TEXT, .len= 1, .data={43}}, {.name="text-empty", .format=MODE_TEXT, .len=EMPTY_FILE}, {.name="text-missing", .format=MODE_TEXT, .len=MISSING_FILE}, {.name="int-5", .format=MODE_INT, .len= 5, .data={1,2,3,4,5}}, // {.name="int-10", .format=MODE_INT, .len=10, .data={16, 17, 18, 0, 13, 5, 12, 8, 2, 4}}, // {.name="int-32", .format=MODE_INT, .len=32, .data={79, 43, 46, 74, 192, 172, 296, 275, 161, 163, 157, 137, 321, 48, 124, 233, 321, 226, 123, 86, 316, 197, 224, 161, 33, 300, 22, 298, 302, 69, 56, 105, }}, {.name="int-128", .format=MODE_INT, .len=32, .data={257, 278, 68, 12, 117, 109, 225, 36, 91, 1, 260, 101, 317, 302, 83, 313, 129, 77, 13, 55, 251, 177, 20, 90, 285, 176, 163, 64, 64, 318, 117, 282, 151, 125, 326, 304, 223, 184, 217, 199, 128, 283, 325, 138, 64, 44, 298, 34, 327, 156, 124, 14, 88, 326, 170, 43, 179, 130, 124, 111, 99, 39, 270, 135, 93, 80, 319, 152, 236, 256, 6, 274, 323, 83, 200, 283, 243, 276, 207, 254, 319, 264, 270, 276, 19, 9, 48, 33, 308, 56, 106, 20, 308, 322, 150, 102, 140, 9, 87, 306, 272, 153, 70, 85, 281, 37, 244, 80, 222, 317, 16, 14, 308, 147, 215, 136, 216, 208, 323, 96, 155, 206, 300, 237, 95, 100, 6, 145, }}, {.name="int-one", .format=MODE_INT, .len= 1, .data={43}}, {.name="int-empty", .format=MODE_INT, .len=EMPTY_FILE}, {.name="int-missing", .format=MODE_INT, .len=MISSING_FILE}, {.name="", .len=-1} }; for(int i=0; tests[i].len != -1; i++){ test_t test = tests[i]; char *format = "???"; if(test.format == MODE_TEXT){ format = "read_text_deltas()"; } else if(test.format == MODE_INT){ format = "read_int_deltas()"; } else if(test.format == MODE_4BIT){ format = "read_4bit_deltas()"; } else{ printf("WTF^M?\n"); exit(1); } printf("TEST %2d %12s : %20s len=%3d : ", i+1,test.name,format,test.len); if(test.len == EMPTY_FILE){ check_empty_deltas(test.name, test.format, 1); } else if(test.len == MISSING_FILE){ check_empty_deltas(test.name, test.format, 0); } else{ check_deltas(test.name, test.format, test.data, test.len); } } printf("========================================\n"); printf("RESULTS: %d / %d tests passed\n",NPASS,NTESTS); return 0; }
__MACOSX/a1-code/._test_read_deltas.c
a1-code/deltas_main.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "deltas.h" int main(int argc, char *argv[]){ if(argc < 3){ printf("usage: %s <format> <filename>\n",argv[0]); printf(" <format> is one of\n"); printf(" text : text ints are in the given filename\n"); printf(" int : binary ints are in the given filename\n"); printf(" 4bit : 4bit binary ints are in the given filename\n"); return 1; } char *format = argv[1]; char *fname = argv[2]; int data_len = -1; int *data_vals = NULL; if( strcmp("text", format)==0 ){ printf("Reading text format\n"); data_vals = read_text_deltas(fname, &data_len); } else if( strcmp("int", format)==0 ){ printf("Reading binary int format\n"); data_vals = read_int_deltas(fname, &data_len); } //else if( strcmp("4bit", format)==0 ){ //printf("Reading 4bit binary int format\n"); //data_vals = read_4bit_deltas(fname, &data_len); //} else{ printf("Unknown format '%s'\n",format); return 1; } printf("data_len: %d\n",data_len); printf("%4s %4s\n","#","read"); for(int i=0; i<data_len; i++){ printf("%4d %4d\n",i,data_vals[i]); } free(data_vals); return 0; }
__MACOSX/a1-code/._deltas_main.c
a1-code/test_check_valgrind.sh
#!/bin/bash # usage: test_check_valgrind.sh 10 "prob name" output_file.txt MAX_POINTS=$1 PROBNAME=$2 VALGOUT=$3 printf '========================================\n' printf "%s\n" "$PROBNAME" # printf "%s\n" '----------------------------------------' points=$MAX_POINTS if ! grep -q 'ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)' $VALGOUT || ! grep -q 'in use at exit: 0 bytes in 0 blocks' $VALGOUT || grep -q 'definitely lost: 0 bytes in 0 blocks' $VALGOUT; then printf "FAIL: Valgrind detected problems\n" cat $VALGOUT | sed 's/RESULTS/RESULTS/g; s/PROBLEM/PROBLEM/g; s/TEST/TEST/g;' points="0" else echo "Valgrind ok" fi printf '========================================\n' printf "RESULTS: %d / %d points for avoiding memory errors\n" "$points" "$MAX_POINTS"
__MACOSX/a1-code/._test_check_valgrind.sh
a1-code/deltas.h
// Header for deltas problem #ifndef DELTAS_H #define DELTAS_H 1 int *read_text_deltas(char *fname, int *len); int *read_int_deltas(char *fname, int *len); int *read_4bit_deltas(char *fname, int *len); void print_graph(int *data, int len, int max_height); #endif