~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/sys/sysLst_ddstr.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/sys/sysLst_ddstr.c,v $
 37  * Date    :  $Date: 2003/09/22 16:09:02 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: sysLst_ddstr.c,v 1.4 2003/09/22 16:09:02 tony Exp $
 40  */
 41 /**
 42  *  @file List handling (doubly directed).
 43  *  @brief List is {int type; List *next; List *last; void *to;}
 44  *  They are always referenced by both start and end pointers neither of
 45  *  which should be nil. The important points being (a) that start and
 46  *  end are included in the list, and (b) that the list may be part of a
 47  *  larger list.
 48  *
 49  *********
 50 */
 51 
 52 #include "sysLst_ddstr.h"
 53 
 54 #if HAVE_CONFIG_H
 55   #include <config.h>
 56 #endif
 57 
 58 #include <stdio.h>
 59 #include <tina/sys/sys_GenDef.h>
 60 #include <tina/sys/sys_LstDef.h>
 61 #include <tina/sys/sys_MemDef.h>
 62 #include <tina/sys/sysLst_list.h>
 63 
 64 
 65 int ddstr_count(List * start, List * end)
 66 {
 67         List *dptr;
 68         int count;
 69 
 70         if (start == NULL || end == NULL)
 71                 return (0);
 72 
 73         count = 1;
 74         for (dptr = start; dptr != end; dptr = dptr->next)
 75                 ++count;
 76         return (count);
 77 }
 78 
 79 void ddstr_free(List * start, List * end, void (*freefunc) ( /* ??? */ ))
 80 {
 81         List *dptr;
 82 
 83         if (start == NULL || end == NULL)
 84                 return;
 85 
 86         dptr = start;
 87 
 88         for(;;)
 89         {
 90                 dd_ref_free(dptr, freefunc);
 91                 if (dptr == end)
 92                         break;
 93                 dptr = dptr->next;
 94         } 
 95 }
 96 
 97 void ddstr_rm_links(List * start, List * end)
 98 {
 99         List *dptr;
100         List *next;
101         List *dd_link_rm_el();
102 
103         if (start == NULL || end == NULL)
104                 return;
105 
106         dptr = start;
107 
108         for(;;)
109         {
110                 next = dd_link_rm_el(dptr);
111                 if (dptr == end)
112                         break;
113                 dptr = next;
114         }
115 }
116 
117 void ddstr_rm(List * start, List * end, void (*freefunc) ( /* ??? */ ))
118 {
119         List *dptr;
120         List *next;
121         List *dd_link_rm();
122 
123         if (start == NULL || end == NULL)
124                 return;
125 
126         dptr = start;
127         for(;;)
128         {
129                 next = dd_link_rm(dptr, freefunc);
130                 if (dptr == end)
131                         break;
132                 dptr = next;
133         }
134 }
135 
136 List *ddstr_link_get_by_ref(List * start, List * end, void *ptr)
137 {
138         List *dptr;
139 
140         if (start == NULL || end == NULL)
141                 return (NULL);
142 
143         dptr = start;
144         for(;;)
145         {
146                 if (dptr->to == ptr)
147                         return (dptr);
148                 if (dptr == end)
149                         break;
150                 dptr = dptr->next;
151         }
152         return (NULL);
153 }
154 
155 void ddstr_reverse(List ** startp, List ** endp)
156 {
157         List *dptr;
158         List *start;
159         List *end;
160         List *dd_link_addtostart();
161 
162         if (*startp == NULL || *endp == NULL)
163                 return;
164 
165         end = dptr = *startp;
166         start = NULL;
167 
168         for(;;)
169         {
170                 List *next = dptr->next;
171 
172                 start = dd_link_addtostart(start, dptr);
173                 if (dptr == *endp)
174                         break;
175                 dptr = next;
176         }
177         *startp = start;
178         *endp = end;
179 }
180 
181 void ddstr_copy(List ** startp, List ** endp,
182                                                                 void *(*copyfunc) ( /* ??? */ ), void *data)
183 {
184         List *dptr;
185         List *start = NULL;
186         List *end = NULL;
187         List *dd_link_copy();
188         List *dd_link_addtoend();
189 
190         if (*startp == NULL || *endp == NULL)
191                 return;
192 
193 
194         dptr = *startp;
195         for(;;)
196         {
197                 end = dd_link_addtoend(end, dd_link_copy(dptr, copyfunc, data));
198                 if (start == NULL)
199                         start = end;
200                 if (dptr == *endp)
201                         break;
202                 dptr = dptr->next;
203         }
204         *startp = start;
205         *endp = end;
206 }
207 
208 void ddstr_set_type(List * start, List * end, int type, int n)
209 {
210         List *dptr;
211         int i;
212 
213         if (start == NULL || end == NULL)
214                 return;
215 
216         for (i = 0, dptr = start; dptr != end; dptr = dptr->next, ++i)
217                 if (i % n == 0)
218                         dptr->type = type;
219         end->type = type;
220 }
221 
222 List *ddstr_nth_point(List * start, List * end, int n)
223 {
224         List *dptr;
225         int i;
226 
227         if (start == NULL || end == NULL)
228                 return (NULL);
229 
230         for (i = 0, dptr = start;; dptr = dptr->next, ++i)
231         {
232                 if (i == n)
233                         return (dptr);
234                 if (dptr == end)
235                         break;
236         }
237         return (NULL);
238 }
239 
240 List *ddstr_mid_point(List * start, List * end)
241 {
242         int n;
243 
244         if (start == NULL || end == NULL)
245                 return (NULL);
246 
247         n = ddstr_count(start, end) / 2;
248         return (ddstr_nth_point(start, end, n));
249 }
250 
251 void ddstr_apply_func(List * start, List * end, void (*func) ( /* ??? */ ),
252                                                                                         void *data)
253 {
254         List *dptr;
255 
256         if (start == NULL || end == NULL)
257                 return;
258 
259         dptr = start;
260 
261         for(;;)
262         {
263                 func(dptr->to, dptr->type, data);
264                 if (dptr == end)
265                         break;
266                 dptr = dptr->next;
267         }
268 }
269 
270 List *ddstr_get_min(List * start, List * end, Bool(*func) ( /* ??? */ ),
271                                                                                 void *data)
272 {
273         List *dptr;
274         List *min_ptr = NULL;
275         double d, min_d = 0.0;
276 
277         if (start == NULL || end == NULL)
278                 return (NULL);
279 
280         dptr = start;
281 
282         for(;;)
283         {
284                 if (func(dptr->to, dptr->type, data, &d) == true &&
285                                 (min_ptr == NULL || d < min_d))
286                 {
287                         min_ptr = dptr;
288                         min_d = d;
289                 }
290                 if (dptr == end)
291                         break;
292                 dptr = dptr->next;
293         }
294         return (min_ptr);
295 }
296 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.