#include "espresso.h"
Go to the source code of this file.
int bit_index | ( | unsigned int | a | ) |
static int intcpy | ( | unsigned int * | d, | |
unsigned int * | s, | |||
long | n | |||
) | [static] |
char* pbv1 | ( | pset | s, | |
int | n | |||
) |
char* ps1 | ( | pset | a | ) |
Definition at line 512 of file set.c.
00514 { 00515 register int i, num, l, len = 0, n = NELEM(a); 00516 char temp[20]; 00517 bool first = TRUE; 00518 00519 s1[len++] = '['; 00520 for(i = 0; i < n; i++) 00521 if (is_in_set(a,i)) { 00522 if (! first) 00523 s1[len++] = ','; 00524 first = FALSE; num = i; 00525 /* Generate digits (reverse order) */ 00526 l = 0; do temp[l++] = num % 10 + '0'; while ((num /= 10) > 0); 00527 /* Copy them back in correct order */ 00528 do s1[len++] = temp[--l]; while (l > 0); 00529 if (len > largest_string-15) { 00530 s1[len++] = '.'; s1[len++] = '.'; s1[len++] = '.'; 00531 break; 00532 } 00533 } 00534 00535 s1[len++] = ']'; 00536 s1[len++] = '\0'; 00537 return s1; 00538 }
void set_adjcnt | ( | pset | a, | |
int * | count, | |||
int | weight | |||
) |
Definition at line 56 of file set.c.
00058 { 00059 register int i, sum = 0; 00060 register unsigned int val; 00061 for(i = LOOP(a); i > 0; i--) 00062 if ((val = a[i] & b[i]) != 0) 00063 sum += count_ones(val); 00064 return sum; 00065 }
int set_ord | ( | pset | a | ) |
Definition at line 44 of file set.c.
00046 { 00047 register int i, sum = 0; 00048 register unsigned int val; 00049 for(i = LOOP(a); i > 0; i--) 00050 if ((val = a[i]) != 0) 00051 sum += count_ones(val); 00052 return sum; 00053 }
void set_write | ( | FILE * | fp, | |
pset | a | |||
) |
pset_family sf_active | ( | pset_family | A | ) |
Definition at line 247 of file set.c.
00249 { 00250 register pset p, last; 00251 foreach_set(A, last, p) { 00252 SET(p, ACTIVE); 00253 } 00254 A->active_count = A->count; 00255 return A; 00256 }
pset_family sf_addcol | ( | pset_family | A, | |
int | firstcol, | |||
int | n | |||
) |
Definition at line 648 of file set.c.
00651 { 00652 int maxsize; 00653 00654 /* Check if adding columns at the end ... */ 00655 if (firstcol == A->sf_size) { 00656 /* If so, check if there is already enough room */ 00657 maxsize = BPI * LOOPINIT(A->sf_size); 00658 if ((A->sf_size + n) <= maxsize) { 00659 A->sf_size += n; 00660 return A; 00661 } 00662 } 00663 return sf_delcol(A, firstcol, -n); 00664 }
pset_family sf_addset | ( | pset_family | A, | |
pset | s | |||
) |
pset sf_and | ( | pset_family | A | ) |
Definition at line 235 of file set.c.
00237 { 00238 register pset and, last, p; 00239 00240 and = set_fill(set_new(A->sf_size), A->sf_size); 00241 foreach_set(A, last, p) 00242 INLINEset_and(and, and, p); 00243 return and; 00244 }
pset_family sf_append | ( | pset_family | A, | |
pset_family | B | |||
) |
Definition at line 314 of file set.c.
00316 { 00317 long asize = A->count * A->wsize; 00318 long bsize = B->count * B->wsize; 00319 00320 if (A->sf_size != B->sf_size) fatal("sf_append: sf_size mismatch"); 00321 A->capacity = A->count + B->count; 00322 A->data = REALLOC(unsigned int, A->data, (long) A->capacity * A->wsize); 00323 intcpy(A->data + asize, B->data, bsize); 00324 A->count += B->count; 00325 A->active_count += B->active_count; 00326 sf_free(B); 00327 return A; 00328 }
void sf_bm_print | ( | pset_family | A | ) |
pset_family sf_bm_read | ( | FILE * | fp | ) |
Definition at line 477 of file set.c.
00479 { 00480 int i, j, rows, cols; 00481 register pset pdest; 00482 pset_family A; 00483 00484 (void) fscanf(fp, "%d %d\n", &rows, &cols); 00485 A = sf_new(rows, cols); 00486 for(i = 0; i < rows; i++) { 00487 pdest = GETSET(A, A->count++); 00488 (void) set_clear(pdest, A->sf_size); 00489 for(j = 0; j < cols; j++) { 00490 switch(getc(fp)) { 00491 case '0': 00492 break; 00493 case '1': 00494 set_insert(pdest, j); 00495 break; 00496 default: 00497 fatal("Error reading set family"); 00498 } 00499 } 00500 if (getc(fp) != '\n') { 00501 fatal("Error reading set family (at end of line)"); 00502 } 00503 } 00504 return A; 00505 }
void sf_cleanup | ( | ) |
Definition at line 371 of file set.c.
00372 { 00373 register pset_family p, pnext; 00374 for(p = set_family_garbage; p != (pset_family) NULL; p = pnext) { 00375 pnext = p->next; 00376 FREE(p); 00377 } 00378 set_family_garbage = (pset_family) NULL; 00379 }
pset_family sf_compress | ( | pset_family | A, | |
pset | c | |||
) |
Definition at line 735 of file set.c.
00738 { 00739 register pset p; 00740 register int i, bcol; 00741 pset_family B; 00742 00743 /* create a clean set family for the result */ 00744 B = sf_new(A->count, set_ord(c)); 00745 for(i = 0; i < A->count; i++) { 00746 p = GETSET(B, B->count++); 00747 INLINEset_clear(p, B->sf_size); 00748 } 00749 00750 /* copy each column of A which has a 1 in c */ 00751 bcol = 0; 00752 for(i = 0; i < A->sf_size; i++) { 00753 if (is_in_set(c, i)) { 00754 (void) sf_copy_col(B, bcol++, A, i); 00755 } 00756 } 00757 sf_free(A); 00758 return B; 00759 }
pset_family sf_copy | ( | pset_family | R, | |
pset_family | A | |||
) |
Definition at line 281 of file set.c.
00283 { 00284 R->sf_size = A->sf_size; 00285 R->wsize = A->wsize; 00286 /*R->capacity = A->count;*/ 00287 /*R->data = REALLOC(unsigned int, R->data, (long) R->capacity * R->wsize);*/ 00288 R->count = A->count; 00289 R->active_count = A->active_count; 00290 intcpy(R->data, A->data, (long) A->wsize * A->count); 00291 return R; 00292 }
pset_family sf_copy_col | ( | pset_family | dst, | |
int | dstcol, | |||
pset_family | src, | |||
int | srccol | |||
) |
Definition at line 703 of file set.c.
00706 { 00707 register pset last, p, pdest; 00708 register int word_test, word_set; 00709 unsigned int bit_set, bit_test; 00710 00711 /* CHEAT! form these constants outside the loop */ 00712 word_test = WHICH_WORD(srccol); 00713 bit_test = 1 << WHICH_BIT(srccol); 00714 word_set = WHICH_WORD(dstcol); 00715 bit_set = 1 << WHICH_BIT(dstcol); 00716 00717 pdest = dst->data; 00718 foreach_set(src, last, p) { 00719 if ((p[word_test] & bit_test) != 0) 00720 pdest[word_set] |= bit_set; 00721 /* 00722 * equivalent code for this is ... 00723 * if (is_in_set(p, srccol)) set_insert(pdest, destcol); 00724 */ 00725 pdest += dst->wsize; 00726 } 00727 return dst; 00728 }
int* sf_count | ( | pset_family | A | ) |
Definition at line 574 of file set.c.
00576 { 00577 register pset p, last; 00578 register int i, base, *count; 00579 register unsigned int val; 00580 00581 count = ALLOC(int, A->sf_size); 00582 for(i = A->sf_size - 1; i >= 0; i--) { 00583 count[i] = 0; 00584 } 00585 00586 foreach_set(A, last, p) { 00587 for(i = LOOP(p); i > 0; ) { 00588 for(val = p[i], base = --i << LOGBPI; val != 0; base++, val >>= 1) { 00589 if (val & 1) { 00590 count[base]++; 00591 } 00592 } 00593 } 00594 } 00595 return count; 00596 }
int* sf_count_restricted | ( | pset_family | A, | |
pset | r | |||
) |
Definition at line 603 of file set.c.
00606 { 00607 register pset p; 00608 register int i, base, *count; 00609 register unsigned int val; 00610 int weight; 00611 pset last; 00612 00613 count = ALLOC(int, A->sf_size); 00614 for(i = A->sf_size - 1; i >= 0; i--) { 00615 count[i] = 0; 00616 } 00617 00618 /* Loop for each set */ 00619 foreach_set(A, last, p) { 00620 weight = 1024 / (set_ord(p) - 1); 00621 for(i = LOOP(p); i > 0; ) { 00622 for(val=p[i]&r[i], base= --i<<LOGBPI; val!=0; base++, val >>= 1) { 00623 if (val & 1) { 00624 count[base] += weight; 00625 } 00626 } 00627 } 00628 } 00629 return count; 00630 }
pset_family sf_delc | ( | pset_family | A, | |
int | first, | |||
int | last | |||
) |
pset_family sf_delcol | ( | pset_family | A, | |
int | firstcol, | |||
int | n | |||
) |
Definition at line 676 of file set.c.
00679 { 00680 register pset p, last, pdest; 00681 register int i; 00682 pset_family B; 00683 00684 B = sf_new(A->count, A->sf_size - n); 00685 foreach_set(A, last, p) { 00686 pdest = GETSET(B, B->count++); 00687 INLINEset_clear(pdest, B->sf_size); 00688 for(i = 0; i < firstcol; i++) 00689 if (is_in_set(p, i)) 00690 set_insert(pdest, i); 00691 for(i = n > 0 ? firstcol + n : firstcol; i < A->sf_size; i++) 00692 if (is_in_set(p, i)) 00693 set_insert(pdest, i - n); 00694 } 00695 sf_free(A); 00696 return B; 00697 }
void sf_delset | ( | pset_family | A, | |
int | i | |||
) |
void sf_free | ( | pset_family | A | ) |
Definition at line 361 of file set.c.
00363 { 00364 FREE(A->data); 00365 A->next = set_family_garbage; 00366 set_family_garbage = A; 00367 }
pset_family sf_inactive | ( | pset_family | A | ) |
Definition at line 260 of file set.c.
00262 { 00263 register pset p, last, pdest; 00264 00265 pdest = A->data; 00266 foreach_set(A, last, p) { 00267 if (TESTP(p, ACTIVE)) { 00268 if (pdest != p) { 00269 INLINEset_copy(pdest, p); 00270 } 00271 pdest += A->wsize; 00272 } else { 00273 A->count--; 00274 } 00275 } 00276 return A; 00277 }
pset_family sf_join | ( | pset_family | A, | |
pset_family | B | |||
) |
Definition at line 296 of file set.c.
00298 { 00299 pset_family R; 00300 long asize = A->count * A->wsize; 00301 long bsize = B->count * B->wsize; 00302 00303 if (A->sf_size != B->sf_size) fatal("sf_join: sf_size mismatch"); 00304 R = sf_new(A->count + B->count, A->sf_size); 00305 R->count = A->count + B->count; 00306 R->active_count = A->active_count + B->active_count; 00307 intcpy(R->data, A->data, asize); 00308 intcpy(R->data + asize, B->data, bsize); 00309 return R; 00310 }
pset_family sf_new | ( | int | num, | |
int | size | |||
) |
Definition at line 332 of file set.c.
00334 { 00335 pset_family A; 00336 if (set_family_garbage == NULL) { 00337 A = ALLOC(set_family_t, 1); 00338 } else { 00339 A = set_family_garbage; 00340 set_family_garbage = A->next; 00341 } 00342 A->sf_size = size; 00343 A->wsize = SET_SIZE(size); 00344 A->capacity = num; 00345 A->data = ALLOC(unsigned int, (long) A->capacity * A->wsize); 00346 A->count = 0; 00347 A->active_count = 0; 00348 return A; 00349 }
pset sf_or | ( | pset_family | A | ) |
Definition at line 223 of file set.c.
00225 { 00226 register pset or, last, p; 00227 00228 or = set_new(A->sf_size); 00229 foreach_set(A, last, p) 00230 INLINEset_or(or, or, p); 00231 return or; 00232 }
pset_family sf_permute | ( | pset_family | A, | |
int * | permute, | |||
int | npermute | |||
) |
Definition at line 798 of file set.c.
00801 { 00802 pset_family B; 00803 register pset p, last, pdest; 00804 register int j; 00805 00806 B = sf_new(A->count, npermute); 00807 B->count = A->count; 00808 foreach_set(B, last, p) 00809 INLINEset_clear(p, npermute); 00810 00811 pdest = B->data; 00812 foreach_set(A, last, p) { 00813 for(j = 0; j < npermute; j++) 00814 if (is_in_set(p, permute[j])) 00815 set_insert(pdest, j); 00816 pdest += B->wsize; 00817 } 00818 sf_free(A); 00819 return B; 00820 }
void sf_print | ( | pset_family | A | ) |
pset_family sf_read | ( | FILE * | fp | ) |
Definition at line 441 of file set.c.
00443 { 00444 int i, j; 00445 register pset p, last; 00446 pset_family A; 00447 00448 (void) fscanf(fp, "%d %d\n", &i, &j); 00449 A = sf_new(i, j); 00450 A->count = i; 00451 foreach_set(A, last, p) { 00452 (void) fscanf(fp, "%x", p); 00453 for(j = 1; j <= LOOP(p); j++) 00454 (void) fscanf(fp, "%x", p+j); 00455 } 00456 return A; 00457 }
pset_family sf_save | ( | pset_family | A | ) |
pset_family sf_transpose | ( | pset_family | A | ) |
Definition at line 768 of file set.c.
00770 { 00771 pset_family B; 00772 register pset p; 00773 register int i, j; 00774 00775 B = sf_new(A->sf_size, A->count); 00776 B->count = A->sf_size; 00777 foreachi_set(B, i, p) { 00778 INLINEset_clear(p, B->sf_size); 00779 } 00780 foreachi_set(A, i, p) { 00781 for(j = 0; j < A->sf_size; j++) { 00782 if (is_in_set(p, j)) { 00783 set_insert(GETSET(B, j), i); 00784 } 00785 } 00786 } 00787 sf_free(A); 00788 return B; 00789 }
void sf_write | ( | FILE * | fp, | |
pset_family | A | |||
) |
pset_family set_family_garbage = NULL [static] |