abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rows.c File Reference
#include "sparse_int.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START 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

ABC_NAMESPACE_IMPL_START sm_row* sm_row_alloc ( )

Definition at line 21 of file rows.c.

22 {
23  register sm_row *prow;
24 
25 #ifdef FAST_AND_LOOSE
26  if (sm_row_freelist == NIL(sm_row)) {
27  prow = ALLOC(sm_row, 1);
28  } else {
29  prow = sm_row_freelist;
30  sm_row_freelist = prow->next_row;
31  }
32 #else
33  prow = ALLOC(sm_row, 1);
34 #endif
35 
36  prow->row_num = 0;
37  prow->length = 0;
38  prow->first_col = prow->last_col = NIL(sm_element);
39  prow->next_row = prow->prev_row = NIL(sm_row);
40  prow->flag = 0;
41  prow->user_word = NIL(char); /* for our user ... */
42  return prow;
43 }
int length
Definition: sparse.h:46
sm_row * next_row
Definition: sparse.h:50
sm_row * prev_row
Definition: sparse.h:51
sm_element * last_col
Definition: sparse.h:49
#define NIL(type)
Definition: avl.h:25
#define ALLOC(type, num)
Definition: avl.h:27
int row_num
Definition: sparse.h:45
int flag
Definition: sparse.h:47
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
char * user_word
Definition: sparse.h:52
sm_element * first_col
Definition: sparse.h:48
sm_row* sm_row_and ( sm_row p1,
sm_row p2 
)

Definition at line 247 of file rows.c.

249 {
250  register sm_element *q1, *q2;
251  register sm_row *result;
252 
253  result = sm_row_alloc();
254  q1 = p1->first_col;
255  q2 = p2->first_col;
256  if (q1 == 0 || q2 == 0) return result;
257  for(;;) {
258  if (q1->col_num < q2->col_num) {
259  if ((q1 = q1->next_col) == 0) {
260  return result;
261  }
262  } else if (q1->col_num > q2->col_num) {
263  if ((q2 = q2->next_col) == 0) {
264  return result;
265  }
266  } else {
267  (void) sm_row_insert(result, q1->col_num);
268  if ((q1 = q1->next_col) == 0) {
269  return result;
270  }
271  if ((q2 = q2->next_col) == 0) {
272  return result;
273  }
274  }
275  }
276 }
sm_element * sm_row_insert(sm_row *prow, int col)
Definition: rows.c:100
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
static int result
Definition: cuddGenetic.c:125
ABC_NAMESPACE_IMPL_START sm_row * sm_row_alloc()
Definition: rows.c:21
sm_element * first_col
Definition: sparse.h:48
int sm_row_compare ( sm_row p1,
sm_row p2 
)

Definition at line 218 of file rows.c.

220 {
221  register sm_element *q1, *q2;
222 
223  q1 = p1->first_col;
224  q2 = p2->first_col;
225  while(q1 != 0 && q2 != 0) {
226  if (q1->col_num != q2->col_num) {
227  return q1->col_num - q2->col_num;
228  }
229  q1 = q1->next_col;
230  q2 = q2->next_col;
231  }
232 
233  if (q1 != 0) {
234  return 1;
235  } else if (q2 != 0) {
236  return -1;
237  } else {
238  return 0;
239  }
240 }
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
sm_element * first_col
Definition: sparse.h:48
int sm_row_contains ( sm_row p1,
sm_row p2 
)

Definition at line 165 of file rows.c.

167 {
168  register sm_element *q1, *q2;
169 
170  q1 = p1->first_col;
171  q2 = p2->first_col;
172  while (q1 != 0) {
173  if (q2 == 0 || q1->col_num < q2->col_num) {
174  return 0;
175  } else if (q1->col_num == q2->col_num) {
176  q1 = q1->next_col;
177  q2 = q2->next_col;
178  } else {
179  q2 = q2->next_col;
180  }
181  }
182  return 1;
183 }
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
sm_element * first_col
Definition: sparse.h:48
sm_row* sm_row_dup ( sm_row prow)

Definition at line 82 of file rows.c.

84 {
85  register sm_row *pnew;
86  register sm_element *p;
87 
88  pnew = sm_row_alloc();
89  for(p = prow->first_col; p != 0; p = p->next_col) {
90  (void) sm_row_insert(pnew, p->col_num);
91  }
92  return pnew;
93 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
sm_element * sm_row_insert(sm_row *prow, int col)
Definition: rows.c:100
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
ABC_NAMESPACE_IMPL_START sm_row * sm_row_alloc()
Definition: rows.c:21
sm_element * first_col
Definition: sparse.h:48
sm_element* sm_row_find ( sm_row prow,
int  col 
)

Definition at line 146 of file rows.c.

149 {
150  register sm_element *p;
151 
152  for(p = prow->first_col; p != 0 && p->col_num < col; p = p->next_col)
153  ;
154  if (p != 0 && p->col_num == col) {
155  return p;
156  } else {
157  return NIL(sm_element);
158  }
159 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define NIL(type)
Definition: avl.h:25
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
sm_element * first_col
Definition: sparse.h:48
void sm_row_free ( sm_row prow)

Definition at line 53 of file rows.c.

55 {
56 #if defined(FAST_AND_LOOSE) && ! defined(COLS)
57  if (prow->first_col != NIL(sm_element)) {
58  /* Add the linked list of row items to the free list */
59  prow->last_col->next_col = sm_element_freelist;
60  sm_element_freelist = prow->first_col;
61  }
62 
63  /* Add the row to the free list of rows */
64  prow->next_row = sm_row_freelist;
65  sm_row_freelist = prow;
66 #else
67  register sm_element *p, *pnext;
68 
69  for(p = prow->first_col; p != 0; p = pnext) {
70  pnext = p->next_col;
71  sm_element_free(p);
72  }
73  FREE(prow);
74 #endif
75 }
sm_row * next_row
Definition: sparse.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define sm_element_free(e)
Definition: sparse_int.h:113
sm_element * last_col
Definition: sparse.h:49
#define NIL(type)
Definition: avl.h:25
#define FREE(obj)
Definition: avl.h:31
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
sm_element * first_col
Definition: sparse.h:48
int sm_row_hash ( sm_row prow,
int  modulus 
)

Definition at line 279 of file rows.c.

282 {
283  register int sum;
284  register sm_element *p;
285 
286  sum = 0;
287  for(p = prow->first_col; p != 0; p = p->next_col) {
288  sum = (sum*17 + p->col_num) % modulus;
289  }
290  return sum;
291 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
sm_element * first_col
Definition: sparse.h:48
sm_element* sm_row_insert ( sm_row prow,
int  col 
)

Definition at line 100 of file rows.c.

103 {
104  register sm_element *test, *element;
105 
106  /* get a new item, save its address */
107  sm_element_alloc(element);
108  test = element;
109  sorted_insert(sm_element, prow->first_col, prow->last_col, prow->length,
110  next_col, prev_col, col_num, col, test);
111 
112  /* if item was not used, free it */
113  if (element != test) {
114  sm_element_free(element);
115  }
116 
117  /* either way, return the current new value */
118  return test;
119 }
int length
Definition: sparse.h:46
#define sm_element_free(e)
Definition: sparse_int.h:113
sm_element * last_col
Definition: sparse.h:49
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
#define sm_element_alloc(newobj)
Definition: sparse_int.h:110
sm_element * first_col
Definition: sparse.h:48
int sm_row_intersects ( sm_row p1,
sm_row p2 
)

Definition at line 190 of file rows.c.

192 {
193  register sm_element *q1, *q2;
194 
195  q1 = p1->first_col;
196  q2 = p2->first_col;
197  if (q1 == 0 || q2 == 0) return 0;
198  for(;;) {
199  if (q1->col_num < q2->col_num) {
200  if ((q1 = q1->next_col) == 0) {
201  return 0;
202  }
203  } else if (q1->col_num > q2->col_num) {
204  if ((q2 = q2->next_col) == 0) {
205  return 0;
206  }
207  } else {
208  return 1;
209  }
210  }
211 }
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
sm_element * first_col
Definition: sparse.h:48
void sm_row_print ( FILE *  fp,
sm_row prow 
)

Definition at line 308 of file rows.c.

311 {
312  sm_element *p;
313 
314  for(p = prow->first_col; p != 0; p = p->next_col) {
315  (void) fprintf(fp, " %d", p->col_num);
316  }
317 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
sm_element * first_col
Definition: sparse.h:48
void sm_row_remove ( sm_row prow,
int  col 
)

Definition at line 126 of file rows.c.

129 {
130  register sm_element *p;
131 
132  for(p = prow->first_col; p != 0 && p->col_num < col; p = p->next_col)
133  ;
134  if (p != 0 && p->col_num == col) {
135  dll_unlink(p, prow->first_col, prow->last_col,
136  next_col, prev_col, prow->length);
137  sm_element_free(p);
138  }
139 }
int length
Definition: sparse.h:46
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define sm_element_free(e)
Definition: sparse_int.h:113
sm_element * last_col
Definition: sparse.h:49
#define dll_unlink(p, first, last, next, prev, count)
Definition: sparse_int.h:76
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
sm_element * first_col
Definition: sparse.h:48
void sm_row_remove_element ( sm_row prow,
sm_element p 
)

Definition at line 297 of file rows.c.

300 {
301  dll_unlink(p, prow->first_col, prow->last_col,
302  next_col, prev_col, prow->length);
304 }
int length
Definition: sparse.h:46
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define sm_element_free(e)
Definition: sparse_int.h:113
sm_element * last_col
Definition: sparse.h:49
#define dll_unlink(p, first, last, next, prev, count)
Definition: sparse_int.h:76
sm_element * first_col
Definition: sparse.h:48