CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Path: gap4r8 / src / blister.h
Views: 418346
1
/****************************************************************************
2
**
3
*W blister.h GAP source Martin Schönert
4
**
5
**
6
*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
7
*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
8
*Y Copyright (C) 2002 The GAP Group
9
**
10
** This file declares the functions that mainly operate on boolean lists.
11
** Because boolean lists are just a special case of lists many things are
12
** done in the list package.
13
**
14
** A *boolean list* is a list that has no holes and contains only 'true' and
15
** 'false'. For the full definition of boolean list see chapter "Boolean
16
** Lists" in the {\GAP} Manual. Read also the section "More about Boolean
17
** Lists" about the different internal representations of such lists.
18
*/
19
20
#ifndef GAP_BLISTER_H
21
#define GAP_BLISTER_H
22
23
24
/****************************************************************************
25
**
26
27
*V BIPEB . . . . . . . . . . . . . . . . . . . . . . . . . . bits per block
28
**
29
** 'BIPEB' is the number of bits per block, where a block fills a UInt,
30
** which must be the same size as a bag identifier.
31
**
32
*/
33
#define BIPEB (sizeof(UInt) * 8L)
34
35
36
/****************************************************************************
37
**
38
39
*F PLEN_SIZE_BLIST( <size> ) . physical length from size for a boolean list
40
**
41
** 'PLEN_SIZE_BLIST' computes the physical length (e.g. the number of
42
** elements that could be stored in a list) from the <size> (as reported by
43
** 'SIZE') for a boolean list.
44
**
45
** Note that 'PLEN_SIZE_BLIST' is a macro, so do not call it with arguments
46
** that have side effects.
47
*/
48
#define PLEN_SIZE_BLIST(size) \
49
((((size)-sizeof(Obj))/sizeof(UInt)) * BIPEB)
50
51
52
/****************************************************************************
53
**
54
*F SIZE_PLEN_BLIST( <plen> ) . . size for a blist with given physical length
55
**
56
** 'SIZE_PLEN_BLIST' returns the size that a boolean list with room for
57
** <plen> elements must at least have.
58
**
59
** Note that 'SIZE_PLEN_BLIST' is a macro, so do not call it with arguments
60
** that have side effects.
61
*/
62
#define SIZE_PLEN_BLIST(plen) \
63
(sizeof(Obj)+((plen)+BIPEB-1)/BIPEB*sizeof(UInt))
64
65
66
/****************************************************************************
67
**
68
*F LEN_BLIST( <list> ) . . . . . . . . . . . . . . length of a boolean list
69
**
70
** 'LEN_BLIST' returns the logical length of the boolean list <list>, as a C
71
** integer.
72
**
73
** Note that 'LEN_BLIST' is a macro, so do not call it with arguments that
74
** have side effects.
75
*/
76
#define LEN_BLIST(list) (INT_INTOBJ(ADDR_OBJ(list)[0]))
77
78
79
/***************************************************************************
80
**
81
*F NUMBER_BLOCKS_BLIST(<list>) . . . . . . . . number of UInt blocks in list
82
**
83
*/
84
#define NUMBER_BLOCKS_BLIST( blist ) ((LEN_BLIST((blist)) + BIPEB -1)/BIPEB)
85
86
87
/****************************************************************************
88
**
89
*F SET_LEN_BLIST( <list>, <len> ) . . . . set the length of a boolean list
90
**
91
** 'SET_LEN_BLIST' sets the length of the boolean list <list> to the value
92
** <len>, which must be a positive C integer.
93
**
94
** Note that 'SET_LEN_BLIST' is a macro, so do not call it with arguments
95
** that have side effects.
96
*/
97
#define SET_LEN_BLIST(list,len) \
98
(ADDR_OBJ(list)[0] = INTOBJ_INT(len))
99
100
101
/****************************************************************************
102
**
103
*F BLOCKS_BLIST( <list> ) . . . . . . . . . . first block of a boolean list
104
**
105
** returns a pointer to the start of the data of the Boolean list
106
**
107
*/
108
#define BLOCKS_BLIST( list ) ((UInt*)(ADDR_OBJ(list)+1))
109
110
111
/****************************************************************************
112
**
113
*F BLOCK_ELM_BLIST( <list>, <pos> ) . . . . . . . . block of a boolean list
114
**
115
** 'BLOCK_ELM_BLIST' return the block containing the <pos>-th element of the
116
** boolean list <list> as a UInt value, which is also a valid left hand
117
** side. <pos> must be a positive integer less than or equal to the length
118
** of <list>.
119
**
120
** Note that 'BLOCK_ELM_BLIST' is a macro, so do not call it with arguments
121
** that have side effects.
122
*/
123
#define BLOCK_ELM_BLIST(list, pos) (BLOCKS_BLIST( list )[((pos)-1)/BIPEB])
124
125
126
/****************************************************************************
127
**
128
*F MASK_POS_BLIST( <pos> ) . . . . bit mask for position of a Boolean list
129
**
130
** MASK_POS_BLIST(<pos>) returns a UInt with a single set bit in position
131
** (pos-1) % BIPEB, useful for accessing the pos'th element of a blist
132
**
133
** Note that 'MASK_POS_BLIST' is a macro, so do not call it with arguments
134
** that have side effects.
135
*/
136
#define MASK_POS_BLIST( pos ) (((UInt) 1)<<((pos)-1)%BIPEB)
137
138
139
/****************************************************************************
140
**
141
*F ELM_BLIST( <list>, <pos> ) . . . . . . . . . . element of a boolean list
142
**
143
** 'ELM_BLIST' return the <pos>-th element of the boolean list <list>, which
144
** is either 'true' or 'false'. <pos> must be a positive integer less than
145
** or equal to the length of <list>.
146
**
147
** Note that 'ELM_BLIST' is a macro, so do not call it with arguments that
148
** have side effects.
149
*/
150
#define ELM_BLIST(list,pos) \
151
((BLOCK_ELM_BLIST(list,pos) & MASK_POS_BLIST(pos)) ? True : False)
152
153
154
/****************************************************************************
155
**
156
*F SET_ELM_BLIST( <list>, <pos>, <val> ) . set an element of a boolean list
157
**
158
** 'SET_ELM_BLIST' sets the element at position <pos> in the boolean list
159
** <list> to the value <val>. <pos> must be a positive integer less than or
160
** equal to the length of <list>. <val> must be either 'true' or 'false'.
161
**
162
** Note that 'SET_ELM_BLIST' is a macro, so do not call it with arguments
163
** that have side effects.
164
*/
165
#define SET_ELM_BLIST(list,pos,val) \
166
((val) == True ? \
167
(BLOCK_ELM_BLIST(list, pos) |= MASK_POS_BLIST(pos)) : \
168
(BLOCK_ELM_BLIST(list, pos) &= ~MASK_POS_BLIST(pos)))
169
170
171
/****************************************************************************
172
**
173
*F IS_BLIST_REP( <list> ) . . . . . check if <list> is in boolean list rep
174
*/
175
#define IS_BLIST_REP(list) \
176
( T_BLIST <= TNUM_OBJ(list) && TNUM_OBJ(list) <= T_BLIST_SSORT+IMMUTABLE )
177
178
179
/****************************************************************************
180
**
181
*F COUNT_TRUES_BLOCK( <block> ) . . . . . . . . . . . count number of trues
182
*/
183
#ifdef SYS_IS_64_BIT
184
185
#define COUNT_TRUES_BLOCK( block ) \
186
do { \
187
(block) = ((block) & 0x5555555555555555L) + (((block) >> 1) & 0x5555555555555555L); \
188
(block) = ((block) & 0x3333333333333333L) + (((block) >> 2) & 0x3333333333333333L); \
189
(block) = ((block) + ((block) >> 4)) & 0x0f0f0f0f0f0f0f0fL; \
190
(block) = ((block) + ((block) >> 8)); \
191
(block) = ((block) + ((block) >> 16)); \
192
(block) = ((block) + ((block) >> 32)) & 0x00000000000000ffL; } while (0)
193
194
#else
195
196
#define COUNT_TRUES_BLOCK( block ) \
197
do { \
198
(block) = ((block) & 0x55555555) + (((block) >> 1) & 0x55555555); \
199
(block) = ((block) & 0x33333333) + (((block) >> 2) & 0x33333333); \
200
(block) = ((block) + ((block) >> 4)) & 0x0f0f0f0f; \
201
(block) = ((block) + ((block) >> 8)); \
202
(block) = ((block) + ((block) >> 16)) & 0x000000ff; } while (0)
203
#endif
204
205
206
/****************************************************************************
207
**
208
209
*F * * * * * * * * * * * * * * list functions * * * * * * * * * * * * * * * *
210
*/
211
212
/****************************************************************************
213
**
214
215
216
*F AssBlist( <list>, <pos>, <val> ) . . . . . . . assign to a boolean list
217
**
218
** 'AssBlist' assigns the value <val> to the boolean list <list> at the
219
** position <pos>. It is the responsibility of the caller to ensure that
220
** <pos> is positive, and that <val> is not 0.
221
**
222
** 'AssBlist' is the function in 'AssListFuncs' for boolean lists.
223
**
224
** If <pos> is less than or equal to the logical length of the boolean list
225
** and <val> is 'true' or 'false' the assignment is done by setting the
226
** corresponding bit. If <pos> is one more than the logical length of the
227
** boolean list the assignment is done by resizing the boolean list if
228
** necessary, setting the corresponding bit and incrementing the logical
229
** length by one. Otherwise the boolean list is converted to an ordinary
230
** list and the assignment is performed the ordinary way.
231
*/
232
extern void AssBlist (
233
Obj list,
234
Int pos,
235
Obj val );
236
237
238
/****************************************************************************
239
**
240
*F ConvBlist( <list> ) . . . . . . . . . convert a list into a boolean list
241
**
242
** `ConvBlist' changes the representation of boolean lists into the compact
243
** representation of type 'T_BLIST' described above.
244
*/
245
extern void ConvBlist (
246
Obj list );
247
248
249
/****************************************************************************
250
**
251
252
*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
253
*/
254
255
/****************************************************************************
256
**
257
258
*F InitInfoBlist() . . . . . . . . . . . . . . . . . table of init functions
259
*/
260
StructInitInfo * InitInfoBlist ( void );
261
262
263
#endif // GAP_BLISTER_H
264
265
/****************************************************************************
266
**
267
268
*E blister.h . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
269
*/
270
271