Debug swcsa
[SXSI/TextCollection.git] / FMIndexBuilder.h
1 /******************************************************************************
2  *   Copyright (C) 2009 by Niko Valimaki <nvalimak@cs.helsinki.fi>            *
3  *                                                                            *
4  *   This program is free software; you can redistribute it and/or modify     *
5  *   it under the terms of the GNU Lesser General Public License as published *
6  *   by the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                      *
8  *                                                                            *
9  *   This program is distributed in the hope that it will be useful,          *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
12  *   GNU Lesser General Public License for more details.                      *
13  *                                                                            *
14  *   You should have received a copy of the GNU Lesser General Public License *
15  *   along with this program; if not, write to the                            *
16  *   Free Software Foundation, Inc.,                                          *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                *
18  ******************************************************************************/ 
19
20 #ifndef _SXSI_FMIndexBuilder_h_
21 #define _SXSI_FMIndexBuilder_h_
22
23 #include "TextCollectionBuilder.h"
24 #include "TextStorage.h"
25 #include "Tools.h" // Defines ulong and uchar.
26
27 #include <string>
28 #include <vector>
29 #include <utility> // Defines std::pair.
30 #include <cstring> // Defines std::strlen, added by Kim
31
32 // Un-comment to compare BWT against a BWT generated from class dynFMI:
33 //#define TCB_TEST_BWT
34
35
36 namespace SXSI
37 {
38     struct TCBuilderRep; // Pimpl
39     
40     /**
41      * Build an instance of the TextCollection class.
42      */
43     class FMIndexBuilder : public TextCollectionBuilder
44     {
45     public:
46         FMIndexBuilder(unsigned samplerate, ulong estimatedInputLength);
47
48         virtual ~FMIndexBuilder();
49         
50         /** 
51          * Insert text
52          *
53          * Must be a zero-terminated string from alphabet [1,255].
54          * Can not be called after makeStatic().
55          * The i'th text insertion gets an identifier value i-1.
56          * In other words, document identifiers start from 0.
57          *
58          * Second parameter tells if the text will be added to the
59          * index also. If false, text is added only to the TextCollection
60          * and can not be searched for.
61          */
62         virtual void InsertText(uchar const *, bool index = true);
63         /**
64          * Make static
65          *
66          * Convert to a static collection.
67          * New texts can not be inserted after this operation.
68          *
69          * TextStorage type defaults to TYPE_PLAIN_TEXT, another
70          * possible type is TYPE_LZ_INDEX.
71          */
72         virtual TextCollection * InitTextCollection(char type = TextStorage::TYPE_PLAIN_TEXT);
73         
74     private:
75         FMIndexBuilder();
76         
77         // Using Pimpl idiom to hide RLCSA implementation.
78         struct TCBuilderRep * p_;
79
80         // No copy constructor or assignment
81         FMIndexBuilder(FMIndexBuilder const&);
82         FMIndexBuilder& operator = (FMIndexBuilder const&);
83     };
84 }
85 #endif