David Laight wrote:
>
> I guess if there are enough users to make a linear scan impratical
> then the program won't finishe overnight anyway!
If your computer has UID_MAX users and < 1 MHz
This version uses a semi-efficient reverse-sorted list. It also has
the compact code and indescriptive variable names that professionals
seem to value.
The performance penalty for regular use is near zero with the reverse
sorting and swapping algorithm. NIS users still get an OK performance.
Also note that it needs several thousand times more cycles to look up
something in NIS than to walk the list.
static int
inuidlist(uidlist_ptr, uid)
struct uidlist_s *uidlist_ptr;
uid_t uid;
{
struct uidlist_s *p,*tmp;
for (p=uidlist_ptr; p->next && (p->uid > uid); p=p->next);
if ((p->uid==uid) && p->next) return (1);
if (tmp=malloc(sizeof *tmp)) {
*tmp=*p;
p->next=tmp;
p->uid=uid;
}
return (0);
}
joerg <joerg@gmx.net>