Beispiel #1
0
struct gmi_ent* gmi_from_agm(struct agm_ent e)
{
  char* p = 0;
  int uid;
  if (agm_ent_null(e))
    uid = 0;
  else
    uid = e.id * AGM_ENT_TYPES + e.type + 1;
  p += uid;
  return (struct gmi_ent*)p;
}
Beispiel #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;
}
Beispiel #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;
}