src/sparse/cols.c File Reference

#include <stdio.h>
#include "sparse_int.h"
Include dependency graph for cols.c:

Go to the source code of this file.

Functions

sm_colsm_col_alloc (void)
void sm_col_free (sm_col *pcol)
sm_colsm_col_dup (sm_col *pcol)
sm_elementsm_col_insert (sm_col *pcol, int row)
void sm_col_remove (sm_col *pcol, int row)
sm_elementsm_col_find (sm_col *pcol, int row)
int sm_col_contains (sm_col *p1, sm_col *p2)
int sm_col_intersects (sm_col *p1, sm_col *p2)
int sm_col_compare (sm_col *p1, sm_col *p2)
sm_colsm_col_and (sm_col *p1, sm_col *p2)
int sm_col_hash (sm_col *pcol, int modulus)
void sm_col_remove_element (sm_col *pcol, sm_element *p)
void sm_col_print (FILE *fp, sm_col *pcol)

Function Documentation

sm_col* sm_col_alloc ( void   ) 

Definition at line 13 of file cols.c.

00014 {
00015     register sm_col *pcol;
00016 
00017 #ifdef FAST_AND_LOOSE
00018     if (sm_col_freelist == NIL(sm_col)) {
00019         pcol = ALLOC(sm_col, 1);
00020     } else {
00021         pcol = sm_col_freelist;
00022         sm_col_freelist = pcol->next_col;
00023     }
00024 #else
00025     pcol = ALLOC(sm_col, 1);
00026 #endif
00027 
00028     pcol->col_num = 0;
00029     pcol->length = 0;
00030     pcol->first_row = pcol->last_row = NIL(sm_element);
00031     pcol->next_col = pcol->prev_col = NIL(sm_col);
00032     pcol->flag = 0;
00033     pcol->user_word = NIL(char);                /* for our user ... */
00034     return pcol;
00035 }

sm_col* sm_col_and ( sm_col p1,
sm_col p2 
)

Definition at line 228 of file cols.c.

00229 {
00230     register sm_element *q1, *q2;
00231     register sm_col *result;
00232 
00233     result = sm_col_alloc();
00234     q1 = p1->first_row;
00235     q2 = p2->first_row;
00236     if (q1 == 0 || q2 == 0) return result;
00237     for(;;) {
00238         if (q1->row_num < q2->row_num) {
00239             if ((q1 = q1->next_row) == 0) {
00240                 return result;
00241             }
00242         } else if (q1->row_num > q2->row_num) {
00243             if ((q2 = q2->next_row) == 0) {
00244                 return result;
00245             }
00246         } else {
00247             (void) sm_col_insert(result, q1->row_num);
00248             if ((q1 = q1->next_row) == 0) {
00249                 return result;
00250             }
00251             if ((q2 = q2->next_row) == 0) {
00252                 return result;
00253             }
00254         }
00255     }
00256 }

int sm_col_compare ( sm_col p1,
sm_col p2 
)

Definition at line 200 of file cols.c.

00201 {
00202     register sm_element *q1, *q2;
00203 
00204     q1 = p1->first_row;
00205     q2 = p2->first_row;
00206     while(q1 != 0 && q2 != 0) {
00207         if (q1->row_num != q2->row_num) {
00208             return q1->row_num - q2->row_num;
00209         }
00210         q1 = q1->next_row;
00211         q2 = q2->next_row;
00212     }
00213 
00214     if (q1 != 0) {
00215         return 1;
00216     } else if (q2 != 0) {
00217         return -1;
00218     } else {
00219         return 0;
00220     }
00221 }

int sm_col_contains ( sm_col p1,
sm_col p2 
)

Definition at line 149 of file cols.c.

00150 {
00151     register sm_element *q1, *q2;
00152 
00153     q1 = p1->first_row;
00154     q2 = p2->first_row;
00155     while (q1 != 0) {
00156         if (q2 == 0 || q1->row_num < q2->row_num) {
00157             return 0;
00158         } else if (q1->row_num == q2->row_num) {
00159             q1 = q1->next_row;
00160             q2 = q2->next_row;
00161         } else {
00162             q2 = q2->next_row;
00163         }
00164     }
00165     return 1;
00166 }

sm_col* sm_col_dup ( sm_col pcol  ) 

Definition at line 73 of file cols.c.

00074 {
00075     register sm_col *pnew;
00076     register sm_element *p;
00077 
00078     pnew = sm_col_alloc();
00079     for(p = pcol->first_row; p != 0; p = p->next_row) {
00080         (void) sm_col_insert(pnew, p->row_num);
00081     }
00082     return pnew;
00083 }

sm_element* sm_col_find ( sm_col pcol,
int  row 
)

Definition at line 132 of file cols.c.

00133 {
00134     register sm_element *p;
00135 
00136     for(p = pcol->first_row; p != 0 && p->row_num < row; p = p->next_row)
00137         ;
00138     if (p != 0 && p->row_num == row) {
00139         return p;
00140     } else {
00141         return NIL(sm_element);
00142     }
00143 }

void sm_col_free ( sm_col pcol  ) 

Definition at line 45 of file cols.c.

00046 {
00047 #if defined(FAST_AND_LOOSE) && ! defined(COLS)
00048     if (pcol->first_row != NIL(sm_element)) {
00049         /* Add the linked list of col items to the free list */
00050         pcol->last_row->next_row = sm_element_freelist;
00051         sm_element_freelist = pcol->first_row;
00052     }
00053 
00054     /* Add the col to the free list of cols */
00055     pcol->next_col = sm_col_freelist;
00056     sm_col_freelist = pcol;
00057 #else
00058     register sm_element *p, *pnext;
00059 
00060     for(p = pcol->first_row; p != 0; p = pnext) {
00061         pnext = p->next_row;
00062         sm_element_free(p);
00063     }
00064     FREE(pcol);
00065 #endif
00066 }

int sm_col_hash ( sm_col pcol,
int  modulus 
)

Definition at line 259 of file cols.c.

00260 {
00261     register int sum;
00262     register sm_element *p;
00263 
00264     sum = 0;
00265     for(p = pcol->first_row; p != 0; p = p->next_row) {
00266         sum = (sum*17 + p->row_num) % modulus;
00267     }
00268     return sum;
00269 }

sm_element* sm_col_insert ( sm_col pcol,
int  row 
)

Definition at line 90 of file cols.c.

00091 {
00092     register sm_element *test, *element;
00093 
00094     /* get a new item, save its address */
00095     sm_element_alloc(element);
00096     test = element;
00097     sorted_insert(sm_element, pcol->first_row, pcol->last_row, pcol->length, 
00098                     next_row, prev_row, row_num, row, test);
00099 
00100     /* if item was not used, free it */
00101     if (element != test) {
00102         sm_element_free(element);
00103     }
00104 
00105     /* either way, return the current new value */
00106     return test;
00107 }

int sm_col_intersects ( sm_col p1,
sm_col p2 
)

Definition at line 173 of file cols.c.

00174 {
00175     register sm_element *q1, *q2;
00176 
00177     q1 = p1->first_row;
00178     q2 = p2->first_row;
00179     if (q1 == 0 || q2 == 0) return 0;
00180     for(;;) {
00181         if (q1->row_num < q2->row_num) {
00182             if ((q1 = q1->next_row) == 0) {
00183                 return 0;
00184             }
00185         } else if (q1->row_num > q2->row_num) {
00186             if ((q2 = q2->next_row) == 0) {
00187                 return 0;
00188             }
00189         } else {
00190             return 1;
00191         }
00192     }
00193 }

void sm_col_print ( FILE *  fp,
sm_col pcol 
)

Definition at line 284 of file cols.c.

00285 {
00286     sm_element *p;
00287 
00288     for(p = pcol->first_row; p != 0; p = p->next_row) {
00289         (void) fprintf(fp, " %d", p->row_num);
00290     }
00291 }

void sm_col_remove ( sm_col pcol,
int  row 
)

Definition at line 114 of file cols.c.

00115 {
00116     register sm_element *p;
00117 
00118     for(p = pcol->first_row; p != 0 && p->row_num < row; p = p->next_row)
00119         ;
00120     if (p != 0 && p->row_num == row) {
00121         dll_unlink(p, pcol->first_row, pcol->last_row, 
00122                             next_row, prev_row, pcol->length);
00123         sm_element_free(p);
00124     }
00125 }

void sm_col_remove_element ( sm_col pcol,
sm_element p 
)

Definition at line 275 of file cols.c.

00276 {
00277     dll_unlink(p, pcol->first_row, pcol->last_row, 
00278                         next_row, prev_row, pcol->length);
00279     sm_element_free(p);
00280 }


Generated on Tue Jan 12 13:57:28 2010 for glu-2.2 by  doxygen 1.6.1