2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
27 ** based on set_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "splintMacros.nf"
39 intSet s = (intSet) dmalloc (sizeof (*s));
42 s->nspace = intSetBASESIZE;
43 s->elements = (int *) dmalloc (sizeof (*s->elements) * intSetBASESIZE);
49 intSet_grow (intSet s)
54 s->nspace = intSetBASESIZE;
55 newelements = (int *) dmalloc (sizeof (*newelements) * (s->entries + s->nspace));
57 for (i = 0; i < s->entries; i++)
59 newelements[i] = s->elements[i];
63 s->elements = newelements;
67 ** Ensures: if *e \in *s
68 ** then unchanged (*s) & result = false
69 ** else *s' = insert (*s, *e) & result = true
74 intSet_insert (intSet s, int el)
78 for (i = 0; i < s->entries; i++)
80 if (s->elements[i] >= el)
84 if (s->entries > 0 && s->elements[i] == el)
95 if (i == (s->entries - 1))
97 s->elements[s->entries] = el;
103 for (j = s->entries; j > i; j--)
105 s->elements[j] = s->elements[j-1];
116 intSet_member (intSet s, int el)
120 for (i = 0; i < s->entries; i++)
122 if (el == s->elements[i])
126 if (el > s->elements[i])
135 intSet_unparseText (intSet s)
138 cstring st = cstring_undefined;
139 int lastentry = s->entries - 1;
141 for (i = 0; i < s->entries; i++)
144 st = message ("%d", s->elements[i]);
145 else if (i == lastentry)
146 st = message ("%q or %d", st, s->elements[i]);
148 st = message ("%q, %d", st, s->elements[i]);
155 intSet_unparse (intSet s)
158 cstring st = cstring_makeLiteral ("{");
160 for (i = 0; i < s->entries; i++)
162 st = message ("%q %d", st, s->elements[i]);
165 st = message ("%q}", st);
170 intSet_free (intSet s)