Small fixes
[SXSI/TextCollection.git] / RLWaveletTree.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Veli Mäkinen                                    *
3  *                                                                         *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 /*
22  * Wavelet tree by Veli Mäkinen,
23  */
24
25 #ifndef _RLWAVELETTREE_H_
26 #define _RLWAVELETTREE_H_
27 #include "GapEncode.h"
28 #include "Tools.h"
29 #include "BitRank.h"
30
31 class RLWaveletTree {
32 private:
33         ulong n;
34         ulong maxlevel;
35         ulong *leaves; // stores the leaf positions of characters 0..2^maxlevel-1
36         GapEncode *bitrank;
37         BitRank *charMap;
38         void remapAlphabet(uchar*, ulong);
39
40         ulong prevRunLen; // Used by charAtPosRun()
41         ulong prevPos;
42         ulong prevChar;
43         ulong prevRank;
44 public:            
45     RLWaveletTree(uchar *, ulong);
46     RLWaveletTree(FILE *);
47     ~RLWaveletTree();
48
49     void Save(FILE *) const;
50    ulong rank(ulong c, ulong i);
51     
52    ulong select(ulong c, ulong j);
53         
54    bool IsCharAtPos(ulong c, ulong i);
55
56    ulong charAtPos(ulong i);
57    ulong charAtPos(ulong i, ulong *rank);
58    ulong charAtPosRun(ulong i, ulong *rank);
59    double spaceInBits() {
60        return 0; // Not implemented
61    }
62 };
63
64 #endif