-
Notifications
You must be signed in to change notification settings - Fork 5
/
BitRank.h
49 lines (41 loc) · 1.14 KB
/
BitRank.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef _BITRANK_H_
#define _BITRANK_H_
#include "Tools.h"
#include <cstdio>
#include <stdexcept>
class BitRank {
private:
#if __WORDSIZE == 32
static const unsigned wordShift = 5;
static const unsigned superFactor = 8; // 256 bit blocks
#else
static const unsigned wordShift = 6;
static const unsigned superFactor = 4; // 256 bit blocks
#endif
ulong *data; //here is the bit-array
bool owner;
ulong n,integers;
unsigned b,s;
ulong *Rs; //superblock array
uchar *Rb; //block array
ulong BuildRankSub(ulong, ulong); //internal use of BuildRank
void BuildRank(); //crea indice para rank
public:
BitRank(ulong *, ulong, bool);
BitRank(std::FILE *);
~BitRank();
void save(std::FILE *);
ulong rank(ulong i) const; //Rank from 0 to n-1
ulong rank(bool b, ulong i) const
{
return b?rank(i):(i+1-rank(i));
}
ulong rank0(ulong i) const
{
return i+1-rank(i);
}
ulong select(ulong x) const; // gives the position of the x:th 1.
ulong select0(ulong x) const; // gives the position of the x:th 0.
bool IsBitSet(ulong i) const;
};
#endif