84a0ee266f089331329dcce3e758647a9b03dcc8
[pspp-builds.git] / src / libpspp / bit-vector.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA. */
18
19 #if !bitvector_h
20 #define bitvector_h 1
21
22 #include <limits.h>
23
24 /* Sets bit Y starting at address X. */
25 #define SET_BIT(X, Y)                                   \
26         (((unsigned char *) X)[(Y) / CHAR_BIT] |= 1 << ((Y) % CHAR_BIT))
27
28 /* Clears bit Y starting at address X. */
29 #define CLEAR_BIT(X, Y)                                 \
30         (((unsigned char *) X)[(Y) / CHAR_BIT] &= ~(1 << ((Y) % CHAR_BIT)))
31
32 /* Sets bit Y starting at address X to Z, which is zero/nonzero */
33 #define SET_BIT_TO(X, Y, Z)                     \
34         ((Z) ? SET_BIT(X, Y) : CLEAR_BIT(X, Y))
35
36 /* Nonzero if bit Y starting at address X is set. */
37 #define TEST_BIT(X, Y)                                  \
38         (((unsigned char *) X)[(Y) / CHAR_BIT] & (1 << ((Y) % CHAR_BIT)))
39
40 /* Returns 2**X, 0 <= X < 32. */
41 #define BIT_INDEX(X) (1ul << (X))
42
43 #endif /* bitvector.h */