/* * Delete the learner structure and all epartition objects */ void delete_eq_learner(eq_learner_t *learner) { ptr_hmap_pair_t *p; ptr_hmap_t *cache; epartition_manager_t *m; cache = &learner->cache; m = &learner->manager; for (p = ptr_hmap_first_record(cache); p != NULL; p = ptr_hmap_next_record(cache, p)) { delete_epartition(m, p->val); } delete_ptr_hmap(cache); delete_epartition_manager(m); }
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; }