Beispiel #1
0
/*
 * Get abstraction for f in the cache
 * - this works only if the corresponding record exists
 */
static epartition_t *get_cached_abstraction(eq_learner_t *learner, term_t f) {
  ptr_hmap_pair_t *p;

  assert(good_term(learner->terms, f) && is_boolean_term(learner->terms, f));
  p = ptr_hmap_find(&learner->cache, f);
  assert(p != NULL);

  return p->val;
}
Beispiel #2
0
int main() {
  ptr_hmap_pair_t *d;
  int32_t i;

  init_ptr_hmap(&map, 4);
  printf("\n*** Initial map ***\n");
  print_map(&map);

  // add 9 records
  for (i=0; i<9; i++) {
    d = ptr_hmap_get(&map, i);
    if (d->val == NULL) {
      d->val = test[i];
      printf("added new record %p: [key = %"PRId32", val = %s]\n", d, i, (char*) d->val);
    } else {
      printf("found record %p: [key = %"PRId32", val = %s]\n", d, i, (char *) d->val);
    }
  }

  printf("\n*** Map ***\n");
  print_map(&map);

  // search
  for (i=0; i<20; i++) {
    printf("searching: key = %"PRId32": ", i);
    fflush(stdout);
    d = ptr_hmap_find(&map, i);
    if (d == NULL) {
      printf("not found\n");
    } else {
      printf("found: val = %s\n", (char*) d->val);
    }
  }

  // erase some records;
  for (i=0; i<9; i+=3) {
    d = ptr_hmap_find(&map, i);
    if (d != NULL) {
      printf("erasing record %p: key = %"PRId32", val = %s\n", d, i, (char*) d->val);
      ptr_hmap_erase(&map, d);
    } else {
      printf("*** BUG ***\n");
    }
  }

  printf("\n*** Map after deletion ***\n");
  print_map(&map);

  // search
  for (i=0; i<9; i++) {
    printf("searching: key = %"PRId32": ", i);
    fflush(stdout);
    d = ptr_hmap_find(&map, i);
    if (d == NULL) {
      printf("not found\n");
    } else {
      printf("found: val = %s\n", (char*) d->val);
    }
  }

  ptr_hmap_reset(&map);

  printf("\n*** Map after reset ***\n");
  print_map(&map);

  delete_ptr_hmap(&map);

  return 0;
}