From 2d41e9010f3d6ad506d29a80669174367ef0ba32 Mon Sep 17 00:00:00 2001 From: Manuel Bucher <manuel.bucher@hu-berlin.de> Date: Sun, 24 Jun 2018 19:01:14 +0200 Subject: [PATCH] code cleanup --- check | 5 +++++ loesung.c | 11 +++++------ visualize.py | 11 +++++++---- visualize_result.py | 11 +++++++---- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/check b/check index 2a419bf..95d28ac 100755 --- a/check +++ b/check @@ -1,2 +1,7 @@ #!/bin/bash +if [ $# -eq 0 ]; then + echo "Usage: check <input file>" + exit 0 +fi + ./loesung <$1 | ./check_result $1 diff --git a/loesung.c b/loesung.c index 89de1cb..ea40b12 100755 --- a/loesung.c +++ b/loesung.c @@ -55,7 +55,7 @@ typedef struct Field { uint32_t num_odd; } Field; -// returns 0 if successful, nonzero if failed +// gibt 0 zurueck, wenn Initialisierung Erfolgreich durchgelaufen ist int field_init(Field *this) { memset(this, 0, sizeof(Field)); this->tiles = malloc(sizeof(Tile)); @@ -64,7 +64,8 @@ int field_init(Field *this) { return this->tiles == 0; } -// if an error occurs, all memory get freed +// fuegt p_tile zum dynamischen Array hinzu, im Fehlerfall muss immernoch +// der reservierte Speicher speicher freigegeben werden int field_push(Field *this, Tile *p_tile) { if (this->size == this->num_tiles) { if (this->size == 1u<<31) return 1; // catch overflow @@ -196,10 +197,8 @@ int field_neighbours(Field *this) { top = begin_line; begin_line = cur; // neue Zeile } - // ermitteln der Zeilen-Beziehung - if (begin_line != 1 && t[top].x < t[begin_line].x - 1) { - // Zeilensprung => Warten bis zur naechsten Zeile angekommen - } else if (t[top].x == t[cur].x - 1) { + // ermitteln der Zeilen-Beziehung, nur wenn obere Zeile ein ueber der aktuellen ist + if (t[top].x == t[cur].x - 1) { // finden, ob paar nach oben existiert O(n) fuer alle Nachbarn nach oben/unten. for(;t[top].y < t[cur].y && top < begin_line; top++); diff --git a/visualize.py b/visualize.py index 1a4093e..e38d8ee 100755 --- a/visualize.py +++ b/visualize.py @@ -2,9 +2,12 @@ import sys import matplotlib.pyplot as plt import numpy as np -inp = sys.argv[1] -def load(): +def main(): + if len(sys.argv) != 1: + print("Usage: visualize <input file>") + return + inp = sys.argv[1] f = open(inp) xs = [] ys = [] @@ -16,6 +19,6 @@ def load(): plt.scatter(xs, ys, marker="s") plt.show() -while True: - load() +if __name__ == "__main__": + main() diff --git a/visualize_result.py b/visualize_result.py index b4000aa..5ae4701 100755 --- a/visualize_result.py +++ b/visualize_result.py @@ -2,9 +2,12 @@ import sys import matplotlib.pyplot as plt import numpy as np -inp = sys.argv[1] -def load(): +def main(): + if len(sys.argv) != 1: + print("Usage: visualize <output file>") + return + inp = sys.argv[1] f = open(inp) xs = [] ys = [] @@ -19,6 +22,6 @@ def load(): plt.plot(xs, ys, marker="s") plt.show() -while True: - load() +if __name__ == "__main__": + main() -- GitLab