/*
* We keep an array sorted by bad atom pointer.
* The theory is that since we don't free memory very often,
* the array will be mostly sorted already and insertions will
* usually be near the end, so we won't spend much time
* keeping it sorted.
*/
/*
* Binary search a Tx list.
* If no entry is found, return a pointer to
* where a new such entry would go.
*/
static Tx*
txsearch(char *atom, Tx *t, int n)
{
while(n > 0) {
if(atom < t[n/2].bad)
n = n/2;
else if(atom > t[n/2].bad) {
t += n/2+1;
n -= (n/2+1);
} else
return &t[n/2];
}
return t;
}
void
addtx(char *b, char *g)
{
Tx *t;
Conform *c;
if(map == nil)
map = emalloc(sizeof(*map));
c = map;
if(c->nt%32 == 0)
c->t = erealloc(c->t, (c->nt+32)*sizeof(c->t[0]));
t = txsearch(b, c->t, c->nt);
if(t < c->t+c->nt && t->bad == b) {
fprint(2, "warning: duplicate entry for %s in _conform.map\n", b);
return;
}