struct gmi_iter* gmi_base_begin(struct gmi_model* m, int dim) { struct agm_ent* i; i = malloc(sizeof(*i)); *i = agm_first_ent(to_base(m)->topo, agm_type_from_dim(dim)); return (struct gmi_iter*)i; }
void gmi_freeze_lookup(struct gmi_lookup* l, enum agm_ent_type t) { struct entry* es; int n; struct agm_ent e; struct entry* y; assert(!(l->sorted[t])); n = agm_ent_count(l->topo, t); es = malloc(n * sizeof(*es)); y = es; for (e = agm_first_ent(l->topo, t); !agm_ent_null(e); e = agm_next_ent(l->topo, e)) { y->index = e.id; y->tag = *(get_tag(l, e)); ++y; } assert(y - es == n); qsort(es, n, sizeof(*es), comp_entries); l->sorted[t] = es; }
struct agm_ent gmi_look_up(struct gmi_lookup* l, enum agm_ent_type t, int tag) { struct entry key; struct entry* found; struct agm_ent e; if (l->sorted[t]) { e.type = t; e.id = -1; key.tag = tag; found = bsearch(&key, l->sorted[t], agm_ent_count(l->topo, t), sizeof(key), comp_entries); if (found) e.id = found->index; } else { for (e = agm_first_ent(l->topo, t); !agm_ent_null(e); e = agm_next_ent(l->topo, e)) if (*(get_tag(l, e)) == tag) return e; } return e; }