/**
+ * Author: Daniel Grund
+ * Date: 07.04.2005
+ * Copyright: (c) Universitaet Karlsruhe
+ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+
* Sparse matrix storage with linked lists for rows and cols.
- * I did not need floats, so this is all integer.
- * @author Daniel Grund
- * @date 07.04.2005
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
-#include <alloca.h>
#include <assert.h>
#include "sp_matrix.h"
#include "list.h"
/**
* Allocates space for @p count entries in the rows array and
- * intitializes all entries from @p start to the end.
+ * inititializes all entries from @p start to the end.
*/
static INLINE void _m_alloc_row(sp_matrix_t *m, int start, int count) {
int p;
/**
* Allocates space for @p count entries in the cols array and
- * intitializes all entries from @p start to the end.
+ * inititializes all entries from @p start to the end.
*/
static INLINE void _m_alloc_col(sp_matrix_t *m, int start, int count) {
int p;
free(m);
}
-void matrix_set(sp_matrix_t *m, int row, int col, int val) {
+void matrix_set(sp_matrix_t *m, int row, int col, matrix_type val) {
matrix_elem_t *me = NULL;
entry_t *entr;
struct list_head *leftof, *above;
m->entries++;
}
-int matrix_get(const sp_matrix_t *m, int row, int col) {
+matrix_type matrix_get(const sp_matrix_t *m, int row, int col) {
struct list_head *dummy;
matrix_elem_t *me;
/* kill all double-entries (Mij and Mji are set) */
matrix_foreach(m, e) {
+ int t_val;
+
assert(e->row != e->col && "Root has itself as arg. Ok. But the arg (=root) will alwazs have the same color as root");
- int t_val = matrix_get(m, e->col, e->row);
+ t_val = matrix_get(m, e->col, e->row);
if (t_val) {
matrix_set(m, e->col, e->row, 0);
matrix_set(m, e->row, e->col, e->val + t_val);
matrix_foreach_in_row(m, i, e) {
for (o=last_idx+1; o<e->col; ++o)
fprintf(out, "0");
- fprintf(out, "%d", factor*e->val);
+ fprintf(out, "%f", factor*e->val);
last_idx = e->col;
}
for (o=last_idx+1; o<=m->maxcol; ++o)