Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

interfaceNodeList.c

Go to the documentation of this file.
00001 /*
00002 ** LCLint - annotation-assisted static program checker
00003 ** Copyright (C) 1994-2000 University of Virginia,
00004 **         Massachusetts Institute of Technology
00005 **
00006 ** This program is free software; you can redistribute it and/or modify it
00007 ** under the terms of the GNU General Public License as published by the
00008 ** Free Software Foundation; either version 2 of the License, or (at your
00009 ** option) any later version.
00010 ** 
00011 ** This program is distributed in the hope that it will be useful, but
00012 ** WITHOUT ANY WARRANTY; without even the implied warranty of
00013 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 ** General Public License for more details.
00015 ** 
00016 ** The GNU General Public License is available from http://www.gnu.org/ or
00017 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00018 ** MA 02111-1307, USA.
00019 **
00020 ** For information on lclint: lclint-request@cs.virginia.edu
00021 ** To report a bug: lclint-bug@cs.virginia.edu
00022 ** For more information: http://lclint.cs.virginia.edu
00023 */
00024 /*
00025 ** interfaceNodeList.c
00026 **
00027 ** based on list_template.c
00028 **
00029 ** where T has T_equal (or change this) and T_unparse
00030 */
00031 
00032 # include "lclintMacros.nf"
00033 # include "llbasic.h"
00034 
00035 /*@only@*/ interfaceNodeList
00036 interfaceNodeList_new ()
00037 {
00038   interfaceNodeList s = (interfaceNodeList) dmalloc (sizeof (*s));
00039 
00040   s->nelements = 0;
00041   s->nspacelow = interfaceNodeListGROWLOW;
00042   s->nspacehigh = interfaceNodeListGROWHI;
00043   s->elementsroot = (interfaceNode *) dmalloc (sizeof (*s->elements)
00044                                                * interfaceNodeListBASESIZE);
00045   s->elements = s->elementsroot + interfaceNodeListGROWLOW;
00046 
00047   return (s);
00048 }
00049 
00050 static void
00051 interfaceNodeList_grow (interfaceNodeList s)
00052 {
00053   int i;
00054   interfaceNode *newelements; 
00055   
00056   newelements = (interfaceNode *) dmalloc 
00057     (sizeof (*newelements) * (s->nelements + interfaceNodeListBASESIZE));
00058 
00059   for (i = 0; i < s->nelements; i++)
00060     {
00061       newelements[i + interfaceNodeListGROWLOW] = s->elements[i];
00062     }
00063   
00064   s->nspacelow = interfaceNodeListGROWLOW;
00065   s->nspacehigh = interfaceNodeListGROWHI; 
00066   
00067   sfree (s->elementsroot);  
00068   s->elementsroot = newelements;
00069 
00070   s->elements = newelements + s->nspacelow;
00071 }
00072 
00073 interfaceNodeList
00074 interfaceNodeList_addh (interfaceNodeList s, interfaceNode el)
00075 {
00076   llassert (interfaceNodeListGROWHI > 0);
00077 
00078   if (s->nspacehigh <= 0)
00079     interfaceNodeList_grow (s);
00080 
00081   s->nspacehigh--;
00082   s->elements[s->nelements] = el;
00083   s->nelements++;
00084 
00085   return s;
00086 }
00087 
00088 void 
00089 interfaceNodeList_addl (interfaceNodeList s, /*@keep@*/ interfaceNode el)
00090 {
00091   llassert (interfaceNodeListGROWLOW > 0);
00092 
00093   if (s->nspacelow <= 0)
00094     interfaceNodeList_grow (s);
00095 
00096   s->nspacelow--;
00097   s->elements--;
00098   s->elements[0] = el;
00099   s->nelements++;
00100 }
00101 
00102 void
00103 interfaceNodeList_free (interfaceNodeList s)
00104 {
00105   int i;
00106 
00107   for (i = 0; i < s->nelements; i++)
00108     {
00109       interfaceNode_free (s->elements[i]);
00110     }
00111 
00112   sfree (s->elementsroot);
00113   sfree (s);
00114 }

Generated at Fri Nov 3 18:57:41 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000