Implement binary emitter for fpush.
[libfirm] / ir / adt / hungarian.c
index e6a74ff..26c4fe5 100644 (file)
@@ -49,7 +49,6 @@ struct _hungarian_problem_t {
        int      num_rows;          /**< number of rows */
        int      num_cols;          /**< number of columns */
        int      **cost;            /**< the cost matrix */
-       int      width;             /**< the width for cost matrix dumper */
        int      max_cost;          /**< the maximal costs in the matrix */
        int      match_type;        /**< PERFECT or NORMAL matching */
        bitset_t *missing_left;     /**< left side nodes having no edge to the right side */
@@ -58,12 +57,6 @@ struct _hungarian_problem_t {
        DEBUG_ONLY(firm_dbg_module_t *dbg);
 };
 
-static INLINE void *get_init_mem(struct obstack *obst, long sz) {
-       void *p = obstack_alloc(obst, sz);
-       memset(p, 0, sz);
-       return p;
-}
-
 static void hungarian_dump_f(FILE *f, int **C, int rows, int cols, int width) {
        int i, j;
 
@@ -78,14 +71,14 @@ static void hungarian_dump_f(FILE *f, int **C, int rows, int cols, int width) {
        fprintf(f, "\n");
 }
 
-void hungarian_print_costmatrix(hungarian_problem_t *p) {
-       hungarian_dump_f(stderr, p->cost, p->num_rows, p->num_cols, p->width);
+void hungarian_print_cost_matrix(hungarian_problem_t *p, int width) {
+       hungarian_dump_f(stderr, p->cost, p->num_rows, p->num_cols, width);
 }
 
 /**
  * Create the object and allocate memory for the data structures.
  */
-hungarian_problem_t *hungarian_new(int rows, int cols, int width, int match_type) {
+hungarian_problem_t *hungarian_new(int rows, int cols, int match_type) {
        int i;
        hungarian_problem_t *p = XMALLOCZ(hungarian_problem_t);
 
@@ -102,7 +95,6 @@ hungarian_problem_t *hungarian_new(int rows, int cols, int width, int match_type
 
        p->num_rows   = rows;
        p->num_cols   = cols;
-       p->width      = width;
        p->match_type = match_type;
 
        /*
@@ -118,9 +110,9 @@ hungarian_problem_t *hungarian_new(int rows, int cols, int width, int match_type
        }
 
        /* allocate space for cost matrix */
-       p->cost = (int **)get_init_mem(&p->obst, rows * sizeof(p->cost[0]));
+       p->cost = OALLOCNZ(&p->obst, int*, rows);
        for (i = 0; i < p->num_rows; i++)
-               p->cost[i] = (int *)get_init_mem(&p->obst, cols * sizeof(p->cost[0][0]));
+               p->cost[i] = OALLOCNZ(&p->obst, int, cols);
 
        return p;
 }
@@ -449,7 +441,8 @@ done:
        xfree(unchosen_row);
        xfree(col_mate);
 
-       *final_cost = cost;
+       if (final_cost != NULL)
+               *final_cost = cost;
 
        return 0;
 }