Added simple WCSA
[SXSI/TextCollection.git] / TextCollectionBuilder.h
1 /******************************************************************************
2  *   Copyright (C) 2009 by Niko Valimaki <nvalimak@cs.helsinki.fi>            *
3  *   Text collection interface for an in-memory XQuery/XPath engine           *
4  *                                                                            *
5  *   This program is free software; you can redistribute it and/or modify     *
6  *   it under the terms of the GNU Lesser General Public License as published *
7  *   by 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 Lesser General Public License for more details.                      *
14  *                                                                            *
15  *   You should have received a copy of the GNU Lesser General Public License *
16  *   along with this program; if not, write to the                            *
17  *   Free Software Foundation, Inc.,                                          *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                *
19  ******************************************************************************/ 
20
21 #ifndef _SXSI_TextCollectionBuilder_h_
22 #define _SXSI_TextCollectionBuilder_h_
23
24 #include "TextCollection.h"
25 #include "TextStorage.h"
26 #include "Tools.h" // Defines ulong and uchar.
27
28 #include <string>
29 #include <vector>
30 #include <utility> // Defines std::pair.
31 #include <cstring> // Defines std::strlen, added by Kim
32
33 // Un-comment to compare BWT against a BWT generated from class dynFMI:
34 //#define TCB_TEST_BWT
35
36 // Default samplerate for suffix array samples
37 #define TEXTCOLLECTION_DEFAULT_SAMPLERATE 64
38
39 // Default input length, used to calculate the buffer size.
40 #define TEXTCOLLECTION_DEFAULT_INPUT_LENGTH (150 * 1024 * 1024)
41
42
43 namespace SXSI
44 {
45     struct TCBuilderRep; // Pimpl
46     
47     /**
48      * Build an instance of the TextCollection class.
49      */
50     class TextCollectionBuilder
51     {
52     public:
53         explicit TextCollectionBuilder(unsigned samplerate = TEXTCOLLECTION_DEFAULT_SAMPLERATE, 
54                                        ulong estimatedInputLength =  TEXTCOLLECTION_DEFAULT_INPUT_LENGTH);
55         ~TextCollectionBuilder();
56         
57         /** 
58          * Insert text
59          *
60          * Must be a zero-terminated string from alphabet [1,255].
61          * Can not be called after makeStatic().
62          * The i'th text insertion gets an identifier value i-1.
63          * In other words, document identifiers start from 0.
64          *
65          * Second parameter tells if the text will be added to the
66          * index also. If false, text is added only to the TextCollection
67          * and can not be searched for.
68          */
69         void InsertText(uchar const *, bool index = true);
70         /**
71          * Make static
72          *
73          * Convert to a static collection.
74          * New texts can not be inserted after this operation.
75          *
76          * TextStorage type defaults to TYPE_PLAIN_TEXT, another
77          * possible type is TYPE_LZ_INDEX.
78          */
79         TextCollection * InitTextCollection(char type = TextStorage::TYPE_PLAIN_TEXT);
80         
81     private:
82         // Using Pimpl idiom to hide RLCSA implementation.
83         struct TCBuilderRep * p_;
84
85         // No copy constructor or assignment
86         TextCollectionBuilder(TextCollectionBuilder const&);
87         TextCollectionBuilder& operator = (TextCollectionBuilder const&);
88     };
89 }
90 #endif