src/misc/espresso/rows.c File Reference

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

Go to the source code of this file.

Functions

sm_rowsm_row_alloc ()
void sm_row_free (sm_row *prow)
sm_rowsm_row_dup (sm_row *prow)
sm_elementsm_row_insert (sm_row *prow, int col)
void sm_row_remove (sm_row *prow, int col)
sm_elementsm_row_find (sm_row *prow, int col)
int sm_row_contains (sm_row *p1, sm_row *p2)
int sm_row_intersects (sm_row *p1, sm_row *p2)
int sm_row_compare (sm_row *p1, sm_row *p2)
sm_rowsm_row_and (sm_row *p1, sm_row *p2)
int sm_row_hash (sm_row *prow, int modulus)
void sm_row_remove_element (sm_row *prow, sm_element *p)
void sm_row_print (FILE *fp, sm_row *prow)

Function Documentation

sm_row* sm_row_alloc (  ) 

Definition at line 18 of file rows.c.

00019 {
00020     register sm_row *prow;
00021 
00022 #ifdef FAST_AND_LOOSE
00023     if (sm_row_freelist == NIL(sm_row)) {
00024         prow = ALLOC(sm_row, 1);
00025     } else {
00026         prow = sm_row_freelist;
00027         sm_row_freelist = prow->next_row;
00028     }
00029 #else
00030     prow = ALLOC(sm_row, 1);
00031 #endif
00032 
00033     prow->row_num = 0;
00034     prow->length = 0;
00035     prow->first_col = prow->last_col = NIL(sm_element);
00036     prow->next_row = prow->prev_row = NIL(sm_row);
00037     prow->flag = 0;
00038     prow->user_word = NIL(char);                /* for our user ... */
00039     return prow;
00040 }

sm_row* sm_row_and ( sm_row p1,
sm_row p2 
)

Definition at line 244 of file rows.c.

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

int sm_row_compare ( sm_row p1,
sm_row p2 
)

Definition at line 215 of file rows.c.

00217 {
00218     register sm_element *q1, *q2;
00219 
00220     q1 = p1->first_col;
00221     q2 = p2->first_col;
00222     while(q1 != 0 && q2 != 0) {
00223         if (q1->col_num != q2->col_num) {
00224             return q1->col_num - q2->col_num;
00225         }
00226         q1 = q1->next_col;
00227         q2 = q2->next_col;
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_row_contains ( sm_row p1,
sm_row p2 
)

Definition at line 162 of file rows.c.

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

sm_row* sm_row_dup ( sm_row prow  ) 

Definition at line 79 of file rows.c.

00081 {
00082     register sm_row *pnew;
00083     register sm_element *p;
00084 
00085     pnew = sm_row_alloc();
00086     for(p = prow->first_col; p != 0; p = p->next_col) {
00087         (void) sm_row_insert(pnew, p->col_num);
00088     }
00089     return pnew;
00090 }

sm_element* sm_row_find ( sm_row prow,
int  col 
)

Definition at line 143 of file rows.c.

00146 {
00147     register sm_element *p;
00148 
00149     for(p = prow->first_col; p != 0 && p->col_num < col; p = p->next_col)
00150         ;
00151     if (p != 0 && p->col_num == col) {
00152         return p;
00153     } else {
00154         return NIL(sm_element);
00155     }
00156 }

void sm_row_free ( sm_row prow  ) 

Definition at line 50 of file rows.c.

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

int sm_row_hash ( sm_row prow,
int  modulus 
)

Definition at line 276 of file rows.c.

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

sm_element* sm_row_insert ( sm_row prow,
int  col 
)

Definition at line 97 of file rows.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, prow->first_col, prow->last_col, prow->length, 
00107                     next_col, prev_col, col_num, col, 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_row_intersects ( sm_row p1,
sm_row p2 
)

Definition at line 187 of file rows.c.

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

void sm_row_print ( FILE *  fp,
sm_row prow 
)

Definition at line 305 of file rows.c.

00308 {
00309     sm_element *p;
00310 
00311     for(p = prow->first_col; p != 0; p = p->next_col) {
00312         (void) fprintf(fp, " %d", p->col_num);
00313     }
00314 }

void sm_row_remove ( sm_row prow,
int  col 
)

Definition at line 123 of file rows.c.

00126 {
00127     register sm_element *p;
00128 
00129     for(p = prow->first_col; p != 0 && p->col_num < col; p = p->next_col)
00130         ;
00131     if (p != 0 && p->col_num == col) {
00132         dll_unlink(p, prow->first_col, prow->last_col, 
00133                             next_col, prev_col, prow->length);
00134         sm_element_free(p);
00135     }
00136 }

void sm_row_remove_element ( sm_row prow,
sm_element p 
)

Definition at line 294 of file rows.c.

00297 {
00298     dll_unlink(p, prow->first_col, prow->last_col, 
00299                         next_col, prev_col, prow->length);
00300     sm_element_free(p);
00301 }


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