1 /* static_bitsequence.cpp
2 * Copyright (C) 2008, Francisco Claude, all rights reserved.
4 * static_bitsequence 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 #include "static_bitsequence.h"
24 uint static_bitsequence::rank0(uint i) {
28 uint static_bitsequence::rank1(uint i) {
29 if(i>=len) return ones;
30 if(ones==0) return -1;
34 uint pos = (ini+fin)/2;
35 uint bp = select1(pos);
42 if(select1(ini)>i) return ini-1;
46 uint static_bitsequence::select0(uint i) {
47 if(i>len-ones) return len;
52 uint pos = (ini+fin)/2;
62 uint static_bitsequence::select1(uint i) {
63 if(i>ones) return len;
68 uint pos = (ini+fin)/2;
78 bool static_bitsequence::access(uint i) {
79 return (rank1(i)-(i!=0?rank1(i-1):0))>0;
82 uint static_bitsequence::length() {
86 uint static_bitsequence::count_one() {
90 uint static_bitsequence::count_zero() {
94 static_bitsequence * static_bitsequence::load(FILE * fp) {
96 if(fread(&r,sizeof(uint),1,fp)!=1) return NULL;
97 fseek(fp,-1*sizeof(uint),SEEK_CUR);
99 case RRR02_HDR: return static_bitsequence_rrr02::load(fp);
100 case BRW32_HDR: return static_bitsequence_brw32::load(fp);
101 case RRR02_LIGHT_HDR: return static_bitsequence_rrr02_light::load(fp);