Backport changes from the grammar branch
[SXSI/XMLTree.git] / libcds / src / static_sequence / wt_coder.h
1 /* wt_coder.h
2  * Copyright (C) 2008, Francisco Claude, all rights reserved.
3  *
4  * wt_coder definition
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21  
22 #ifndef wt_coder_h
23 #define wt_coder_h
24
25 #include <basics.h>
26 #include <iostream>
27
28 //using namespace std;
29
30 #define WT_CODER_HUFF_HDR 2
31 #define WT_CODER_BINARY_HDR 3
32
33 /** Coder that defines the shape of a wavelet tree 
34  * 
35  *  @author Francisco Claude
36  */
37 class wt_coder {
38         public:
39                 wt_coder();
40                 virtual void use();
41                 virtual void unuse();
42     virtual ~wt_coder() {}; 
43     /** Tells if at level l the symbol is represented by a one or a zero */
44                 virtual bool is_set(uint symbol, uint l)=0;
45     /** Tells if the path of symbol becomes unique at level l */
46                 virtual bool done(uint symbol, uint l)=0;
47     /** Returns the size of the coder */
48     virtual uint size()=0;
49     /** Returns the depth of the tree */
50     virtual uint depth() {
51         return -1; // Implemented in wt_coder_binary
52     }
53     /** Saves the coder to a file, returns 0 in case of success */
54     virtual uint save(FILE *fp)=0;
55     /** Loads a coder from a file, returns NULL in case of error */
56     static wt_coder * load(FILE *fp);
57         protected:
58                 uint user_count;
59 };
60
61 #include <wt_coder_huff.h>
62 #include <wt_coder_binary.h>
63
64 #endif