66 if (A->first_row != 0) {
67 for(prow = A->first_row; prow != 0; prow = prow->
next_row) {
69 prow->
last_col->next_col = sm_element_freelist;
74 A->last_row->next_row = sm_row_freelist;
75 sm_row_freelist = A->first_row;
78 A->
last_col->next_col = sm_col_freelist;
79 sm_col_freelist = A->first_col;
82 register sm_row *prow, *pnext_row;
83 register sm_col *pcol, *pnext_col;
85 for(prow = A->first_row; prow != 0; prow = pnext_row) {
89 for(pcol = A->first_col; pcol != 0; pcol = pnext_col) {
112 if (A->last_row != 0) {
114 for(prow = A->first_row; prow != 0; prow = prow->
next_row) {
115 for(p = prow->
first_col; p != 0; p = p->next_col) {
116 (void)
sm_insert(B, p->row_num, p->col_num);
129 register int i, new_size;
131 if (row >= A->rows_size) {
132 new_size =
MAX(A->rows_size*2, row+1);
134 for(i = A->rows_size; i < new_size; i++) {
137 A->rows_size = new_size;
140 if (col >= A->cols_size) {
141 new_size =
MAX(A->cols_size*2, col+1);
143 for(i = A->cols_size; i < new_size; i++) {
146 A->cols_size = new_size;
157 register
int row, col;
164 if (row >= A->rows_size || col >= A->cols_size) {
172 sorted_insert(
sm_row, A->first_row, A->last_row, A->nrows,
173 next_row, prev_row, row_num, row, prow);
180 sorted_insert(
sm_col, A->first_col, A->last_col, A->ncols,
181 next_col, prev_col, col_num, col, pcol);
186 save_element = element;
190 prow->
length, next_col, prev_col, col_num, col, element);
193 if (element == save_element) {
195 pcol->
length, next_row, prev_row, row_num, row, element);
252 next_col, prev_col, prow->
length);
262 next_row, prev_row, pcol->
length);
284 for(p = prow->
first_col; p != 0; p = pnext) {
300 next_row, prev_row, A->nrows);
318 for(p = pcol->
first_row; p != 0; p = pnext) {
334 next_col, prev_col, A->ncols);
348 for(p = prow->
first_col; p != 0; p = p->next_col) {
349 (void)
sm_insert(dest, dest_row, p->col_num);
362 for(p = pcol->
first_row; p != 0; p = p->next_row) {
363 (void)
sm_insert(dest, dest_col, p->row_num);
372 register sm_row *large_row, *prow;
373 register int max_length;
377 for(prow = A->first_row; prow != 0; prow = prow->
next_row) {
378 if (prow->
length > max_length) {
379 max_length = prow->
length;
391 register sm_col *large_col, *pcol;
392 register int max_length;
396 for(pcol = A->first_col; pcol != 0; pcol = pcol->
next_col) {
397 if (pcol->
length > max_length) {
398 max_length = pcol->
length;
428 err = fscanf(fp,
"%d %d", &i, &j);
431 }
else if (err != 2) {
445 int i, j, k, nrows, ncols;
449 if (fscanf(fp,
"%d %d", &nrows, &ncols) != 2) {
454 for(i = 0; i < nrows; i++) {
455 if (fscanf(fp,
"%lx", &x) != 1) {
458 for(j = 0; j < ncols; j += 32) {
459 if (fscanf(fp,
"%lx", &x) != 1) {
462 for(k = j; x != 0; x >>= 1, k++) {
482 for(p = prow->
first_col; p != 0; p = p->next_col) {
483 (void) fprintf(fp,
"%d %d\n", p->row_num, p->col_num);
498 (void) fprintf(fp,
" ");
500 (void) fprintf(fp,
"%d", (pcol->
col_num / 100)%10);
506 (void) fprintf(fp,
" ");
508 (void) fprintf(fp,
"%d", (pcol->
col_num / 10)%10);
513 (void) fprintf(fp,
" ");
515 (void) fprintf(fp,
"%d", pcol->
col_num % 10);
519 (void) fprintf(fp,
" ");
521 (void) fprintf(fp,
"-");
526 (void) fprintf(fp,
"%3d:", prow->
row_num);
545 (void) fprintf(fp,
"%s %d rows by %d cols\n", s, A->nrows, A->ncols);
546 if (A->nrows < max) {
554 #ifdef FAST_AND_LOOSE
556 register sm_row *prow, *pnextrow;
557 register sm_col *pcol, *pnextcol;
559 for(p = sm_element_freelist; p != 0; p = pnext) {
563 sm_element_freelist = 0;
565 for(prow = sm_row_freelist; prow != 0; prow = pnextrow) {
571 for(pcol = sm_col_freelist; pcol != 0; pcol = pnextcol) {
void sm_copy_row(sm_matrix *dest, int dest_row, sm_row *prow)
void sm_row_remove_element(sm_row *prow, sm_element *p)
sm_row * sm_longest_row(sm_matrix *A)
sm_matrix * sm_dup(sm_matrix *A)
void sm_remove(sm_matrix *A, int rownum, int colnum)
#define sm_element_free(e)
#define sm_foreach_row(A, prow)
sm_element * sm_find(sm_matrix *A, int rownum, int colnum)
void sm_remove_element(sm_matrix *A, sm_element *p)
int sm_num_elements(sm_matrix *A)
void sm_delrow(sm_matrix *A, int i)
#define dll_unlink(p, first, last, next, prev, count)
#define sm_get_row(A, rownum)
sm_matrix * sm_alloc_size(int row, int col)
sm_element * sm_col_find(sm_col *pcol, int row)
#define ABC_NAMESPACE_IMPL_END
sm_element * sm_row_find(sm_row *prow, int col)
#define sm_get_col(A, colnum)
void sm_free(sm_matrix *A)
int sm_read(FILE *fp, sm_matrix **A)
void sm_copy_col(sm_matrix *dest, int dest_col, sm_col *pcol)
int sm_read_compressed(FILE *fp, sm_matrix **A)
sm_element * sm_insert(sm_matrix *A, int row, int col)
#define REALLOC(type, obj, num)
ABC_NAMESPACE_IMPL_START sm_matrix * sm_alloc()
#define ABC_NAMESPACE_IMPL_START
void sm_col_remove_element(sm_col *pcol, sm_element *p)
void sm_print(FILE *fp, sm_matrix *A)
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
#define sm_element_alloc(newobj)
void sm_dump(sm_matrix *A, char *s, int max)
ABC_NAMESPACE_IMPL_START sm_row * sm_row_alloc()
void sm_row_free(sm_row *prow)
void sm_write(FILE *fp, sm_matrix *A)
void sm_col_free(sm_col *pcol)
void sm_delcol(sm_matrix *A, int i)
void sm_resize(sm_matrix *A, int row, int col)
sm_col * sm_longest_col(sm_matrix *A)
ABC_NAMESPACE_IMPL_START sm_col * sm_col_alloc()