Example #1
0
/*
 * Store that f is abstracted to p
 * - there must not be a record for f in the cache
 */
static void cache_abstraction(eq_learner_t *learner, term_t f, epartition_t *p) {
  ptr_hmap_pair_t *r;

  assert(good_term(learner->terms, f) && is_boolean_term(learner->terms, f) && p != NULL);
  r = ptr_hmap_get(&learner->cache, f);
  assert(r->val == NULL);
  r->val = p;
}
Example #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;
}