Ejemplo n.º 1
0
struct gmi_ent* gmi_base_next(struct gmi_model* m, struct gmi_iter* it)
{
  struct agm_ent* i;
  struct agm_ent e;
  i = (struct agm_ent*)it;
  e = *i;
  *i = agm_next_ent(to_base(m)->topo, e);
  return gmi_from_agm(e);
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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;
}