aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2012-11-07 22:14:41 +0100
committerMattias Andrée <maandree@operamail.com>2012-11-07 22:14:41 +0100
commita1aed2eba016138c473ffb6a06239c4bdc0b0960 (patch)
tree5596984c385a9a7ceb8210914fffa15f14d3c892
parenttypo (diff)
downloadhungarian-algorithm-n3-a1aed2eba016138c473ffb6a06239c4bdc0b0960.tar.gz
hungarian-algorithm-n3-a1aed2eba016138c473ffb6a06239c4bdc0b0960.tar.bz2
hungarian-algorithm-n3-a1aed2eba016138c473ffb6a06239c4bdc0b0960.tar.xz
unrevert
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--hungarian.c34
2 files changed, 34 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 79c80f6..75eade0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
all:
- gcc -o "hungarian"{,.c}
+ gcc -g -o "hungarian"{,.c}
nodebug:
gcc -o "hungarian"{,.c}
diff --git a/hungarian.c b/hungarian.c
index fc44b64..5c82db3 100644
--- a/hungarian.c
+++ b/hungarian.c
@@ -183,7 +183,15 @@ int main(int argc, char** argv)
cell sum = 0;
for (i = 0; i < n; i++)
+ {
sum += *(*(t + *(*(assignment + i) + 0)) + *(*(assignment + i) + 1));
+ free(*(assignment + i));
+ free(*(table + i));
+ free(*(t + i));
+ }
+ free(assignment);
+ free(table);
+ free(t);
printf("\n\nSum: %li\n\n", sum);
return 0;
@@ -214,7 +222,11 @@ void print(cell** t, long n, long m, long** assignment)
printf("%5li%s\e[m ", (cell)(*(*(t + i) + j)), (*(*(assigned + i) + j) ? "^" : " "));
}
printf("\n\n");
+
+ free(*(assigned + i));
}
+
+ free(assigned);
}
@@ -274,13 +286,27 @@ long** kuhn_match(cell** table, long n, long m)
}
for (i = n; i < m; i++)
*(colCovered + i) = false;
+ free(prime);
break;
}
kuhn_addAndSubtract(table, rowCovered, colCovered, n, m);
}
}
- return kuhn_assign(marks, n, m);
+ free(rowCovered);
+ free(colCovered);
+ free(altRow);
+ free(altCol);
+ free(rowPrimes);
+ free(colMarks);
+
+ long** rc = kuhn_assign(marks, n, m);
+
+ for (i = 0; i < n; i++)
+ free(*(marks + i));
+ free(marks);
+
+ return rc;
}
@@ -353,6 +379,8 @@ byte** kuhn_mark(cell** t, long n, long m)
*(colCovered + j) = true;
}
+ free(rowCovered);
+ free(colCovered);
return marks;
}
@@ -470,6 +498,10 @@ long* kuhn_findPrime(cell** t, byte** marks, boolean* rowCovered, boolean* colCo
long* rc = new_longs(2);
*rc = row;
*(rc + 1) = col;
+ free(zeroes.limbs);
+ free(zeroes.first);
+ free(zeroes.next);
+ free(zeroes.prev);
return rc;
}
}