1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2019 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 enum { BITS_PER_ULONG = CHAR_BIT * sizeof (unsigned long int) };
26 unsigned long int *bitvector_allocate(size_t n);
27 size_t bitvector_count (const unsigned long int *, size_t);
29 static unsigned long int
30 bitvector_mask (size_t idx)
32 return 1UL << (idx % BITS_PER_ULONG);
35 static const unsigned long int *
36 bitvector_unit (const unsigned long int *vec, size_t idx)
38 return &vec[idx / BITS_PER_ULONG];
41 static unsigned long int *
42 bitvector_unit_rw (unsigned long int *vec, size_t idx)
44 return &vec[idx / BITS_PER_ULONG];
48 bitvector_set1 (unsigned long int *vec, size_t idx)
50 *bitvector_unit_rw (vec, idx) |= bitvector_mask (idx);
54 bitvector_set0 (unsigned long int *vec, size_t idx)
56 *bitvector_unit_rw (vec, idx) &= ~bitvector_mask (idx);
60 bitvector_is_set (const unsigned long int *vec, size_t idx)
62 return (*bitvector_unit (vec, idx) & bitvector_mask (idx)) != 0;
65 /* Returns 2**X, 0 <= X < 32. */
66 #define BIT_INDEX(X) (1ul << (X))
68 #endif /* bitvector.h */