--- ray/src/hd/sm_list.c 1998/08/19 17:45:24 3.1 +++ ray/src/hd/sm_list.c 1999/06/10 15:22:23 3.7 @@ -20,12 +20,11 @@ static LIST *free_lists = NULL; extern int Malloc_cnt; #endif LIST +/* NOTE: Memory is not initialized */ *new_list() { LIST *l; - - /* check free list for available edges */ if( free_lists ) { @@ -38,9 +37,6 @@ LIST if( !(l = (LIST *)malloc(sizeof(LIST)))) error(SYSTEM,"new_list():Unable to allocate memory"); } - /* clear the memory */ - bzero(l, sizeof(LIST)); - return(l); } @@ -52,9 +48,6 @@ LIST *a,*b; { LIST * l; - if(!a) - return(b); - if(!b) return(a); @@ -67,6 +60,40 @@ LIST *a,*b; return(b); } +/* attaches list a at the end of list b */ +LIST +*add_data(l,d,end) +LIST *l; +int d; +LIST **end; + +{ + LIST *list,*lptr; + + list = new_list(); + SET_LIST_DATA(list,d); + SET_LIST_NEXT(list,NULL); + if(!l) + { + if(end) + *end = list; + return(list); + } + if(end) + lptr = *end; + else + { + lptr = l; + while(LIST_NEXT(lptr)) + lptr = LIST_NEXT(lptr); + } + LIST_NEXT(lptr) = list; + if(end) + *end = list; + + return(l); +} + /* Adds data to the end of a circular list. If set, "end" * is a pointer to the last element in the list */ @@ -95,22 +122,8 @@ int d; return(l); } -/* Pushes data element d at the top of the list- returns pointer - to new top of list - */ -LIST -*push_data(l,d) -LIST *l; -int d; -{ - LIST * list; - - list = new_list(); - SET_LIST_DATA(list,d); - SET_LIST_NEXT(list,l); - return(list); -} + /* frees the list */ LIST *free_list(l) @@ -118,11 +131,27 @@ LIST * l; { if(!l) return(NULL); + free_lists = append_list(free_lists,l); return(NULL); } +/* Pushes data element d at the top of the list- returns pointer + to new top of list + */ +LIST +*push_data(l,d) +LIST *l; +int d; +{ + LIST *list; + + list = new_list(); + SET_LIST_DATA(list,d); + SET_LIST_NEXT(list,l); + return(list); +} /* Returns data element d at the top of the list- returns pointer to new top of list */ @@ -131,7 +160,7 @@ pop_list(l) LIST **l; { LIST *p; - void *d; + int d; if(!l) return(NULL); @@ -179,6 +208,10 @@ LIST **list; } return(FALSE); } + + + +