2 * Copyright (C) 2008, Francisco Claude, all rights reserved.
4 * Table for offsets definition.
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
22 #ifndef _TABLE_OFFSET_H
23 #define _TABLE_OFFSET_H
30 /** Universal table required for static_bitsequence_rrr02, Raman, Raman and Rao's [1]
31 * proposal for rank/select capable data structures, it achieves space nH_0,
32 * O(sample_rate) time for rank and O(log len) for select. The practial implementation
35 * [1] R. Raman, V. Raman and S. Rao. Succinct indexable dictionaries with applications
36 * to encoding $k$-ary trees and multisets. SODA02.
37 * [2] F. Claude and G. Navarro. Practical Rank/Select over Arbitrary Sequences. SPIRE08.
39 * @author Francisco Claude
47 /** Increments the counter of users for the table */
52 /** Tells the object that the user is not going to need the table anymore. */
53 inline table_offset * unuse() {
62 /** Computes binomial(n,k) for n,k<=u */
63 inline uint get_binomial(uint n, uint k) {
64 return binomial[n][k];
67 /** Computes ceil(log2(binomial(n,k))) for n,k<=u */
68 inline ushort get_log2binomial(uint n, uint k) {
69 return log2binomial[n][k];
72 /** Returns the bitmap represented by the given class and inclass offsets */
73 inline ushort short_bitmap(uint class_offset, uint inclass_offset) {
74 if(class_offset==0) return 0;
75 if(class_offset==u) return (ushort)(((uint)1<<u)-1);
76 return short_bitmaps[offset_class[class_offset]+inclass_offset];
84 /** Computes the offset of the first u bits of a given bitstring */
85 inline ushort compute_offset(ushort v) {
89 /** Returns the size of the bitmap in bytes */
97 ushort ** log2binomial;
98 ushort * offset_class;
99 ushort * short_bitmaps;