source: vis_dev/glu-2.1/src/sparse/sparse.h @ 8

Last change on this file since 8 was 8, checked in by cecile, 13 years ago

src glu

File size: 5.6 KB
RevLine 
[8]1#ifndef SPARSE_H
2#define SPARSE_H
3
4#include "util.h"
5
6/* hack to fix conflict with libX11.a */
7#define sm_alloc sm_allocate
8#define sm_free sm_free_space
9
10/*
11 *  sparse.h -- sparse matrix package header file
12 */
13
14typedef struct sm_element_struct sm_element;
15typedef struct sm_row_struct sm_row;
16typedef struct sm_col_struct sm_col;
17typedef struct sm_matrix_struct sm_matrix;
18
19
20/*
21 *  sparse matrix element
22 */
23struct sm_element_struct {
24    int row_num;                /* row number of this element */
25    int col_num;                /* column number of this element */
26    sm_element *next_row;       /* next row in this column */
27    sm_element *prev_row;       /* previous row in this column */
28    sm_element *next_col;       /* next column in this row */
29    sm_element *prev_col;       /* previous column in this row */
30    char *user_word;            /* user-defined word */
31};
32
33
34/*
35 *  row header
36 */
37struct sm_row_struct {
38    int row_num;                /* the row number */
39    int length;                 /* number of elements in this row */
40    int flag;                   /* user-defined word */
41    sm_element *first_col;      /* first element in this row */
42    sm_element *last_col;       /* last element in this row */
43    sm_row *next_row;           /* next row (in sm_matrix linked list) */
44    sm_row *prev_row;           /* previous row (in sm_matrix linked list) */
45    char *user_word;            /* user-defined word */
46};
47
48
49/*
50 *  column header
51 */
52struct sm_col_struct {
53    int col_num;                /* the column number */
54    int length;                 /* number of elements in this column */
55    int flag;                   /* user-defined word */
56    sm_element *first_row;      /* first element in this column */
57    sm_element *last_row;       /* last element in this column */
58    sm_col *next_col;           /* next column (in sm_matrix linked list) */
59    sm_col *prev_col;           /* prev column (in sm_matrix linked list) */
60    char *user_word;            /* user-defined word */
61};
62
63
64/*
65 *  A sparse matrix
66 */
67struct sm_matrix_struct {
68    sm_row **rows;              /* pointer to row headers (by row #) */
69    int rows_size;              /* alloc'ed size of above array */
70    sm_col **cols;              /* pointer to column headers (by col #) */
71    int cols_size;              /* alloc'ed size of above array */
72    sm_row *first_row;          /* first row (linked list of all rows) */
73    sm_row *last_row;           /* last row (linked list of all rows) */
74    int nrows;                  /* number of rows */
75    sm_col *first_col;          /* first column (linked list of columns) */
76    sm_col *last_col;           /* last column (linked list of columns) */
77    int ncols;                  /* number of columns */
78    char *user_word;            /* user-defined word */
79};
80
81
82#define sm_get_col(A, colnum)   \
83    (((colnum) >= 0 && (colnum) < (A)->cols_size) ? \
84        (A)->cols[colnum] : (sm_col *) 0)
85
86#define sm_get_row(A, rownum)   \
87    (((rownum) >= 0 && (rownum) < (A)->rows_size) ? \
88        (A)->rows[rownum] : (sm_row *) 0)
89
90#define sm_foreach_row(A, prow) \
91        for(prow = A->first_row; prow != 0; prow = prow->next_row)
92
93#define sm_foreach_col(A, pcol) \
94        for(pcol = A->first_col; pcol != 0; pcol = pcol->next_col)
95
96#define sm_foreach_row_element(prow, p) \
97        for(p = (prow == 0) ? 0 : prow->first_col; p != 0; p = p->next_col)
98
99#define sm_foreach_col_element(pcol, p) \
100        for(p = (pcol == 0) ? 0 : pcol->first_row; p != 0; p = p->next_row)
101
102#define sm_put(x, val) \
103        (x->user_word = (char *) val)
104
105#define sm_get(type, x) \
106        ((type) (x->user_word))
107
108EXTERN sm_matrix *sm_allocate ARGS((void));
109EXTERN sm_matrix *sm_alloc_size ARGS((int, int));
110EXTERN void sm_free_space ARGS((sm_matrix *));
111EXTERN sm_matrix *sm_dup ARGS((sm_matrix *));
112EXTERN void sm_resize ARGS((sm_matrix *, int, int));
113EXTERN sm_element *sm_insert ARGS((sm_matrix *, int, int));
114EXTERN sm_element *sm_find ARGS((sm_matrix *, int, int));
115EXTERN void sm_remove ARGS((sm_matrix *, int, int));
116EXTERN void sm_remove_element ARGS((sm_matrix *, sm_element *));
117EXTERN void sm_delrow ARGS((sm_matrix *, int));
118EXTERN void sm_delcol ARGS((sm_matrix *, int));
119EXTERN void sm_copy_row ARGS((sm_matrix *, int, sm_row *));
120EXTERN void sm_copy_col ARGS((sm_matrix *, int, sm_col *));
121EXTERN sm_row *sm_longest_row ARGS((sm_matrix *));
122EXTERN sm_col *sm_longest_col ARGS((sm_matrix *));
123EXTERN int sm_num_elements ARGS((sm_matrix *));
124EXTERN int sm_read ARGS((FILE *, sm_matrix **));
125EXTERN int sm_read_compressed ARGS((FILE *, sm_matrix **));
126EXTERN void sm_write ARGS((FILE *, sm_matrix *));
127EXTERN void sm_print ARGS((FILE *, sm_matrix *));
128EXTERN void sm_dump ARGS((sm_matrix *, char *, int));
129EXTERN void sm_cleanup ARGS((void));
130
131EXTERN sm_col *sm_col_alloc ARGS((void));
132EXTERN void sm_col_free ARGS((sm_col *));
133EXTERN sm_col *sm_col_dup ARGS((sm_col *));
134EXTERN sm_element *sm_col_insert ARGS((sm_col *, int));
135EXTERN void sm_col_remove ARGS((sm_col *, int));
136EXTERN sm_element *sm_col_find ARGS((sm_col *, int));
137EXTERN int sm_col_contains ARGS((sm_col *, sm_col *));
138EXTERN int sm_col_intersects ARGS((sm_col *, sm_col *));
139EXTERN int sm_col_compare ARGS((sm_col *, sm_col *));
140EXTERN sm_col *sm_col_and ARGS((sm_col *, sm_col *));
141EXTERN int sm_col_hash ARGS((sm_col *, int));
142EXTERN void sm_col_remove_element ARGS((sm_col *, sm_element *));
143EXTERN void sm_col_print ARGS((FILE *, sm_col *));
144
145EXTERN sm_row *sm_row_alloc ARGS((void));
146EXTERN void sm_row_free ARGS((sm_row *));
147EXTERN sm_row *sm_row_dup ARGS((sm_row *));
148EXTERN sm_element *sm_row_insert ARGS((sm_row *, int));
149EXTERN void sm_row_remove ARGS((sm_row *, int));
150EXTERN sm_element *sm_row_find ARGS((sm_row *, int));
151EXTERN int sm_row_contains ARGS((sm_row *, sm_row *));
152EXTERN int sm_row_intersects ARGS((sm_row *, sm_row *));
153EXTERN int sm_row_compare ARGS((sm_row *, sm_row *));
154EXTERN sm_row *sm_row_and ARGS((sm_row *, sm_row *));
155EXTERN int sm_row_hash ARGS((sm_row *, int));
156EXTERN void sm_row_remove_element ARGS((sm_row *, sm_element *));
157EXTERN void sm_row_print ARGS((FILE *, sm_row *));
158
159#endif
Note: See TracBrowser for help on using the repository browser.