1 /* static_bitsequence_rrr02_light.h
2 * Copyright (C) 2008, Francisco Claude, all rights reserved.
4 * RRR02 Bitsequence - light version
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef _STATIC_BITSEQUENCE_RRR02_LIGHT_H
24 #define _STATIC_BITSEQUENCE_RRR02_LIGHT_H
26 #define BLOCK_SIZE_LIGHT 15
27 #define DEFAULT_SAMPLING_LIGHT 32
29 #include <static_bitsequence.h>
30 #include <table_offset.h>
34 //using namespace std;
36 /** Implementation of Raman, Raman and Rao's [1] proposal for rank/select capable
37 * data structures, it achieves space nH_0, O(sample_rate) time for rank and O(log len)
38 * for select. The practial implementation is based on [2]
40 * [1] R. Raman, V. Raman and S. Rao. Succinct indexable dictionaries with applications
41 * to encoding $k$-ary trees and multisets. SODA02.
42 * [2] F. Claude and G. Navarro. Practical Rank/Select over Arbitrary Sequences. SPIRE08.
44 * @author Francisco Claude
46 class static_bitsequence_rrr02_light: public static_bitsequence {
48 static_bitsequence_rrr02_light(uint * bitseq, uint len, uint sample_rate=DEFAULT_SAMPLING_LIGHT);
49 virtual ~static_bitsequence_rrr02_light();
51 /** Returns the number of zeros until position i */
52 virtual uint rank0(uint i);
54 /** Returns the number of ones until position i */
55 virtual uint rank1(uint i);
57 /** Returns the position of the i-th zero
58 * @return (uint)-1 if i=0, len if i>num_zeros or the position */
59 virtual uint select0(uint i);
61 /** Returns the position of the i-th one
62 * @return (uint)-1 if i=0, len if i>num_ones or the position */
63 virtual uint select1(uint i);
65 /** Returns the i-th bit */
66 virtual bool access(uint i);
68 /** Returns the size of the structure in bytes */
71 /** Stores the bitmap given a file pointer, return 0 in case of success */
72 virtual int save(FILE * fp);
74 /** Reads the bitmap from a file pointer, returns NULL in case of error */
75 static static_bitsequence_rrr02_light * load(FILE * fp);
77 /** Creates a new sampling for the queries */
78 void create_sampling(uint sampling_rate);
80 /** Frees the space required by the table E, which is static and global
83 static void delete_E() {
88 static_bitsequence_rrr02_light();
89 /** Classes and offsets */
92 /** C and O samplings */
93 uint *C_sampling, *O_pos;
97 static table_offset * E;
100 #endif /* _STATIC_BITSEQUENCE_RRR02_H */