/[bison]/bison/lib/bitsetv.c
ViewVC logotype

Diff of /bison/lib/bitsetv.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by akim, Mon Mar 4 11:58:52 2002 UTC revision 1.2 by akim, Mon Mar 4 12:07:08 2002 UTC
# Line 30  Software Foundation, 59 Temple Place - S Line 30  Software Foundation, 59 Temple Place - S
30     type TYPE.  */     type TYPE.  */
31  bitset *  bitset *
32  bitsetv_alloc (n_vecs, n_bits, type)  bitsetv_alloc (n_vecs, n_bits, type)
33      unsigned int n_vecs;       unsigned int n_vecs;
34      unsigned int n_bits;       unsigned int n_bits;
35      enum bitset_type type;       enum bitset_type type;
36  {  {
37      unsigned int vector_bytes;    unsigned int vector_bytes;
38      unsigned int bytes;    unsigned int bytes;
39      bitset *bsetv;    bitset *bsetv;
40      unsigned int i;    unsigned int i;
41      
42      /* Determine number of bytes for each set.  */    /* Determine number of bytes for each set.  */
43      bytes = bitset_bytes (type, n_bits);    bytes = bitset_bytes (type, n_bits);
44      
45      /* Allocate vector table at head of bitset array.  */    /* Allocate vector table at head of bitset array.  */
46      vector_bytes = n_vecs * sizeof (bitset);    vector_bytes = (n_vecs + 1) * sizeof (bitset);
47      bsetv = (bitset *) xmalloc (vector_bytes + bytes * n_vecs);    bsetv = (bitset *) xcalloc (1, vector_bytes + bytes * n_vecs);
48      
49      for (i = 0; i < n_vecs; i++)    for (i = 0; i < n_vecs; i++)
50      {      {
51        bsetv[i] = (bitset)((char *)bsetv + vector_bytes + i * bytes);        bsetv[i] = (bitset) ((char *) bsetv + vector_bytes + i * bytes);
52    
53        bitset_init (bsetv[i], n_bits, type);        bitset_init (bsetv[i], n_bits, type);
54      }      }
55      return bsetv;    
56      /* Null terminate table.  */
57      bsetv[i] = 0;
58      return bsetv;
59  }  }
60    
61    
# Line 60  bitsetv_alloc (n_vecs, n_bits, type) Line 63  bitsetv_alloc (n_vecs, n_bits, type)
63     attribute hints specified by ATTR.  */     attribute hints specified by ATTR.  */
64  bitset *  bitset *
65  bitsetv_create (n_vecs, n_bits, attr)  bitsetv_create (n_vecs, n_bits, attr)
66      unsigned int n_vecs;       unsigned int n_vecs;
67      unsigned int n_bits;       unsigned int n_bits;
68      unsigned int attr;       unsigned int attr;
69  {  {
70      enum bitset_type type;    enum bitset_type type;
71      
72      type = bitset_type_choose (n_bits, attr);    type = bitset_type_choose (n_bits, attr);
73      return bitsetv_alloc (n_vecs, n_bits, type);    return bitsetv_alloc (n_vecs, n_bits, type);
74  }  }
75    
76    
77  /* Free bitset vector BSETV.  */  /* Free bitset vector BSETV.  */
78  void  void
79  bitsetv_free (bsetv)  bitsetv_free (bsetv)
80      bitset *bsetv;       bitset *bsetv;
81  {  {
82      free (bsetv);    unsigned int i;
83    
84      for (i = 0; bsetv[i]; i++)
85          BITSET_FREE_ (bsetv[i]);
86      free (bsetv);
87  }  }
88    
89    
90  /* Zero a vector of N_VECS bitsets.  */  /* Zero a vector of bitsets.  */
91  void  void
92  bitsetv_zero (bsetv, n_vecs)  bitsetv_zero (bsetv)
93       struct bitset_struct **bsetv;       struct bitset_struct **bsetv;
      unsigned int n_vecs;  
94  {  {
95    unsigned int i;    unsigned int i;
96      
97    for (i = 0; i < n_vecs; i++)    for (i = 0; bsetv[i]; i++)
98        bitset_zero (bsetv[i]);      bitset_zero (bsetv[i]);
99  }  }
100    
101    
102  /* Set a vector of N_VECS bitsets to ones.  */  /* Set a vector of bitsets to ones.  */
103  void  void
104  bitsetv_ones (bsetv, n_vecs)  bitsetv_ones (bsetv)
105       bitset *bsetv;       bitset *bsetv;
      unsigned int n_vecs;  
106  {  {
107    unsigned int i;    unsigned int i;
108      
109    for (i = 0; i < n_vecs; i++)    for (i = 0; bsetv[i]; i++)
110      bitset_ones (bsetv[i]);      bitset_ones (bsetv[i]);
111  }  }
112    
# Line 109  bitsetv_ones (bsetv, n_vecs) Line 114  bitsetv_ones (bsetv, n_vecs)
114  /* Dump the contents of a bitset vector BSETV with N_VECS elements to  /* Dump the contents of a bitset vector BSETV with N_VECS elements to
115     FILE.  */     FILE.  */
116  void  void
117  bitsetv_dump (file, title, subtitle, bsetv, n_vecs)  bitsetv_dump (file, title, subtitle, bsetv)
118       FILE *file;       FILE *file;
119       const char *title, *subtitle;       const char *title, *subtitle;
120       bitset *bsetv;       bitset *bsetv;
      unsigned int n_vecs;  
121  {  {
122    unsigned int i;    unsigned int i;
123      
124    fprintf (file, "%s\n", title);    fprintf (file, "%s\n", title);
125    for (i = 0; i < n_vecs; i++)    for (i = 0; bsetv[i]; i++)
126      {      {
127        fprintf (file, "%s %d\n", subtitle, i);        fprintf (file, "%s %d\n", subtitle, i);
128        bitset_dump (file, bsetv[i]);        bitset_dump (file, bsetv[i]);
129      }      }
130      
131    fprintf (file, "\n");    fprintf (file, "\n");
132  }  }
133    
134    
135    void
136    debug_bitsetv (bsetv)
137         bitset *bsetv;
138    {
139      unsigned int i;
140      
141      for (i = 0; bsetv[i]; i++)
142        {
143          fprintf (stderr, "%d: ", i);
144          debug_bitset (bsetv[i]);
145        }
146      
147      fprintf (stderr, "\n");
148    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26