Save file version flag updated
[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 #include <vector>
28 #include <utility> // Defines std::pair.
29 #include <cstring> // Defines std::strlen, added by Kim
30
31 // Un-comment to compare BWT against a BWT generated from class dynFMI:
32 //#define TCB_TEST_BWT
33
34 // Default samplerate for suffix array samples
35 #define TEXTCOLLECTION_DEFAULT_SAMPLERATE 64
36
37 // Default input length, used to calculate the buffer size.
38 #define TEXTCOLLECTION_DEFAULT_INPUT_LENGTH (150 * 1024 * 1024)
39
40
41 namespace SXSI
42 {
43     struct TCBuilderRep; // Pimpl
44     
45     /**
46      * Build an instance of the TextCollection class.
47      */
48     class TextCollectionBuilder
49     {
50     public:
51         explicit TextCollectionBuilder(unsigned samplerate = TEXTCOLLECTION_DEFAULT_SAMPLERATE, 
52                                        ulong estimatedInputLength =  TEXTCOLLECTION_DEFAULT_INPUT_LENGTH);
53         ~TextCollectionBuilder();
54         
55         /** 
56          * Insert text
57          *
58          * Must be a zero-terminated string from alphabet [1,255].
59          * Can not be called after makeStatic().
60          * The i'th text insertion gets an identifier value i-1.
61          * In other words, document identifiers start from 0.
62          */
63         void InsertText(uchar const *);
64         /**
65          * Make static
66          *
67          * Convert to a static collection.
68          * New texts can not be inserted after this operation.
69          *
70          * TextStorage type defaults to TYPE_PLAIN_TEXT, another
71          * possible type is TYPE_LZ_INDEX.
72          */
73         TextCollection * InitTextCollection(char type = TextStorage::TYPE_PLAIN_TEXT);
74         
75     private:
76         struct TCBuilderRep * p_;
77
78         // No copy constructor or assignment
79         TextCollectionBuilder(TextCollectionBuilder const&);
80         TextCollectionBuilder& operator = (TextCollectionBuilder const&);
81     };
82 }
83 #endif