src/misc/espresso/cols.c File Reference

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

Go to the source code of this file.

Functions

sm_colsm_col_alloc ()
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 (  ) 

Definition at line 18 of file cols.c.

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

sm_col* sm_col_and ( sm_col p1,
sm_col p2 
)

Definition at line 244 of file cols.c.

00246 {
00247     register sm_element *q1, *q2;
00248     register sm_col *result;
00249 
00250     result = sm_col_alloc();
00251     q1 = p1->first_row;
00252     q2 = p2->first_row;
00253     if (q1 == 0 || q2 == 0) return result;
00254     for(;;) {
00255         if (q1->row_num < q2->row_num) {
00256             if ((q1 = q1->next_row) == 0) {
00257                 return result;
00258             }
00259         } else if (q1->row_num > q2->row_num) {
00260             if ((q2 = q2->next_row) == 0) {
00261                 return result;
00262             }
00263         } else {
00264             (void) sm_col_insert(result, q1->row_num);
00265             if ((q1 = q1->next_row) == 0) {
00266                 return result;
00267             }
00268             if ((q2 = q2->next_row) == 0) {
00269                 return result;
00270             }
00271         }
00272     }
00273 }

int sm_col_compare ( sm_col p1,
sm_col p2 
)

Definition at line 215 of file cols.c.

00217 {
00218     register sm_element *q1, *q2;
00219 
00220     q1 = p1->first_row;
00221     q2 = p2->first_row;
00222     while(q1 != 0 && q2 != 0) {
00223         if (q1->row_num != q2->row_num) {
00224             return q1->row_num - q2->row_num;
00225         }
00226         q1 = q1->next_row;
00227         q2 = q2->next_row;
00228     }
00229 
00230     if (q1 != 0) {
00231         return 1;
00232     } else if (q2 != 0) {
00233         return -1;
00234     } else {
00235         return 0;
00236     }
00237 }

int sm_col_contains ( sm_col p1,
sm_col p2 
)

Definition at line 162 of file cols.c.

00164 {
00165     register sm_element *q1, *q2;
00166 
00167     q1 = p1->first_row;
00168     q2 = p2->first_row;
00169     while (q1 != 0) {
00170         if (q2 == 0 || q1->row_num < q2->row_num) {
00171             return 0;
00172         } else if (q1->row_num == q2->row_num) {
00173             q1 = q1->next_row;
00174             q2 = q2->next_row;
00175         } else {
00176             q2 = q2->next_row;
00177         }
00178     }
00179     return 1;
00180 }

sm_col* sm_col_dup ( sm_col pcol  ) 

Definition at line 79 of file cols.c.

00081 {
00082     register sm_col *pnew;
00083     register sm_element *p;
00084 
00085     pnew = sm_col_alloc();
00086     for(p = pcol->first_row; p != 0; p = p->next_row) {
00087         (void) sm_col_insert(pnew, p->row_num);
00088     }
00089     return pnew;
00090 }

sm_element* sm_col_find ( sm_col pcol,
int  row 
)

Definition at line 143 of file cols.c.

00146 {
00147     register sm_element *p;
00148 
00149     for(p = pcol->first_row; p != 0 && p->row_num < row; p = p->next_row)
00150         ;
00151     if (p != 0 && p->row_num == row) {
00152         return p;
00153     } else {
00154         return NIL(sm_element);
00155     }
00156 }

void sm_col_free ( sm_col pcol  ) 

Definition at line 50 of file cols.c.

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

int sm_col_hash ( sm_col pcol,
int  modulus 
)

Definition at line 276 of file cols.c.

00279 {
00280     register int sum;
00281     register sm_element *p;
00282 
00283     sum = 0;
00284     for(p = pcol->first_row; p != 0; p = p->next_row) {
00285         sum = (sum*17 + p->row_num) % modulus;
00286     }
00287     return sum;
00288 }

sm_element* sm_col_insert ( sm_col pcol,
int  row 
)

Definition at line 97 of file cols.c.

00100 {
00101     register sm_element *test, *element;
00102 
00103     /* get a new item, save its address */
00104     sm_element_alloc(element);
00105     test = element;
00106     sorted_insert(sm_element, pcol->first_row, pcol->last_row, pcol->length, 
00107                     next_row, prev_row, row_num, row, test);
00108 
00109     /* if item was not used, free it */
00110     if (element != test) {
00111         sm_element_free(element);
00112     }
00113 
00114     /* either way, return the current new value */
00115     return test;
00116 }

int sm_col_intersects ( sm_col p1,
sm_col p2 
)

Definition at line 187 of file cols.c.

00189 {
00190     register sm_element *q1, *q2;
00191 
00192     q1 = p1->first_row;
00193     q2 = p2->first_row;
00194     if (q1 == 0 || q2 == 0) return 0;
00195     for(;;) {
00196         if (q1->row_num < q2->row_num) {
00197             if ((q1 = q1->next_row) == 0) {
00198                 return 0;
00199             }
00200         } else if (q1->row_num > q2->row_num) {
00201             if ((q2 = q2->next_row) == 0) {
00202                 return 0;
00203             }
00204         } else {
00205             return 1;
00206         }
00207     }
00208 }

void sm_col_print ( FILE *  fp,
sm_col pcol 
)

Definition at line 305 of file cols.c.

00308 {
00309     sm_element *p;
00310 
00311     for(p = pcol->first_row; p != 0; p = p->next_row) {
00312         (void) fprintf(fp, " %d", p->row_num);
00313     }
00314 }

void sm_col_remove ( sm_col pcol,
int  row 
)

Definition at line 123 of file cols.c.

00126 {
00127     register sm_element *p;
00128 
00129     for(p = pcol->first_row; p != 0 && p->row_num < row; p = p->next_row)
00130         ;
00131     if (p != 0 && p->row_num == row) {
00132         dll_unlink(p, pcol->first_row, pcol->last_row, 
00133                             next_row, prev_row, pcol->length);
00134         sm_element_free(p);
00135     }
00136 }

void sm_col_remove_element ( sm_col pcol,
sm_element p 
)

Definition at line 294 of file cols.c.

00297 {
00298     dll_unlink(p, pcol->first_row, pcol->last_row, 
00299                         next_row, prev_row, pcol->length);
00300     sm_element_free(p);
00301 }


Generated on Tue Jan 5 12:19:09 2010 for abc70930 by  doxygen 1.6.1