cbits 0.3.0
High-performance BitVector C-API & Python binding
 
Loading...
Searching...
No Matches
bitvector_internal.h
Go to the documentation of this file.
1
15#ifndef CBITS_BITVECTOR_INTERNAL_H
16#define CBITS_BITVECTOR_INTERNAL_H
17
18#include "bitvector.h"
19
25static inline size_t
26bv_word(const size_t pos)
27{
28 return pos >> 6;
29}
35static inline size_t
36bv_bit(const size_t pos)
37{
38 return pos & 63;
39}
40
48static inline int
49bv__get_inline(const BitVector *bv, const size_t pos)
50{
51 return (bv->data[bv_word(pos)] >> bv_bit(pos)) & 1;
52}
59static inline void
60bv__set_inline(BitVector *bv, const size_t pos)
61{
62 uint64_t mask = 1ULL << bv_bit(pos);
63 bv->data[bv_word(pos)] |= mask;
64 bv->rank_dirty = true;
65}
72static inline void
73bv__clear_inline(BitVector *bv, const size_t pos)
74{
75 uint64_t mask = ~(1ULL << bv_bit(pos));
76 bv->data[bv_word(pos)] &= mask;
77 bv->rank_dirty = true;
78}
85static inline void
86bv__flip_inline(BitVector *bv, const size_t pos)
87{
88 uint64_t mask = 1ULL << bv_bit(pos);
89 bv->data[bv_word(pos)] ^= mask;
90 bv->rank_dirty = true;
91}
92
98static inline void
100{
101 if (!bv->n_words) {
102 return;
103 }
104 unsigned tail = (unsigned) (bv->n_bits & 63);
105 if (tail) {
106 uint64_t mask = (UINT64_C(1) << tail) - 1;
107 bv->data[bv->n_words - 1] &= mask;
108 }
109}
110
111#endif /* CBITS_BITVECTOR_INTERNAL_H */
Public C API for the BitVector data structure.
static void bv__set_inline(BitVector *bv, const size_t pos)
Internal inline version of bv_set().
Definition bitvector_internal.h:60
static void bv__flip_inline(BitVector *bv, const size_t pos)
Internal inline version of bv_flip().
Definition bitvector_internal.h:86
static void bv_apply_tail_mask(BitVector *bv)
Mask off any excess bits in the last word of a BitVector.
Definition bitvector_internal.h:99
static void bv__clear_inline(BitVector *bv, const size_t pos)
Internal inline version of bv_clear().
Definition bitvector_internal.h:73
static int bv__get_inline(const BitVector *bv, const size_t pos)
Internal inline version of bv_get().
Definition bitvector_internal.h:49
static size_t bv_word(const size_t pos)
Compute the word index for a given bit position.
Definition bitvector_internal.h:26
static size_t bv_bit(const size_t pos)
Compute the bit offset within its 64-bit word.
Definition bitvector_internal.h:36
Packed bit array with rank-support structures.
Definition bitvector.h:60
uint64_t * data
Definition bitvector.h:61
size_t n_bits
Definition bitvector.h:62
size_t n_words
Definition bitvector.h:63
bool rank_dirty
Definition bitvector.h:66