/* * Find the value of term t in model * - return null_value if t is not mapped to anything * - return the concrete object mapped to t otherwise */ value_t model_find_term_value(model_t *model, term_t t) { int_hmap_pair_t *r; assert(good_term(model->terms, t)); r = int_hmap_find(&model->map, t); if (r == NULL) { return null_value; } else { return r->val; } }
/* * Check what's mapped to v in convert->cache * - return -1 if nothing */ static term_t convert_cached_term(val_converter_t *convert, value_t v) { int_hmap_pair_t *r; term_t t; assert(good_object(convert->vtbl, v)); t = NULL_TERM; r = int_hmap_find(&convert->cache, v); if (r != NULL) { t = r->val; } return t; }
/* * Check whether t is mapped to a term v in the substitution table. * - return v if it is * - return NULL_TERM otherwise */ term_t model_find_term_substitution(model_t *model, term_t t) { int_hmap_t *alias; int_hmap_pair_t *r; assert(good_term(model->terms, t) && model->has_alias); alias = model->alias_map; if (alias != NULL) { r = int_hmap_find(alias, t); if (r != NULL) { return r->val; } } return NULL_TERM; }
/* * Store the substitution t --> u in the model * - t and u must be valid term indices * - t must be an uninterpreted term, not mapped to anything */ void model_add_substitution(model_t *model, term_t t, term_t u) { int_hmap_t *alias; int_hmap_pair_t *r; assert(term_kind(model->terms, t) == UNINTERPRETED_TERM && good_term(model->terms, u) && t != u && model->has_alias && int_hmap_find(&model->map, t) == NULL); alias = model->alias_map; if (alias == NULL) { alias = (int_hmap_t *) safe_malloc(sizeof(int_hmap_t)); init_int_hmap(alias, 0); // default size model->alias_map = alias; } r = int_hmap_get(alias, t); assert(r->val < 0); r->val = u; }