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

sortSetList.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 ** sortSetList.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@*/ sortSetList
00036 sortSetList_new ()
00037 {
00038   sortSetList s = (sortSetList) dmalloc (sizeof (*s));
00039   
00040   s->nelements = 0;
00041   s->free = sortSetListBASESIZE;
00042   s->elements = (sortSet *) dmalloc (sizeof (*s->elements) * sortSetListBASESIZE);
00043   s->current = 0;
00044   
00045   return (s);
00046 }
00047 
00048 static void
00049 sortSetList_grow (sortSetList s)
00050 {
00051   int i;
00052   sortSet *newelements;
00053 
00054   s->free += sortSetListBASESIZE;
00055   newelements = (sortSet *) dmalloc (sizeof (*newelements)
00056                                      * (s->nelements + s->free));
00057   
00058   if (newelements == (sortSet *) 0)
00059     {
00060       llfatalerror (cstring_makeLiteral ("sortSetList_grow: out of memory!"));
00061     }
00062 
00063   for (i = 0; i < s->nelements; i++)
00064     {
00065       newelements[i] = s->elements[i];
00066     }
00067 
00068   sfree (s->elements);
00069   s->elements = newelements;
00070 }
00071 
00072 void 
00073 sortSetList_addh (sortSetList s, sortSet el)
00074 {
00075   llassert (sortSetListBASESIZE > 0);
00076 
00077   if (s->free <= 0)
00078     sortSetList_grow (s);
00079 
00080   s->free--;
00081   s->elements[s->nelements] = el;
00082   s->nelements++;
00083 }
00084 
00085 void 
00086 sortSetList_reset (sortSetList s)
00087 {
00088   s->current = 0;
00089 }
00090 
00091 void 
00092 sortSetList_advance (sortSetList s)
00093 {
00094   s->current++;
00095 }
00096 
00097 /*@observer@*/ sortSet 
00098 sortSetList_head (sortSetList s)
00099 {
00100   llassert (s->nelements > 0);
00101   return (s->elements[0]);
00102 }
00103 
00104 /*@observer@*/ sortSet 
00105 sortSetList_current (sortSetList s)
00106 {
00107   if (s->current < 0 || s->current >= s->nelements)
00108     {
00109       llbug (message ("sortSetList_current: current out of range: %d (size: %d)",
00110                       s->current, s->nelements));
00111     }
00112   return (s->elements[s->current]);
00113 }
00114 
00115 /*@only@*/ cstring
00116 sortSetList_unparse (sortSetList s)
00117 {
00118   int i;
00119   cstring st = cstring_makeLiteral ("[ ");
00120 
00121   for (i = 0; i < s->nelements; i++)
00122     {
00123       if (i != 0)
00124         st = message ("%q, %q", st, sortSet_unparse (s->elements[i]));
00125       else
00126         st = message ("%q%q", st, sortSet_unparse (s->elements[i]));
00127     }
00128   
00129   st = message ("%q]", st);
00130   return st;
00131 }
00132 
00133 void
00134 sortSetList_free (sortSetList s)
00135 {
00136   /* note: elements are dependent */
00137 
00138   sfree (s->elements);       
00139   sfree (s);
00140 }

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