Exemplo n.º 1
0
/*
 * Add the substitution [r1 := r2] to the table.
 * The substitution must be valid.
 */
void intern_tbl_add_subst(intern_tbl_t *tbl, term_t r1, term_t r2) {
  assert(intern_tbl_root_is_free(tbl, r1));

  if (! intern_tbl_term_present(tbl, r1)) {
    partition_add(tbl, r1);
  }

  if (! intern_tbl_term_present(tbl, r2)) {
    partition_add_frozen(tbl, r2);
  }

  partition_merge(tbl, r1, r2);
}
Exemplo n.º 2
0
/*
 * Merge the classes of r1 and r2
 * - both r1 and r2 must be free roots and have compatible types
 * - if both r1 and r2 are boolean, they may have arbitrary polarity
 * This adds either the substitution [r1 := r2] or [r2 := r1]
 */
void intern_tbl_merge_classes(intern_tbl_t *tbl, term_t r1, term_t r2) {
  assert(intern_tbl_root_is_free(tbl, r1) &&
         intern_tbl_root_is_free(tbl, r2));

  if (! intern_tbl_term_present(tbl, r1)) {
    partition_add(tbl, r1);
  }

  if (! intern_tbl_term_present(tbl, r2)) {
    partition_add(tbl, r2);
  }

  partition_merge(tbl, r1, r2);
}
Exemplo n.º 3
0
int main() {
  uint32_t i;
  int32_t x, y, rx, ry;

  init_partition(&partition, 0);
  printf("\n*** Initial partition ***\n");
  print_partition_details(&partition);

  for (i=0; i<40; i++) {
    x = random() % N;
    printf("--- testing %"PRId32" ---\n", x);
    y = partition_find(&partition, x);
    if (y < 0) {
      printf("item %"PRId32" not present; adding it\n", x);
      partition_add(&partition, x);
    } else {
      printf("root[%"PRId32"] = %"PRId32"\n", x, y);
    }
  }

  printf("\n*** Partition ***\n");
  print_partition_details(&partition);
  printf("\n");

  print_partition(&partition);
  printf("\n");

  for (x=0; x<N; x++) {
    aux[x] = partition_find(&partition, x);
  }
  for (i=1; i<10; i++) {
    do { x = random() % N; } while (aux[x] < 0);
    do { y = random() % N; } while (x == y || aux[y] < 0);

    x = partition_find(&partition, x);
    y = partition_find(&partition, y);
    if (x != y) {
      printf("--- Merging %"PRId32" and %"PRId32" ---\n", x, y);
      partition_merge(&partition, x, y);
    }
  }
  printf("\n");
  print_partition(&partition);

  reset_partition(&partition);

  for (i=0; i<100; i++) {
    x = random() % 300;
    rx = partition_find(&partition, x);
    if (rx < 0) {
      partition_add(&partition, x);
      rx = x;
    }
    y = random() % 300;
    ry = partition_find(&partition, y);
    if (ry < 0) {
      partition_add(&partition, y);
      ry = y;
    }
    if (rx != ry) {
      partition_merge(&partition, rx, ry);
    }
  }

  printf("\n\n");
  print_partition(&partition);

  delete_partition(&partition);

  return 0;
}